From 57cb3b4a14bb3b02aaa24a70c87ca2ce54b69f78 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 2 Oct 2019 23:06:20 +0200 Subject: [PATCH] Fixed preview problem, and seeds now depend on node position --- addons/material_maker/engine/gen_base.gd | 5 ++-- addons/material_maker/engine/gen_graph.gd | 13 +++++++--- addons/material_maker/engine/gen_ios.gd | 25 ++++++++------------ addons/material_maker/engine/gen_material.gd | 13 +++++++++- addons/material_maker/engine/gen_shader.gd | 16 ++++++++++++- addons/material_maker/engine/renderer.gd | 3 ++- addons/material_maker/graph_edit.gd | 2 +- addons/material_maker/main_window.gd | 3 --- addons/material_maker/nodes/generic.gd | 2 +- addons/material_maker/preview_objects.tscn | 1 + 10 files changed, 54 insertions(+), 29 deletions(-) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 25f05c8..e046681 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -7,7 +7,6 @@ Base class for texture generators, that defines their API """ signal parameter_changed -signal update_textures class InputPort: var generator : MMGenBase = null @@ -46,8 +45,8 @@ func init_parameters(): else: print("No default value for parameter "+p.name) -func get_seed(): - return 0 +func set_position(p): + position = p func get_type(): return "generic" diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index e22f1c2..2ec4c89 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -22,12 +22,12 @@ func set_parameter(p, v): func get_input_defs(): if has_node("gen_inputs"): - return get_node("gen_inputs").get_input_defs() + return get_node("gen_inputs").get_output_defs() return [] func get_output_defs(): if has_node("gen_outputs"): - return get_node("gen_outputs").get_output_defs() + return get_node("gen_outputs").get_input_defs() return [] func source_changed(input_index : int): @@ -155,7 +155,14 @@ func create_subgraph(generators): my_new_connections.push_back( { from=new_graph.name, from_port=port_index, to=c.to, to_port=c.to_port } ) new_graph_connections.push_back( { from=c.from, from_port=c.from_port, to="gen_outputs", to_port=port_index } ) elif names.find(c.to) != -1: - print("3: "+str(c)) + if inputs == null: + inputs = MMGenIOs.new() + inputs.name = "gen_inputs" + new_graph.add_generator(inputs) + var port_index = inputs.ports.size() + inputs.ports.push_back( { name="port"+str(port_index), type="rgba" } ) + my_new_connections.push_back( { from=c.from, from_port=c.from_port, to=new_graph.name, to_port=port_index } ) + new_graph_connections.push_back( { from="gen_inputs", from_port=port_index, to=c.to, to_port=c.to_port } ) else: my_new_connections.push_back(c) connections = my_new_connections diff --git a/addons/material_maker/engine/gen_ios.gd b/addons/material_maker/engine/gen_ios.gd index ae530b5..1ce1d8c 100644 --- a/addons/material_maker/engine/gen_ios.gd +++ b/addons/material_maker/engine/gen_ios.gd @@ -9,10 +9,6 @@ IOs just forward their inputs to their outputs and are used to specify graph int var mask : int = 3 var ports : Array = [] -func _ready(): - if !parameters.has("size"): - parameters.size = 4 - func get_type(): return "buffer" @@ -23,19 +19,18 @@ func get_type_name(): _: return "IOs" return "Buffer" +func get_io_defs(): + var rv : Array = [] + if mask != 2: + for p in ports: + rv.push_back({ name=p.name, type="rgba" }) + return rv + func get_input_defs(): - var rv : Array = [] - if mask != 2: - for p in ports: - rv.push_back({ name=p.name, type="rgba" }) - return rv - + return [] if name == "gen_inputs" else get_io_defs() + func get_output_defs(): - var rv : Array = [] - if mask != 2: - for p in ports: - rv.push_back({ name=p.name, type="rgba" }) - return rv + return [] if name == "gen_outputs" else get_io_defs() func source_changed(input_index : int): if name == "gen_outputs": diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 0f00ef8..2fe6e2c 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -49,8 +49,19 @@ func get_input_defs(): { name="depth_texture", label="", type="f" } ] +func update_preview(): + var graph_edit = self + while graph_edit is MMGenBase: + graph_edit = graph_edit.get_parent() + if graph_edit.has_method("send_changed_signal"): + graph_edit.send_changed_signal() + +func set_parameter(p, v): + .set_parameter(p, v) + update_preview() + func source_changed(input_index : int): - emit_signal("update_textures") + update_preview() func render_textures(renderer : MMGenRenderer): for t in texture_list: diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 0709cb1..b610d6e 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -3,6 +3,7 @@ extends MMGenBase class_name MMGenShader var shader_model : Dictionary = {} +var uses_seed = false func get_type(): return "shader" @@ -43,6 +44,15 @@ func set_shader_model(data: Dictionary): else: shader_model.outputs[i].type = "f" +func set_position(p): + .set_position(p) + if uses_seed: + source_changed(0) + +func get_seed(): + var s = ((int(position.x) * 0x1f1f1f1f) ^ int(position.y)) % 65536 + return s + func find_keyword_call(string, keyword): var search_string = "$%s(" % keyword var position = string.find(search_string) @@ -124,7 +134,10 @@ func subst(string, context, uv = ""): var required_code = "" var required_textures = {} string = replace_variable(string, "name", genname) - string = replace_variable(string, "seed", str(get_seed())) + var tmp_string = replace_variable(string, "seed", str(get_seed())) + if tmp_string != string: + string = tmp_string + uses_seed = true if uv != "": string = replace_variable(string, "uv", "("+uv+")") if shader_model.has("parameters") and typeof(shader_model.parameters) == TYPE_ARRAY: @@ -179,6 +192,7 @@ func subst(string, context, uv = ""): return { string=string, globals=required_globals, defs=required_defs, code=required_code, textures=required_textures } func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + uses_seed = false var genname = "o"+str(get_instance_id()) var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ] var rv = { globals=[], defs="", code="", textures={} } diff --git a/addons/material_maker/engine/renderer.gd b/addons/material_maker/engine/renderer.gd index f9f8d02..6f7789f 100644 --- a/addons/material_maker/engine/renderer.gd +++ b/addons/material_maker/engine/renderer.gd @@ -93,5 +93,6 @@ func render_shader(shader, textures, render_size): yield(get_tree(), "idle_frame") yield(get_tree(), "idle_frame") rendering = false - return true emit_signal("done") + return true + diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 825b9a3..854665f 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -260,7 +260,7 @@ func paste(pos = Vector2(0, 0)): func send_changed_signal(): set_need_save(true) - $Timer.start() + $Timer.start(0.1) func do_send_changed_signal(): emit_signal("graph_changed") diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index dab2864..a3afb78 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -166,11 +166,9 @@ func do_load_material(filename): node_count = 0 for c in graph_edit.get_children(): if c is GraphNode: - print(c.name) node_count += 1 if node_count > 1: break - print(node_count) if node_count > 1: graph_edit = new_pane() graph_edit.load_file(filename) @@ -259,7 +257,6 @@ func make_selected_nodes_editable(): var selected_nodes = get_selected_nodes() if !selected_nodes.empty(): for n in selected_nodes: - print(n.name) n.generator.model = null n.update_node() diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 722d5f4..606efb3 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -16,7 +16,7 @@ func on_close_request(): generator.get_parent().remove_generator(generator) func on_offset_changed(): - generator.position = offset + generator.set_position(offset) func on_parameter_changed(p, v): if ignore_parameter_change == p: diff --git a/addons/material_maker/preview_objects.tscn b/addons/material_maker/preview_objects.tscn index 3ae7a4f..a0bcf66 100644 --- a/addons/material_maker/preview_objects.tscn +++ b/addons/material_maker/preview_objects.tscn @@ -53,6 +53,7 @@ mesh = SubResource( 3 ) material/0 = SubResource( 4 ) [node name="Sphere" type="MeshInstance" parent="."] +visible = false mesh = SubResource( 5 ) material/0 = SubResource( 6 )