Fixed preview problem, and seeds now depend on node position

This commit is contained in:
RodZill4 2019-10-02 23:06:20 +02:00
parent 8ed10ccd02
commit 57cb3b4a14
10 changed files with 54 additions and 29 deletions

View File

@ -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"

View File

@ -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

View File

@ -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_input_defs():
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():
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":

View File

@ -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:

View File

@ -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={} }

View File

@ -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

View File

@ -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")

View File

@ -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()

View File

@ -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:

View File

@ -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 )