Skip to content

Commit

Permalink
More Godot 4.4 related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Dec 12, 2024
1 parent 3d752d9 commit ad13e46
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion addons/material_maker/engine/nodes/gen_material.gd
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func update_materials(material_list, sequential : bool = false) -> void:

func update_material(m, sequential : bool = false) -> void:
if m is ShaderMaterial:
m.shader.code = preview_material.shader.code
m.shader = preview_material.shader
for p in preview_parameters.keys():
m.set_shader_parameter(p, preview_parameters[p])

Expand Down
7 changes: 4 additions & 3 deletions addons/material_maker/engine/renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ func render_material(object : Object, material : Material, render_size : int, wi
$ColorRect.material = null
return self

func render_shader(object : Object, shader : String, render_size : int, with_hdr : bool = true) -> Object:
func render_shader(object : Object, shader_code : String, render_size : int, with_hdr : bool = true) -> Object:
var shader_material = ShaderMaterial.new()
shader_material.shader = Shader.new()
shader_material.shader.code = shader
var shader : Shader = Shader.new()
shader.code = shader_code
shader_material.shader = shader
mm_deps.material_update_params(MMShaderMaterial.new(shader_material))
var status = await render_material(object, shader_material, render_size, with_hdr)
return self
Expand Down
4 changes: 3 additions & 1 deletion material_maker/nodes/debug/debug_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func _on_ShaderType_item_selected(index):
else:
$VBoxContainer/Code.visible = false
$VBoxContainer/ColorRect.visible = true
$VBoxContainer/ColorRect.material.shader.code = generate_godot_canvasitem()
var shader : Shader = Shader.new()
shader.code = generate_godot_canvasitem()
$VBoxContainer/ColorRect.material.shader = shader

func _on_CopyToClipboard_pressed():
DisplayServer.clipboard_set($VBoxContainer/Code.text)
Expand Down
5 changes: 3 additions & 2 deletions material_maker/panels/preview_2d/preview_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ func create_image(renderer_function : String, params : Array, image_size : int)
source = MMGenBase.get_default_generated_shader()
# Update shader
var tmp_material = ShaderMaterial.new()
tmp_material.shader = Shader.new()
tmp_material.shader.code = MMGenBase.generate_preview_shader(source, source.output_type, "uniform vec2 mm_texture_size;\nuniform float mm_chunk_size = 1.0;\nuniform vec2 mm_chunk_offset = vec2(0.0);\nvoid fragment() {COLOR = preview_2d(mm_chunk_offset+mm_chunk_size*UV);}")
var shader : Shader = Shader.new()
shader.code = MMGenBase.generate_preview_shader(source, source.output_type, "uniform vec2 mm_texture_size;\nuniform float mm_chunk_size = 1.0;\nuniform vec2 mm_chunk_offset = vec2(0.0);\nvoid fragment() {COLOR = preview_2d(mm_chunk_offset+mm_chunk_size*UV);}")
tmp_material.shader = shader
for u in source.uniforms:
tmp_material.set_shader_parameter(u.name, u.value)
mm_deps.material_update_params(MMShaderMaterial.new(tmp_material))
Expand Down
14 changes: 8 additions & 6 deletions material_maker/panels/reference/gradient_slot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ signal clicked

func set_gradient(g) -> void:
gradient = g
var shader := ""
shader = "shader_type canvas_item;\n"
shader += gradient.get_shader_params("")
shader += gradient.get_shader("")
shader += "void fragment() { COLOR = _gradient_fct(UV.x); }"
$ColorRect.material.shader.code = shader
var shader_code : String = ""
shader_code = "shader_type canvas_item;\n"
shader_code += gradient.get_shader_params("")
shader_code += gradient.get_shader("")
shader_code += "void fragment() { COLOR = _gradient_fct(UV.x); }"
var shader : Shader = Shader.new()
shader.code = shader_code
$ColorRect.material.shader = shader
update_shader_parameters()


Expand Down
22 changes: 12 additions & 10 deletions material_maker/widgets/gradient_editor/gradient_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ var active_cursor := 0:
# Reference of the preview cursor (when dropping in a color)
var preview_cursor: GradientEditCursor = null
# Reference to the popup
var popup: Control = null
var popup : Control = null

var hovered := false
var hovered : bool = false


func _ready() -> void:
Expand Down Expand Up @@ -178,27 +178,29 @@ func add_cursor(offset, color) -> GradientEditCursor:
func update_shader() -> void:
if value == null:
return
var shader := ""
shader = "shader_type canvas_item;\n"
shader += value.get_shader_params("")
shader += """
var shader_code := ""
shader_code = "shader_type canvas_item;\n"
shader_code += value.get_shader_params("")
shader_code += """
uniform vec2 size = vec2(25.0, 25.0);
uniform vec3 background_color_1 = vec3(0.4);
uniform vec3 background_color_2 = vec3(0.6);
"""
shader += value.get_shader("")
shader += """void fragment() {
shader_code += value.get_shader("")
shader_code += """void fragment() {
vec2 uv = UV*size;
float checkerboard = mod(floor(uv.x*0.2)+floor(uv.y*0.2), 2.0);
vec4 gradient = _gradient_fct(UV.x);
vec3 gradient_with_checkerboard = mix(mix(background_color_1, background_color_2, checkerboard).rgb, gradient.rgb, gradient.a);
if (UV.y < 0.75){
COLOR.rgb = gradient_with_checkerboard;
}else{
} else {
COLOR.rgb = gradient.rgb;
}
}"""
%Gradient.material.shader.set_code(shader)
var shader : Shader = Shader.new()
shader.code = shader_code
%Gradient.material.shader = shader
update_shader_parameters()


Expand Down
10 changes: 7 additions & 3 deletions material_maker/windows/export_animation/export_animation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ func set_source(g, o):
var ends_code = code;
ends_code = ends_code.replace("varying float elapsed_time;", "uniform float elapsed_time;");
ends_code = ends_code.replace("elapsed_time = TIME;", "");
image_begin.material.shader.code = ends_code
image_end.material.shader.code = ends_code
var ends_shader : Shader = Shader.new()
ends_shader.code = ends_code
image_begin.material.shader = ends_shader
image_end.material.shader = ends_shader
var anim_code = code;
anim_code = anim_code.replace("varying float elapsed_time;", "uniform float begin;\nuniform float end;\nvarying float elapsed_time;");
anim_code = anim_code.replace("elapsed_time = TIME;", "elapsed_time = (begin == end) ? begin : begin+sign(end-begin)*mod(TIME, abs(end-begin));");
image_anim.material.shader.code = anim_code
var anim_shader : Shader = Shader.new()
anim_shader.code = anim_code
image_anim.material.shader = anim_shader
for u in source.uniforms:
image_begin.material.set_shader_parameter(u.name, u.value)
image_anim.material.set_shader_parameter(u.name, u.value)
Expand Down
8 changes: 6 additions & 2 deletions material_maker/windows/load_from_website/load_from_website.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func select_asset(type : int = 0, return_index : bool = false) -> Dictionary:
var image : Image = Image.create(256, 256, false, Image.FORMAT_RGBA8)
for i in range(tmp_assets.size()):
var m = tmp_assets[i]
if int(m.type) & 15 == type:
m.id = int(m.id)
m.type = int(m.type)
if m.type & 15 == type:
m.texture = ImageTexture.new()
m.texture.set_image(image)
assets.push_back(m)
Expand All @@ -109,9 +111,11 @@ func update_thumbnails() -> void:
var cache_filename : String = "user://website_cache/thumbnail_%d.png" % m.id
var image : Image = Image.new()
if ! FileAccess.file_exists(cache_filename) or image.load(cache_filename) != OK:
var error = $ImageHTTPRequest.request(MMPaths.WEBSITE_ADDRESS+"/data/materials/material_"+str(m.id)+".webp")
var address : String = MMPaths.WEBSITE_ADDRESS+"/data/materials/material_"+str(m.id)+".webp"
var error = $ImageHTTPRequest.request(address)
if error == OK:
var data : PackedByteArray = (await $ImageHTTPRequest.request_completed)[3]
print(data.get_string_from_ascii())
image.load_webp_from_buffer(data)
image.save_png(cache_filename)
else:
Expand Down

0 comments on commit ad13e46

Please sign in to comment.