Skip to content

Commit

Permalink
EasySDF editor fixes (uninitialized variables in generated shader, co…
Browse files Browse the repository at this point in the history
…lor uniforms init).
  • Loading branch information
RodZill4 committed Feb 6, 2025
1 parent f4e0d4e commit a267cfd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
9 changes: 8 additions & 1 deletion addons/material_maker/sdf_builder/base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ static func get_color_code_smooth_union(scene : Dictionary, ctxt : Dictionary =
color_code += "\ncurrent_color_%d = tmp_%d;" % [ scene.index, scene.index ]
if color_code == "":
return { distance = "_n%d" % scene.index }
color_code = ("%s sum_%d;\n%s tmp_%d;\n%s current_color_%d;\nfloat coef_%d;\nfloat coefsum_%d = 0.0;\n" % [ ctxt.glsl_type, scene.index, ctxt.glsl_type, scene.index, ctxt.glsl_type, scene.index, scene.index, scene.index ])+color_code+("%s = sum_%d/coefsum_%d;" % [ ctxt.target, scene.index, scene.index ])
var init_code : String = ""
init_code += "%s sum_%d = %s(0.0);\n" % [ ctxt.glsl_type, scene.index, ctxt.glsl_type ]
init_code += "%s tmp_%d;\n" % [ ctxt.glsl_type, scene.index ]
init_code += "%s current_color_%d = %s;\n" % [ ctxt.glsl_type, scene.index, ctxt.channel ]
init_code += "float coef_%d;\n" % [ scene.index ]
init_code += "float coefsum_%d = 0.0;\n" % [ scene.index ]
color_code = init_code+color_code
color_code += "\n%s = sum_%d/coefsum_%d;" % [ ctxt.target, scene.index, scene.index ]
return { color = color_code, distance = "_n%d" % scene.index }
11 changes: 7 additions & 4 deletions material_maker/windows/sdf_builder/preview_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ func set_generator(g : MMGenBase, o : int = 0, force : bool = false) -> void:
variables.COLOR_FCT = node_prefix+"_c"
variables.INDEX_UNIFORM = "p_"+node_prefix+"_index"
var shader_code : String = mm_preprocessor.preprocess_file("res://material_maker/windows/sdf_builder/preview_3d.gdshader", variables)
material = await mm_deps.buffer_create_shader_material("preview_"+str(get_instance_id()), MMShaderMaterial.new(material), shader_code)
if material:
for u in source.uniforms:
if u.value:
await mm_deps.buffer_create_shader_material("preview_"+str(get_instance_id()), MMShaderMaterial.new(material), shader_code)
for u in source.uniforms:
if u.value:
if u.value is Dictionary:
if u.value.has("type") and u.value.type == "Color":
material.set_shader_parameter(u.name, Color(u.value.r, u.value.g, u.value.b, u.value.a))
else:
material.set_shader_parameter(u.name, u.value)

var setup_controls_filter : String = ""
Expand Down
16 changes: 14 additions & 2 deletions material_maker/windows/sdf_builder/preview_3d.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=8 format=3 uid="uid://bsdj8r6ur5sja"]
[gd_scene load_steps=11 format=3 uid="uid://bsdj8r6ur5sja"]

[ext_resource type="Script" path="res://material_maker/windows/sdf_builder/preview_3d.gd" id="1"]
[ext_resource type="Script" uid="uid://oghf500m4npr" path="res://material_maker/windows/sdf_builder/preview_3d.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://bkaug0arymhda" path="res://material_maker/windows/sdf_builder/gizmo.tscn" id="2"]

[sub_resource type="World3D" id="World3D_5ccqg"]
Expand All @@ -24,6 +24,15 @@ shader = SubResource("Shader_xkfp5")
margin = 1.0
plane = Plane(0, 0, 1, 0)

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_5ku3d"]

[sub_resource type="Sky" id="Sky_c8kiy"]
sky_material = SubResource("ProceduralSkyMaterial_5ku3d")

[sub_resource type="Environment" id="Environment_si1lg"]
background_mode = 2
sky = SubResource("Sky_c8kiy")

[node name="Preview3D" type="SubViewportContainer" groups=["preview"]]
custom_minimum_size = Vector2(1, 1)
offset_right = 1280.0
Expand Down Expand Up @@ -67,6 +76,9 @@ shape = SubResource("5")
[node name="OmniLight3D" type="DirectionalLight3D" parent="SubViewport"]
transform = Transform3D(0.999941, -0.00199387, -0.01067, 0.0106636, -0.00320327, 0.999938, -0.00202793, -0.999993, -0.00318182, 0, 3.40578, 0)

[node name="WorldEnvironment" type="WorldEnvironment" parent="SubViewport"]
environment = SubResource("Environment_si1lg")

[node name="Buttons" type="HBoxContainer" parent="."]
layout_mode = 2

Expand Down

0 comments on commit a267cfd

Please sign in to comment.