diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index fbcc96e..5ed2767 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -8,6 +8,8 @@ Base class for texture generators, that defines their API signal parameter_changed(n, v) +const DEFAULT_GENERATED_SHADER : Dictionary = { defs="", code="", textures={}, type="f", f="0.0" } + class InputPort: var generator : MMGenBase = null var input_index : int = 0 @@ -232,7 +234,7 @@ func render(output_index : int, size : int, preview : bool = false) -> Object: while source is GDScriptFunctionState: source = yield(source, "completed") if source.empty(): - source = { defs="", code="", textures={}, rgba="vec4(0.0)" } + source = DEFAULT_GENERATED_SHADER var shader : String if preview: var output_type = "rgba" diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 04750f6..42f69db 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -48,7 +48,7 @@ func update_shader() -> void: while source is GDScriptFunctionState: source = yield(source, "completed") if source.empty(): - source = { defs="", code="", textures={}, rgba="vec4(0.0)" } + source = DEFAULT_GENERATED_SHADER material.shader.code = mm_renderer.generate_shader(source) if source.has("textures"): for k in source.textures.keys(): diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index e34675d..69f8497 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -62,9 +62,10 @@ func get_parameter_defs() -> Array: return get_node("gen_parameters").get_parameter_defs() return [] -func set_parameter(p, v) -> void: +func set_parameter(n : String, v) -> void: + .set_parameter(n, v) if has_node("gen_parameters"): - get_node("gen_parameters").set_parameter(p, v) + get_node("gen_parameters").set_parameter(n, v) func get_input_defs() -> Array: if has_node("gen_inputs"): diff --git a/addons/material_maker/engine/gen_ios.gd b/addons/material_maker/engine/gen_ios.gd index 3e2437f..37e7c16 100644 --- a/addons/material_maker/engine/gen_ios.gd +++ b/addons/material_maker/engine/gen_ios.gd @@ -95,7 +95,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) - while rv is GDScriptFunctionState: rv = yield(rv, "completed") return rv - return { defs="", code="", textures={} } + return DEFAULT_GENERATED_SHADER func _serialize(data: Dictionary) -> Dictionary: data.type = "ios" diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 7d57fd0..4864f93 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -98,7 +98,7 @@ func render_textures() -> void: while source is GDScriptFunctionState: source = yield(source, "completed") if source.empty(): - source = { defs="", code="", textures={}, rgba="vec4(0.0)" } + source = DEFAULT_GENERATED_SHADER shader_materials[t.texture].shader.code = mm_renderer.generate_shader(source) if source.has("textures"): for k in source.textures.keys(): diff --git a/material_maker/preview/preview_2d.gd b/material_maker/preview/preview_2d.gd index ab0f98d..54f70df 100644 --- a/material_maker/preview/preview_2d.gd +++ b/material_maker/preview/preview_2d.gd @@ -8,7 +8,7 @@ var output : int = 0 func set_generator(g : MMGenBase, o : int = 0) -> void: if is_instance_valid(generator): generator.disconnect("parameter_changed", self, "on_parameter_changed") - var source = { defs="", code="", textures={}, type="f", f="1.0" } + var source = MMGenBase.DEFAULT_GENERATED_SHADER if is_instance_valid(g): generator = g output = o @@ -23,7 +23,7 @@ func set_generator(g : MMGenBase, o : int = 0) -> void: while source is GDScriptFunctionState: source = yield(source, "completed") if source.empty(): - source = { defs="", code="", textures={}, type="f", f="1.0" } + source = MMGenBase.DEFAULT_GENERATED_SHADER else: g = null for c in get_children(): diff --git a/material_maker/widgets/histogram/histogram.gd b/material_maker/widgets/histogram/histogram.gd index 4b6b867..b57a887 100644 --- a/material_maker/widgets/histogram/histogram.gd +++ b/material_maker/widgets/histogram/histogram.gd @@ -15,7 +15,7 @@ func get_histogram_texture() -> ImageTexture: func set_generator(g : MMGenBase, o : int = 0) -> void: if is_instance_valid(generator): generator.disconnect("parameter_changed", self, "on_parameter_changed") - var source = { defs="", code="", textures={}, type="f", f="1.0" } + var source = MMGenBase.DEFAULT_GENERATED_SHADER if is_instance_valid(g): generator = g output = o @@ -28,7 +28,7 @@ func set_generator(g : MMGenBase, o : int = 0) -> void: while source is GDScriptFunctionState: source = yield(source, "completed") if source.empty(): - source = { defs="", code="", textures={}, type="f", f="1.0" } + source = MMGenBase.DEFAULT_GENERATED_SHADER # Update shader $ViewportImage/ColorRect.material.shader.code = MMGenBase.generate_preview_shader(source, source.type, "uniform vec2 size;void fragment() {COLOR = preview_2d(UV);}") # Get parameter values from the shader code