Skip to content

Commit

Permalink
Fixed code generation for Shadertoy (vertex function removal) and God…
Browse files Browse the repository at this point in the history
…ot (missing vector uniforms initialization).
  • Loading branch information
RodZill4 committed Oct 28, 2024
1 parent c4b7c2f commit 4ea3f43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 1 addition & 6 deletions addons/material_maker/engine/multi_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ signal free_rendering_device

func _ready() -> void:
shader_error_handler = load("res://addons/material_maker/engine/shader_error_handler.gd").new()
common_shader = "varying float elapsed_time;
void vertex() {
elapsed_time = TIME;
}
"
common_shader = "varying float elapsed_time;\nvoid vertex() {\n\telapsed_time = TIME;\n}\n"
common_shader += preload("res://addons/material_maker/shader_functions.tres").text
for i in total_renderers:
var renderer = preload("res://addons/material_maker/engine/renderer.tscn").instantiate()
Expand Down
8 changes: 4 additions & 4 deletions material_maker/nodes/debug/debug_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func generate_shadertoy() -> String:
code += mm_renderer.common_shader
code += "\n"
code = code.replace("varying float elapsed_time;", "")
code = code.replace("void vertex() {\n\telapsed_time = TIME;\n}\n", "")
code = code.replace("void vertex() {\n\telapsed_time = TIME;\n}", "")
code += src_code.uniforms_as_strings("const", true)
code += "\n"
code += src_code.get_globals_string(src_code.defs+src_code.code)
Expand All @@ -43,7 +43,7 @@ func generate_shadertoy() -> String:
code += "vec2 UV = vec2(0.0, 1.0) + vec2(1.0, -1.0) * (fragCoord-0.5*(iResolution.xy-vec2(minSize)))/minSize;\n"
code += src_code.code
if src_code.output_values.has("rgba"):
code += "fragColor = "+src_code.output_values.rgba+";\n"
code += "fragColor = vec4(mix(vec3(0.5), "+src_code.output_values.rgba+".rgb, "+src_code.output_values.rgba+".a), 1.0);\n"
else:
code += "fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
code += "}\n"
Expand All @@ -56,7 +56,7 @@ func generate_godot_canvasitem() -> String:
var code = "shader_type canvas_item;\n"
code += "const float seed_variation = 0.0;\n"
code += mm_renderer.common_shader
code += src_code.uniforms_as_strings()
code += src_code.uniforms_as_strings("uniform", true)
code += "\n"
code += src_code.get_globals_string(src_code.defs+src_code.code)
code += src_code.defs
Expand All @@ -78,7 +78,7 @@ func generate_godot_spatial() -> String:
code += "\nconst float seed_variation = 0.0;\n"
code += mm_renderer.common_shader
code += "\n"
code += src_code.uniforms_as_strings()
code += src_code.uniforms_as_strings("uniform", true)
code += "\n"
code += src_code.get_globals_string(src_code.defs+src_code.code)
code += src_code.defs
Expand Down

0 comments on commit 4ea3f43

Please sign in to comment.