mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Fixed preview problem, and seeds now depend on node position
This commit is contained in:
parent
8ed10ccd02
commit
57cb3b4a14
@ -7,7 +7,6 @@ Base class for texture generators, that defines their API
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
signal parameter_changed
|
signal parameter_changed
|
||||||
signal update_textures
|
|
||||||
|
|
||||||
class InputPort:
|
class InputPort:
|
||||||
var generator : MMGenBase = null
|
var generator : MMGenBase = null
|
||||||
@ -46,8 +45,8 @@ func init_parameters():
|
|||||||
else:
|
else:
|
||||||
print("No default value for parameter "+p.name)
|
print("No default value for parameter "+p.name)
|
||||||
|
|
||||||
func get_seed():
|
func set_position(p):
|
||||||
return 0
|
position = p
|
||||||
|
|
||||||
func get_type():
|
func get_type():
|
||||||
return "generic"
|
return "generic"
|
||||||
|
@ -22,12 +22,12 @@ func set_parameter(p, v):
|
|||||||
|
|
||||||
func get_input_defs():
|
func get_input_defs():
|
||||||
if has_node("gen_inputs"):
|
if has_node("gen_inputs"):
|
||||||
return get_node("gen_inputs").get_input_defs()
|
return get_node("gen_inputs").get_output_defs()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
func get_output_defs():
|
func get_output_defs():
|
||||||
if has_node("gen_outputs"):
|
if has_node("gen_outputs"):
|
||||||
return get_node("gen_outputs").get_output_defs()
|
return get_node("gen_outputs").get_input_defs()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
func source_changed(input_index : int):
|
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 } )
|
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 } )
|
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:
|
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:
|
else:
|
||||||
my_new_connections.push_back(c)
|
my_new_connections.push_back(c)
|
||||||
connections = my_new_connections
|
connections = my_new_connections
|
||||||
|
@ -9,10 +9,6 @@ IOs just forward their inputs to their outputs and are used to specify graph int
|
|||||||
var mask : int = 3
|
var mask : int = 3
|
||||||
var ports : Array = []
|
var ports : Array = []
|
||||||
|
|
||||||
func _ready():
|
|
||||||
if !parameters.has("size"):
|
|
||||||
parameters.size = 4
|
|
||||||
|
|
||||||
func get_type():
|
func get_type():
|
||||||
return "buffer"
|
return "buffer"
|
||||||
|
|
||||||
@ -23,19 +19,18 @@ func get_type_name():
|
|||||||
_: return "IOs"
|
_: return "IOs"
|
||||||
return "Buffer"
|
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():
|
func get_input_defs():
|
||||||
var rv : Array = []
|
return [] if name == "gen_inputs" else get_io_defs()
|
||||||
if mask != 2:
|
|
||||||
for p in ports:
|
|
||||||
rv.push_back({ name=p.name, type="rgba" })
|
|
||||||
return rv
|
|
||||||
|
|
||||||
func get_output_defs():
|
func get_output_defs():
|
||||||
var rv : Array = []
|
return [] if name == "gen_outputs" else get_io_defs()
|
||||||
if mask != 2:
|
|
||||||
for p in ports:
|
|
||||||
rv.push_back({ name=p.name, type="rgba" })
|
|
||||||
return rv
|
|
||||||
|
|
||||||
func source_changed(input_index : int):
|
func source_changed(input_index : int):
|
||||||
if name == "gen_outputs":
|
if name == "gen_outputs":
|
||||||
|
@ -49,8 +49,19 @@ func get_input_defs():
|
|||||||
{ name="depth_texture", label="", type="f" }
|
{ 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):
|
func source_changed(input_index : int):
|
||||||
emit_signal("update_textures")
|
update_preview()
|
||||||
|
|
||||||
func render_textures(renderer : MMGenRenderer):
|
func render_textures(renderer : MMGenRenderer):
|
||||||
for t in texture_list:
|
for t in texture_list:
|
||||||
|
@ -3,6 +3,7 @@ extends MMGenBase
|
|||||||
class_name MMGenShader
|
class_name MMGenShader
|
||||||
|
|
||||||
var shader_model : Dictionary = {}
|
var shader_model : Dictionary = {}
|
||||||
|
var uses_seed = false
|
||||||
|
|
||||||
func get_type():
|
func get_type():
|
||||||
return "shader"
|
return "shader"
|
||||||
@ -43,6 +44,15 @@ func set_shader_model(data: Dictionary):
|
|||||||
else:
|
else:
|
||||||
shader_model.outputs[i].type = "f"
|
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):
|
func find_keyword_call(string, keyword):
|
||||||
var search_string = "$%s(" % keyword
|
var search_string = "$%s(" % keyword
|
||||||
var position = string.find(search_string)
|
var position = string.find(search_string)
|
||||||
@ -124,7 +134,10 @@ func subst(string, context, uv = ""):
|
|||||||
var required_code = ""
|
var required_code = ""
|
||||||
var required_textures = {}
|
var required_textures = {}
|
||||||
string = replace_variable(string, "name", genname)
|
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 != "":
|
if uv != "":
|
||||||
string = replace_variable(string, "uv", "("+uv+")")
|
string = replace_variable(string, "uv", "("+uv+")")
|
||||||
if shader_model.has("parameters") and typeof(shader_model.parameters) == TYPE_ARRAY:
|
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 }
|
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):
|
func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||||
|
uses_seed = false
|
||||||
var genname = "o"+str(get_instance_id())
|
var genname = "o"+str(get_instance_id())
|
||||||
var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ]
|
var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ]
|
||||||
var rv = { globals=[], defs="", code="", textures={} }
|
var rv = { globals=[], defs="", code="", textures={} }
|
||||||
|
@ -93,5 +93,6 @@ func render_shader(shader, textures, render_size):
|
|||||||
yield(get_tree(), "idle_frame")
|
yield(get_tree(), "idle_frame")
|
||||||
yield(get_tree(), "idle_frame")
|
yield(get_tree(), "idle_frame")
|
||||||
rendering = false
|
rendering = false
|
||||||
return true
|
|
||||||
emit_signal("done")
|
emit_signal("done")
|
||||||
|
return true
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ func paste(pos = Vector2(0, 0)):
|
|||||||
|
|
||||||
func send_changed_signal():
|
func send_changed_signal():
|
||||||
set_need_save(true)
|
set_need_save(true)
|
||||||
$Timer.start()
|
$Timer.start(0.1)
|
||||||
|
|
||||||
func do_send_changed_signal():
|
func do_send_changed_signal():
|
||||||
emit_signal("graph_changed")
|
emit_signal("graph_changed")
|
||||||
|
@ -166,11 +166,9 @@ func do_load_material(filename):
|
|||||||
node_count = 0
|
node_count = 0
|
||||||
for c in graph_edit.get_children():
|
for c in graph_edit.get_children():
|
||||||
if c is GraphNode:
|
if c is GraphNode:
|
||||||
print(c.name)
|
|
||||||
node_count += 1
|
node_count += 1
|
||||||
if node_count > 1:
|
if node_count > 1:
|
||||||
break
|
break
|
||||||
print(node_count)
|
|
||||||
if node_count > 1:
|
if node_count > 1:
|
||||||
graph_edit = new_pane()
|
graph_edit = new_pane()
|
||||||
graph_edit.load_file(filename)
|
graph_edit.load_file(filename)
|
||||||
@ -259,7 +257,6 @@ func make_selected_nodes_editable():
|
|||||||
var selected_nodes = get_selected_nodes()
|
var selected_nodes = get_selected_nodes()
|
||||||
if !selected_nodes.empty():
|
if !selected_nodes.empty():
|
||||||
for n in selected_nodes:
|
for n in selected_nodes:
|
||||||
print(n.name)
|
|
||||||
n.generator.model = null
|
n.generator.model = null
|
||||||
n.update_node()
|
n.update_node()
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func on_close_request():
|
|||||||
generator.get_parent().remove_generator(generator)
|
generator.get_parent().remove_generator(generator)
|
||||||
|
|
||||||
func on_offset_changed():
|
func on_offset_changed():
|
||||||
generator.position = offset
|
generator.set_position(offset)
|
||||||
|
|
||||||
func on_parameter_changed(p, v):
|
func on_parameter_changed(p, v):
|
||||||
if ignore_parameter_change == p:
|
if ignore_parameter_change == p:
|
||||||
|
@ -53,6 +53,7 @@ mesh = SubResource( 3 )
|
|||||||
material/0 = SubResource( 4 )
|
material/0 = SubResource( 4 )
|
||||||
|
|
||||||
[node name="Sphere" type="MeshInstance" parent="."]
|
[node name="Sphere" type="MeshInstance" parent="."]
|
||||||
|
visible = false
|
||||||
mesh = SubResource( 5 )
|
mesh = SubResource( 5 )
|
||||||
material/0 = SubResource( 6 )
|
material/0 = SubResource( 6 )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user