From a811f3400fa07a52a6069d7bf0d088548c9bd2cb Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Tue, 28 Jan 2020 22:40:03 +0100 Subject: [PATCH] Moved io types definition (with conversions and preview) to a json file --- addons/material_maker/engine/gen_base.gd | 96 ++++--------------- .../material_maker/engine/gen_convolution.gd | 1 + addons/material_maker/engine/gen_ios.gd | 1 - addons/material_maker/engine/gen_shader.gd | 13 +-- addons/material_maker/engine/gen_texture.gd | 2 +- addons/material_maker/engine/io_types.gd | 22 +++++ addons/material_maker/engine/loader.gd | 3 - addons/material_maker/nodes/io_types.mmt | 79 +++++++++++++++ addons/material_maker/nodes/preview_f.shader | 5 + .../material_maker/nodes/preview_rgb.shader | 5 + .../material_maker/nodes/preview_rgba.shader | 5 + .../material_maker/nodes/preview_sdf2d.shader | 10 ++ .../material_maker/nodes/preview_sdf3d.shader | 33 +++++++ .../nodes/preview_sdf3dc.shader | 45 +++++++++ material_maker/graph_edit.gd | 2 +- material_maker/graph_edit.tscn | 3 + material_maker/icons/randomness_locked.tres | 5 +- material_maker/icons/randomness_unlocked.tres | 5 +- material_maker/nodes/generic.gd | 8 +- material_maker/nodes/ios.gd | 2 +- material_maker/nodes/ios/port.gd | 4 +- material_maker/widgets/node_editor/input.gd | 28 ++---- material_maker/widgets/node_editor/input.tscn | 16 ++-- material_maker/widgets/node_editor/output.gd | 36 +++---- .../widgets/node_editor/output.tscn | 12 +-- .../widgets/node_editor/parameter_enum.gd | 4 +- project.godot | 1 + start.gd | 1 - 28 files changed, 280 insertions(+), 167 deletions(-) create mode 100644 addons/material_maker/engine/io_types.gd create mode 100644 addons/material_maker/nodes/io_types.mmt create mode 100644 addons/material_maker/nodes/preview_f.shader create mode 100644 addons/material_maker/nodes/preview_rgb.shader create mode 100644 addons/material_maker/nodes/preview_rgba.shader create mode 100644 addons/material_maker/nodes/preview_sdf2d.shader create mode 100644 addons/material_maker/nodes/preview_sdf3d.shader create mode 100644 addons/material_maker/nodes/preview_sdf3dc.shader diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 73cadbc..3611a75 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -37,17 +37,6 @@ var parameters = {} var seed_locked : bool = false var seed_value : int = 0 -const PORT_TYPE_NAMES : Array = [ "f", "rgb", "rgba", "sdf2d", "sdf3d" ] - -const PORT_TYPES : Dictionary = { - f = { label="Greyscale", type="float", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 0.5) }, - rgb = { label="Color", type="vec3", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 1.0) }, - rgba = { label="RGBA", type="vec4", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.0, 0.5, 0.0, 0.5) }, - sdf2d = { label="SDF2D", type="float", paramdefs="vec2 uv", params="uv", slot_type=1, color=Color(1.0, 0.5, 0.0) }, - sdf3d = { label="SDF3D", type="float", paramdefs="vec3 p", params="p", slot_type=2, color=Color(1.0, 0.0, 0.0) }, - any = { slot_type=42, color=Color(1.0, 1.0, 1.0) } -} - func _ready() -> void: init_parameters() @@ -165,7 +154,7 @@ func get_input_shader(input_index : int) -> Dictionary: func get_shader(output_index : int, context) -> Dictionary: return get_shader_code("UV", output_index, context) -func generate_preview_shader(src_code) -> String: +func generate_preview_shader(src_code, type) -> String: var code code = "shader_type canvas_item;\n" code += "render_mode blend_disabled;\n" @@ -181,55 +170,11 @@ func generate_preview_shader(src_code) -> String: for g in src_code.globals: code += g var shader_code = src_code.defs - if src_code.has("rgba"): - shader_code += "\nvoid fragment() {\n" - shader_code += "vec2 uv = UV;\n" - shader_code += src_code.code - shader_code += "COLOR = "+src_code.rgba+";\n" - shader_code += "}\n" - elif src_code.has("sdf2d"): - shader_code += "\nvoid fragment() {\n" - shader_code += "vec2 uv = UV;\n" - shader_code += src_code.code - shader_code += "float d = "+src_code.sdf2d+";\n" - shader_code += "vec3 col = vec3(cos(d*min(256, preview_size)));\n" - shader_code += "col *= clamp(1.0-d*d, 0.0, 1.0);\n" - shader_code += "col *= vec3(1.0, vec2(step(-0.015, d)));\n" - shader_code += "col *= vec3(vec2(step(d, 0.015)), 1.0);\n" - shader_code += "COLOR = vec4(col, 1.0);\n" - shader_code += "}\n" - elif src_code.has("sdf3d"): - shader_code += "\nfloat calcdist(vec3 uv) {\n" - shader_code += src_code.code - shader_code += "return min("+src_code.sdf3d+", uv.z);\n" - shader_code += "}\n" - shader_code += "float raymarch(vec3 ro, vec3 rd) {\n" - shader_code += "float d=0.0;\n" - shader_code += "for (int i = 0; i < 50; i++) {\n" - shader_code += "vec3 p = ro + rd*d;\n" - shader_code += "float dstep = calcdist(p);\n" - shader_code += "d += dstep;\n" - shader_code += "if (dstep < 0.0001) break;\n" - shader_code += "}\n" - shader_code += "return d;\n" - shader_code += "}\n" - shader_code += "vec3 normal(vec3 p) {\n" - shader_code += " float d = calcdist(p);\n" - shader_code += " float e = .0001;\n" - shader_code += " vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)), calcdist(p-vec3(0.0, e, 0.0)), calcdist(p-vec3(0.0, 0.0, e)));\n" - shader_code += " return normalize(n);\n" - shader_code += "}\n" - shader_code += "\nvoid fragment() {\n" - shader_code += "vec2 uv = UV-vec2(0.5);\n" - shader_code += "vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)));\n" - shader_code += "vec3 n = normal(p);\n" - shader_code += "vec3 l = vec3(5.0, 5.0, 10.0);\n" - shader_code += "vec3 ld = normalize(l-p);\n" - shader_code += "float o = step(p.z, 0.001);\n" - shader_code += "float shadow = 1.0-0.75*step(raymarch(l, -ld), length(l-p)-0.01);\n" - shader_code += "float light = 0.3+0.7*dot(n, ld)*shadow;\n" - shader_code += "COLOR = vec4(vec3(0.8+0.2*o, 0.8+0.2*o, 1.0)*light, 1.0);\n" - shader_code += "}\n" + if src_code.has(type): + var preview_code : String = mm_io_types.types[type].preview + preview_code = preview_code.replace("$(code)", src_code.code) + preview_code = preview_code.replace("$(value)", src_code[type]) + shader_code += preview_code #print("GENERATED SHADER:\n"+shader_code) code += shader_code return code @@ -243,11 +188,11 @@ func render(output_index : int, size : int, preview : bool = false) -> Object: source = { defs="", code="", textures={}, rgba="vec4(0.0)" } var shader : String if preview: + var output_type = "rgba" var outputs = get_output_defs() if outputs.size() > output_index: - var output = outputs[output_index] - print(output) - shader = generate_preview_shader(source) + output_type = outputs[output_index].type + shader = generate_preview_shader(source, output_type) else: shader = mm_renderer.generate_shader(source) var result = mm_renderer.render_shader(shader, source.textures, size) @@ -259,20 +204,15 @@ func get_shader_code(uv : String, output_index : int, context : MMGenContext) -> var rv = _get_shader_code(uv, output_index, context) while rv is GDScriptFunctionState: rv = yield(rv, "completed") - if !rv.empty(): - if !rv.has("f"): - if rv.has("rgb"): - rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)" - elif rv.has("rgba"): - rv.f = "(dot("+rv.rgba+".rgb, vec3(1.0))/3.0)" - if !rv.has("rgb"): - if rv.has("rgba"): - rv.rgb = rv.rgba+".rgb" - elif rv.has("f"): - rv.rgb = "vec3("+rv.f+")" - if !rv.has("rgba"): - if rv.has("rgb"): - rv.rgba = "vec4("+rv.rgb+", 1.0)" + if rv.has("type"): + if mm_io_types.types[rv.type].has("convert"): + for c in mm_io_types.types[rv.type].convert: + if !rv.has(c.type): + var expr = c.expr.replace("$(value)", rv[rv.type]) + rv[c.type] = expr + else: + print("Missing type for node ") + print(rv) return rv func _get_shader_code(__, __, __) -> Dictionary: diff --git a/addons/material_maker/engine/gen_convolution.gd b/addons/material_maker/engine/gen_convolution.gd index ad9b89b..f1b1f61 100644 --- a/addons/material_maker/engine/gen_convolution.gd +++ b/addons/material_maker/engine/gen_convolution.gd @@ -174,6 +174,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) - for t in src_code.textures.keys(): rv.textures[t] = src_code.textures[t] rv[convolution_params.output_type] = "%s_%d" % [ genname, variant_index ] + rv.type = convolution_params.output_type return rv diff --git a/addons/material_maker/engine/gen_ios.gd b/addons/material_maker/engine/gen_ios.gd index d7d30fe..3e2437f 100644 --- a/addons/material_maker/engine/gen_ios.gd +++ b/addons/material_maker/engine/gen_ios.gd @@ -55,7 +55,6 @@ func set_port_name(i : int, n : String) -> void: ports[i].name = n func set_port_type(i : int, t : String) -> void: - print(t) ports[i].type = t emit_signal("parameter_changed", "__update_all__", null) diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index cf6b11b..dc2ac4f 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -55,7 +55,7 @@ func set_shader_model(data: Dictionary) -> void: for i in range(shader_model.outputs.size()): var output = shader_model.outputs[i] var output_code = "" - for f in PORT_TYPES.keys(): + for f in mm_io_types.types.keys(): if output.has(f): shader_model.outputs[i].type = f output_code = output[f] @@ -260,7 +260,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) - var input = shader_model.inputs[i] if input.has("function") and input.function: var source = get_source(i) - var string = "$%s(%s)" % [ input.name, PORT_TYPES[input.type].params ] + var string = "$%s(%s)" % [ input.name, mm_io_types.types[input.type].params ] var local_context = MMGenContext.new(context) var result = replace_input(string, local_context, input.name, input.type, source, input.default) while result is GDScriptFunctionState: @@ -274,7 +274,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) - # Add textures for t in result.textures.keys(): rv.textures[t] = result.textures[t] - rv.defs += "%s %s_input_%s(%s) {\n" % [ PORT_TYPES[input.type].type, genname, input.name, PORT_TYPES[input.type].paramdefs ] + rv.defs += "%s %s_input_%s(%s) {\n" % [ mm_io_types.types[input.type].type, genname, input.name, mm_io_types.types[input.type].paramdefs ] rv.defs += "%s\n" % result.code rv.defs += "return %s;\n}\n" % result.string if shader_model.has("instance"): @@ -307,7 +307,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) - var variant_index = context.get_variant(self, variant_string) if variant_index == -1: variant_index = context.get_variant(self, variant_string) - for f in PORT_TYPES.keys(): + for f in mm_io_types.types.keys(): if output.has(f): var subst_output = subst(output[f], context, uv) while subst_output is GDScriptFunctionState: @@ -320,12 +320,13 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) - rv.defs += subst_output.defs # Add generated code rv.code += subst_output.code - rv.code += "%s %s_%d_%d_%s = %s;\n" % [ PORT_TYPES[f].type, genname, output_index, variant_index, f, subst_output.string ] + rv.code += "%s %s_%d_%d_%s = %s;\n" % [ mm_io_types.types[f].type, genname, output_index, variant_index, f, subst_output.string ] for t in subst_output.textures.keys(): rv.textures[t] = subst_output.textures[t] - for f in PORT_TYPES.keys(): + for f in mm_io_types.types.keys(): if output.has(f): rv[f] = "%s_%d_%d_%s" % [ genname, output_index, variant_index, f ] + rv.type = output.type if shader_model.has("global") && rv.globals.find(shader_model.global) == -1: rv.globals.push_back(shader_model.global) return rv diff --git a/addons/material_maker/engine/gen_texture.gd b/addons/material_maker/engine/gen_texture.gd index 0b90b33..183e15c 100644 --- a/addons/material_maker/engine/gen_texture.gd +++ b/addons/material_maker/engine/gen_texture.gd @@ -13,7 +13,7 @@ func get_output_defs() -> Array: func _get_shader_code_lod(uv : String, output_index : int, context : MMGenContext, lod : float = 0.0) -> Dictionary: var genname = "o"+str(get_instance_id()) - var rv = { globals=[], defs="", code="" } + var rv = { globals=[], defs="", code="", type="rgba" } var texture_name = genname+"_tex" var variant_index = context.get_variant(self, uv) if variant_index == -1: diff --git a/addons/material_maker/engine/io_types.gd b/addons/material_maker/engine/io_types.gd new file mode 100644 index 0000000..5bf862f --- /dev/null +++ b/addons/material_maker/engine/io_types.gd @@ -0,0 +1,22 @@ +tool +extends Node + +var type_names : Array = [] +var types : Dictionary = {} + +func _ready(): + var file = File.new() + if file.open("res://addons/material_maker/nodes/io_types.mmt", File.READ) != OK: + print("Cannot read types") + return false + var type_list = parse_json(file.get_as_text()) + file.close() + for t in type_list: + if t.has("label"): + type_names.push_back(t.name) + var c = t.color + t.color = Color(c.r, c.g, c.b, c.a) + if file.open("res://addons/material_maker/nodes/preview_"+t.name+".shader", File.READ) == OK: + t.preview = file.get_as_text() + file.close() + types[t.name] = t diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index c4cfd41..603da7f 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -3,9 +3,6 @@ extends Node const STD_GENDEF_PATH = "res://addons/material_maker/nodes" -func _ready(): - print("loader ready!") - func generator_name_from_path(path : String) -> String: for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]: print(p) diff --git a/addons/material_maker/nodes/io_types.mmt b/addons/material_maker/nodes/io_types.mmt new file mode 100644 index 0000000..358b22d --- /dev/null +++ b/addons/material_maker/nodes/io_types.mmt @@ -0,0 +1,79 @@ +[ + { + "name":"f", + "label":"Greyscale", + "type":"float", + "paramdefs":"vec2 uv", + "params":"uv", + "slot_type":0, + "convert":[ + { "type":"rgb", "expr":"vec3($(value))" }, + { "type":"rgba", "expr":"vec4(vec3($(value)), 1.0)" } + ], + "color":{ "r":0.5, "g":0.5, "b":0.5, "a":1.0 } + }, + { + "name":"rgb", + "label":"Color", + "type":"vec3", + "paramdefs":"vec2 uv", + "params":"uv", + "slot_type":0, + "convert":[ + { "type":"f", "expr":"(dot($(value), vec3(1.0))/3.0)" }, + { "type":"rgba", "expr":"vec4($(value), 1.0)" } + ], + "color":{ "r":0.5, "g":0.5, "b":1.0, "a":1.0 } + }, + { + "name":"rgba", + "label":"RGBA", + "type":"vec4", + "paramdefs":"vec2 uv", + "params":"uv", + "slot_type":0, + "convert":[ + { "type":"f", "expr":"(dot(($(value)).rgb, vec3(1.0))/3.0)" }, + { "type":"rgb ", "expr":"(($(value)).rgb)" } + ], + "color":{ "r":0.0, "g":0.5, "b":0.0, "a":0.5 } + }, + { + "name":"sdf2d", + "label":"SDF2D", + "type":"float", + "paramdefs":"vec2 uv", + "params":"uv", + "slot_type":1, + "color":{ "r":1.0, "g":0.5, "b":0.0, "a":1.0 } + }, + { + "name":"sdf3d", + "label":"SDF3D", + "type":"float", + "paramdefs":"vec3 p", + "params":"p", + "slot_type":2, + "convert":[ + { "type":"sdf3dc", "expr":"vec2($(value)).rgb, 0.0)" } + ], + "color":{ "r":0.5, "g":0.0, "b":0.0, "a":1.0 } + }, + { + "name":"sdf3dc", + "label":"SDF3D-C", + "type":"vec2", + "paramdefs":"vec3 p", + "params":"p", + "slot_type":2, + "convert":[ + { "type":"sdf3d", "expr":"($(value)).x" } + ], + "color":{ "r":1.0, "g":0.0, "b":0.0, "a":1.0 } + }, + { + "name":"any", + "slot_type":42, + "color":{ "r":1.0, "g":1.0, "b":1.0, "a":1.0 } + } +] diff --git a/addons/material_maker/nodes/preview_f.shader b/addons/material_maker/nodes/preview_f.shader new file mode 100644 index 0000000..fc4f1d5 --- /dev/null +++ b/addons/material_maker/nodes/preview_f.shader @@ -0,0 +1,5 @@ +void fragment() { + vec2 uv = UV; + $(code) + COLOR = vec4(vec3($(value)), 1.0); +} diff --git a/addons/material_maker/nodes/preview_rgb.shader b/addons/material_maker/nodes/preview_rgb.shader new file mode 100644 index 0000000..416d73e --- /dev/null +++ b/addons/material_maker/nodes/preview_rgb.shader @@ -0,0 +1,5 @@ +void fragment() { + vec2 uv = UV; + $(code) + COLOR = vec4($(value), 1.0); +} diff --git a/addons/material_maker/nodes/preview_rgba.shader b/addons/material_maker/nodes/preview_rgba.shader new file mode 100644 index 0000000..be33b4b --- /dev/null +++ b/addons/material_maker/nodes/preview_rgba.shader @@ -0,0 +1,5 @@ +void fragment() { + vec2 uv = UV; + $(code) + COLOR = $(value); +} diff --git a/addons/material_maker/nodes/preview_sdf2d.shader b/addons/material_maker/nodes/preview_sdf2d.shader new file mode 100644 index 0000000..33bbb32 --- /dev/null +++ b/addons/material_maker/nodes/preview_sdf2d.shader @@ -0,0 +1,10 @@ +void fragment() { + vec2 uv = UV; + $(code) + float d = $(value); + vec3 col = vec3(cos(d*min(256, preview_size))); + col *= clamp(1.0-d*d, 0.0, 1.0); + col *= vec3(1.0, vec2(step(-0.015, d))); + col *= vec3(vec2(step(d, 0.015)), 1.0); + COLOR = vec4(col, 1.0); +} diff --git a/addons/material_maker/nodes/preview_sdf3d.shader b/addons/material_maker/nodes/preview_sdf3d.shader new file mode 100644 index 0000000..25d87c6 --- /dev/null +++ b/addons/material_maker/nodes/preview_sdf3d.shader @@ -0,0 +1,33 @@ +float calcdist(vec3 uv) { + $(code) + return min($(value), uv.z); +} + +float raymarch(vec3 ro, vec3 rd) { + float d=0.0; + for (int i = 0; i < 50; i++) { + vec3 p = ro + rd*d; + float dstep = calcdist(p); + d += dstep; + if (dstep < 0.0001) break; + } + return d; +} +vec3 normal(vec3 p) { + float d = calcdist(p); + float e = .0001; + vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)), calcdist(p-vec3(0.0, e, 0.0)), calcdist(p-vec3(0.0, 0.0, e))); + return normalize(n); +} + +void fragment() { + vec2 uv = UV-vec2(0.5); + vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0))); + vec3 n = normal(p); + vec3 l = vec3(5.0, 5.0, 10.0); + vec3 ld = normalize(l-p); + float o = step(p.z, 0.001); + float shadow = 1.0-0.75*step(raymarch(l, -ld), length(l-p)-0.01); + float light = 0.3+0.7*dot(n, ld)*shadow; + COLOR = vec4(vec3(0.8+0.2*o, 0.8+0.2*o, 1.0)*light, 1.0); +} diff --git a/addons/material_maker/nodes/preview_sdf3dc.shader b/addons/material_maker/nodes/preview_sdf3dc.shader new file mode 100644 index 0000000..7c6ebbe --- /dev/null +++ b/addons/material_maker/nodes/preview_sdf3dc.shader @@ -0,0 +1,45 @@ +vec2 calcdist(vec3 uv) { + $(code) + vec2 v = $(value); + return vec2(min(v.x, uv.z), v.y); +} + +vec2 raymarch(vec3 ro, vec3 rd) { + float d=0.0; + float color; + for (int i = 0; i < 50; i++) { + vec3 p = ro + rd*d; + vec2 dstep = calcdist(p); + d += dstep.x; + if (dstep.x < 0.0001) { + color = dstep.y; + break; + } + } + return vec2(d, color); +} +vec3 normal(vec3 p) { + float d = calcdist(p).x; + float e = .0001; + vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)).x, calcdist(p-vec3(0.0, e, 0.0)).x, calcdist(p-vec3(0.0, 0.0, e)).x); + return normalize(n); +} + +vec3 rm_color(float c) { + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(vec3(c) + K.xyz) * 6.0 - K.www); + return 1.0 * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), 1.0); +} + +void fragment() { + vec2 uv = UV-vec2(0.5); + vec2 rm = raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)); + vec3 p = vec3(uv, 2.0-rm.x); + vec3 n = normal(p); + vec3 l = vec3(5.0, 5.0, 10.0); + vec3 ld = normalize(l-p); + float o = step(p.z, 0.001); + float shadow = 1.0-0.75*step(raymarch(l, -ld).x, length(l-p)-0.01); + float light = 0.3+0.7*dot(n, ld)*shadow; + COLOR = vec4(mix(rm_color(fract(rm.y)), vec3(0.9), o)*light, 1.0); +} diff --git a/material_maker/graph_edit.gd b/material_maker/graph_edit.gd index c183c19..3179463 100644 --- a/material_maker/graph_edit.gd +++ b/material_maker/graph_edit.gd @@ -23,7 +23,7 @@ signal graph_changed func _ready() -> void: OS.low_processor_usage_mode = true center_view() - for t in range(5): + for t in range(41): add_valid_connection_type(t, 42) add_valid_connection_type(42, t) diff --git a/material_maker/graph_edit.tscn b/material_maker/graph_edit.tscn index 870f343..b92618f 100644 --- a/material_maker/graph_edit.tscn +++ b/material_maker/graph_edit.tscn @@ -28,6 +28,9 @@ custom_styles/bg = SubResource( 1 ) right_disconnects = true use_snap = false script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} [node name="Timer" type="Timer" parent="."] wait_time = 0.2 diff --git a/material_maker/icons/randomness_locked.tres b/material_maker/icons/randomness_locked.tres index 3068361..c2c5064 100644 --- a/material_maker/icons/randomness_locked.tres +++ b/material_maker/icons/randomness_locked.tres @@ -1,9 +1,8 @@ [gd_resource type="AtlasTexture" load_steps=2 format=2] -[sub_resource type="StreamTexture" id=1] -flags = 4 +[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1] [resource] flags = 4 -atlas = SubResource( 1 ) +atlas = ExtResource( 1 ) region = Rect2( 80, 32, 16, 16 ) diff --git a/material_maker/icons/randomness_unlocked.tres b/material_maker/icons/randomness_unlocked.tres index 1e3ab7e..c5cca43 100644 --- a/material_maker/icons/randomness_unlocked.tres +++ b/material_maker/icons/randomness_unlocked.tres @@ -1,9 +1,8 @@ [gd_resource type="AtlasTexture" load_steps=2 format=2] -[sub_resource type="StreamTexture" id=1] -flags = 4 +[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1] [resource] flags = 4 -atlas = SubResource( 1 ) +atlas = ExtResource( 1 ) region = Rect2( 64, 32, 16, 16 ) diff --git a/material_maker/nodes/generic.gd b/material_maker/nodes/generic.gd index 6d6d2f1..7fdec9f 100644 --- a/material_maker/nodes/generic.gd +++ b/material_maker/nodes/generic.gd @@ -177,8 +177,8 @@ func update_node() -> void: var type_left = 0 if typeof(input) == TYPE_DICTIONARY: enable_left = true - color_left = MMGenBase.PORT_TYPES[input.type].color - type_left = MMGenBase.PORT_TYPES[input.type].slot_type + color_left = mm_io_types.types[input.type].color + type_left = mm_io_types.types[input.type].slot_type set_slot(i, enable_left, type_left, color_left, false, 0, Color()) var hsizer : HBoxContainer = HBoxContainer.new() hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL @@ -251,8 +251,8 @@ func update_node() -> void: assert(typeof(output) == TYPE_DICTIONARY) assert(output.has("type")) enable_right = true - color_right = MMGenBase.PORT_TYPES[output.type].color - type_right = MMGenBase.PORT_TYPES[output.type].slot_type + color_right = mm_io_types.types[output.type].color + type_right = mm_io_types.types[output.type].slot_type set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, type_right, color_right) var hsizer : HBoxContainer while i >= get_child_count(): diff --git a/material_maker/nodes/ios.gd b/material_maker/nodes/ios.gd index fd86ad7..28d1ef2 100644 --- a/material_maker/nodes/ios.gd +++ b/material_maker/nodes/ios.gd @@ -22,7 +22,7 @@ func update_node() -> void: title = generator.get_type_name() var color = Color(0.0, 0.5, 0.0, 0.5) for p in generator.get_io_defs(): - color = MMGenBase.PORT_TYPES[p.type].color + color = mm_io_types.types[p.type].color set_slot(get_child_count(), generator.name != "gen_inputs", 0, color, generator.name != "gen_outputs", 0, color) var port : Control if generator.is_editable(): diff --git a/material_maker/nodes/ios/port.gd b/material_maker/nodes/ios/port.gd index 54f8e6a..db86ad5 100644 --- a/material_maker/nodes/ios/port.gd +++ b/material_maker/nodes/ios/port.gd @@ -4,7 +4,7 @@ func set_label(l : String) -> void: $Name.set_text(l) func set_type(t : String) -> void: - $Type.selected = MMGenBase.PORT_TYPE_NAMES.find(t) + $Type.selected = mm_io_types.type_names.find(t) func update_up_down_button() -> void: var parent = get_parent() @@ -17,7 +17,7 @@ func _on_Name_label_changed(new_label) -> void: get_parent().generator.set_port_name(get_index(), new_label) func _on_Type_item_selected(ID) -> void: - get_parent().generator.set_port_type(get_index(), MMGenBase.PORT_TYPE_NAMES[ID]) + get_parent().generator.set_port_type(get_index(), mm_io_types.type_names[ID]) func _on_Delete_pressed() -> void: get_parent().generator.delete_port(get_index()) diff --git a/material_maker/widgets/node_editor/input.gd b/material_maker/widgets/node_editor/input.gd index 313461b..0db81e9 100644 --- a/material_maker/widgets/node_editor/input.gd +++ b/material_maker/widgets/node_editor/input.gd @@ -1,6 +1,12 @@ tool extends HBoxContainer +func _ready(): + $Type.clear() + for tn in mm_io_types.type_names: + var t = mm_io_types.types[tn] + $Type.add_item(t.label) + func update_up_down_button() -> void: var parent = get_parent() if parent == null: @@ -11,31 +17,13 @@ func update_up_down_button() -> void: func set_model_data(data) -> void: $Name.text = data.name $Label.text = data.label - if data.type == "rgb": - $Type.selected = 1 - elif data.type == "rgba": - $Type.selected = 2 - elif data.type == "sdf2d": - $Type.selected = 3 - elif data.type == "sdf3d": - $Type.selected = 4 - else: - $Type.selected = 0 + $Type.selected = mm_io_types.type_names.find(data.type) $Default.text = data.default $Function.pressed = data.has("function") and data.function func get_model_data() -> Dictionary: var data = { name=$Name.text, label=$Label.text, default=$Default.text } - if $Type.selected == 1: - data.type = "rgb" - elif $Type.selected == 2: - data.type = "rgba" - elif $Type.selected == 3: - data.type = "sdf2d" - elif $Type.selected == 4: - data.type = "sdf3d" - else: - data.type = "f" + data.type = mm_io_types.type_names[$Type.selected] if $Function.pressed: data.function = true return data diff --git a/material_maker/widgets/node_editor/input.tscn b/material_maker/widgets/node_editor/input.tscn index 7f9cff7..6f287fb 100644 --- a/material_maker/widgets/node_editor/input.tscn +++ b/material_maker/widgets/node_editor/input.tscn @@ -3,8 +3,6 @@ [ext_resource path="res://material_maker/widgets/node_editor/input.gd" type="Script" id=1] [ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=2] - - [sub_resource type="AtlasTexture" id=1] flags = 4 atlas = ExtResource( 2 ) @@ -63,17 +61,17 @@ text = "Label" [node name="Type" type="OptionButton" parent="."] margin_left = 236.0 -margin_right = 340.0 +margin_right = 338.0 margin_bottom = 24.0 rect_min_size = Vector2( 102, 0 ) hint_tooltip = "Input flag" -text = "GreyScale" -items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null ] +text = "Greyscale" +items = [ "Greyscale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null, "SDF3D-C", null, false, 5, null ] selected = 0 [node name="Default" type="LineEdit" parent="."] -margin_left = 344.0 -margin_right = 414.0 +margin_left = 342.0 +margin_right = 412.0 margin_bottom = 24.0 rect_min_size = Vector2( 70, 0 ) hint_tooltip = "Default value" @@ -81,8 +79,8 @@ size_flags_horizontal = 3 text = "0.0" [node name="Function" type="CheckBox" parent="."] -margin_left = 418.0 -margin_right = 501.0 +margin_left = 416.0 +margin_right = 499.0 margin_bottom = 24.0 text = "Function" [connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"] diff --git a/material_maker/widgets/node_editor/output.gd b/material_maker/widgets/node_editor/output.gd index 4af81ab..c4b85b3 100644 --- a/material_maker/widgets/node_editor/output.gd +++ b/material_maker/widgets/node_editor/output.gd @@ -1,6 +1,12 @@ tool extends HBoxContainer +func _ready(): + $Type.clear() + for tn in mm_io_types.type_names: + var t = mm_io_types.types[tn] + $Type.add_item(t.label) + func update_up_down_button() -> void: var parent = get_parent() if parent == null: @@ -9,33 +15,13 @@ func update_up_down_button() -> void: $Down.disabled = (get_index() == get_parent().get_child_count()-2) func set_model_data(data) -> void: - if data.has("rgb"): - $Type.selected = 1 - $Value.text = data.rgb - elif data.has("rgba"): - $Type.selected = 2 - $Value.text = data.rgba - elif data.has("sdf2d"): - $Type.selected = 3 - $Value.text = data.sdf2d - elif data.has("sdf3d"): - $Type.selected = 4 - $Value.text = data.sdf3d - elif data.has("f"): - $Type.selected = 0 - $Value.text = data.f + for i in range(mm_io_types.type_names.size()): + if data.has(mm_io_types.type_names[i]): + $Type.selected = i + $Value.text = data[mm_io_types.type_names[i]] func get_model_data() -> Dictionary: - if $Type.selected == 1: - return { rgb=$Value.text } - elif $Type.selected == 2: - return { rgba=$Value.text } - elif $Type.selected == 3: - return { sdf2d=$Value.text } - elif $Type.selected == 4: - return { sdf3d=$Value.text } - else: - return { f=$Value.text } + return { mm_io_types.type_names[$Type.selected]:$Value.text } func _on_Delete_pressed() -> void: var p = get_parent() diff --git a/material_maker/widgets/node_editor/output.tscn b/material_maker/widgets/node_editor/output.tscn index bd67275..f36c1dd 100644 --- a/material_maker/widgets/node_editor/output.tscn +++ b/material_maker/widgets/node_editor/output.tscn @@ -3,8 +3,6 @@ [ext_resource path="res://material_maker/widgets/node_editor/output.gd" type="Script" id=1] [ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=2] - - [sub_resource type="AtlasTexture" id=1] flags = 4 atlas = ExtResource( 2 ) @@ -55,17 +53,17 @@ flat = true [node name="Type" type="OptionButton" parent="."] margin_left = 88.0 -margin_right = 192.0 +margin_right = 190.0 margin_bottom = 25.0 rect_min_size = Vector2( 102, 0 ) hint_tooltip = "Input flag" -text = "GreyScale" -items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null ] +text = "Greyscale" +items = [ "Greyscale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null, "SDF3D-C", null, false, 5, null ] selected = 0 [node name="Value" type="LineEdit" parent="."] -margin_left = 196.0 -margin_right = 290.0 +margin_left = 194.0 +margin_right = 288.0 margin_bottom = 25.0 hint_tooltip = "Default value" size_flags_horizontal = 3 diff --git a/material_maker/widgets/node_editor/parameter_enum.gd b/material_maker/widgets/node_editor/parameter_enum.gd index 1891131..cc36ddc 100644 --- a/material_maker/widgets/node_editor/parameter_enum.gd +++ b/material_maker/widgets/node_editor/parameter_enum.gd @@ -51,14 +51,14 @@ func _on_EnumValues_item_selected(id) -> void: if id >= 0 and id < enum_values.size(): enum_current = id elif id == ENUM_EDIT: - var dialog = load("res://addons/material_maker/widgets/node_editor/enum_editor.tscn").instance() + var dialog = load("res://material_maker/widgets/node_editor/enum_editor.tscn").instance() var v = enum_values[enum_current] add_child(dialog) dialog.set_value(v.name, v.value) dialog.connect("ok", self, "update_enum_value", [ enum_current ]) dialog.popup_centered() elif id == ENUM_ADD: - var dialog = load("res://addons/material_maker/widgets/node_editor/enum_editor.tscn").instance() + var dialog = load("res://material_maker/widgets/node_editor/enum_editor.tscn").instance() add_child(dialog) dialog.connect("ok", self, "update_enum_value", [ -1 ]) dialog.popup_centered() diff --git a/project.godot b/project.godot index c388f7b..407e8c2 100644 --- a/project.godot +++ b/project.godot @@ -183,6 +183,7 @@ config/release="0.8" [autoload] +mm_io_types="*res://addons/material_maker/engine/io_types.gd" mm_loader="*res://addons/material_maker/engine/loader.gd" mm_renderer="*res://addons/material_maker/engine/renderer.tscn" diff --git a/start.gd b/start.gd index c285ddc..c447855 100644 --- a/start.gd +++ b/start.gd @@ -1,7 +1,6 @@ extends Control func _ready(): - print("Loading...") call_deferred("change_scene") func change_scene():