Added iteration attribute to the Iteration Buffer node
This commit is contained in:
parent
0b0e268da9
commit
de6543f910
|
@ -53,11 +53,11 @@ func get_output_defs() -> Array:
|
|||
return [ { type="rgba" }, { type="rgba" } ]
|
||||
|
||||
func source_changed(input_port_index : int) -> void:
|
||||
current_iteration = 0
|
||||
set_current_iteration(0)
|
||||
call_deferred("update_shader", input_port_index)
|
||||
|
||||
func all_sources_changed() -> void:
|
||||
current_iteration = 0
|
||||
set_current_iteration(0)
|
||||
call_deferred("update_shader", 0)
|
||||
call_deferred("update_shader", 1)
|
||||
|
||||
|
@ -98,7 +98,7 @@ func set_pending() -> void:
|
|||
|
||||
func set_parameter(n : String, v) -> void:
|
||||
.set_parameter(n, v)
|
||||
current_iteration = 0
|
||||
set_current_iteration(0)
|
||||
if is_inside_tree():
|
||||
update_buffer()
|
||||
|
||||
|
@ -106,11 +106,12 @@ func on_float_parameters_changed(parameter_changes : Dictionary) -> void:
|
|||
var do_update : bool = false
|
||||
if parameter_changes.has("p_o%s_iterations" % str(get_instance_id())):
|
||||
do_update = true
|
||||
var not_just_iteration = parameter_changes.size() > 1 or not parameter_changes.has("o%s_iteration" % str(get_instance_id()))
|
||||
for i in range(2):
|
||||
var m : Material = [ material, loop_material ][i]
|
||||
if mm_renderer.update_float_parameters(m, parameter_changes):
|
||||
if mm_renderer.update_float_parameters(m, parameter_changes) and not_just_iteration:
|
||||
update_again = true
|
||||
current_iteration = 0
|
||||
set_current_iteration(0)
|
||||
if pending_textures[i].empty():
|
||||
update_buffer()
|
||||
|
||||
|
@ -122,7 +123,7 @@ func on_texture_changed(n : String) -> void:
|
|||
for p in VisualServer.shader_get_param_list(m.shader.get_rid()):
|
||||
if p.name == n:
|
||||
if i == 0:
|
||||
current_iteration = 0
|
||||
set_current_iteration(0)
|
||||
update_buffer()
|
||||
return
|
||||
|
||||
|
@ -137,6 +138,13 @@ func on_texture_invalidated(n : String) -> void:
|
|||
if pending_textures[i].find(n) == -1:
|
||||
pending_textures[i].push_back(n)
|
||||
|
||||
func set_current_iteration(i : int) -> void:
|
||||
current_iteration = i
|
||||
var iteration_param_name = "o%s_iteration" % str(get_instance_id())
|
||||
if is_inside_tree():
|
||||
get_tree().call_group("preview", "on_float_parameters_changed", { iteration_param_name:current_iteration })
|
||||
|
||||
|
||||
func update_buffer() -> void:
|
||||
update_again = true
|
||||
if !updating:
|
||||
|
@ -164,14 +172,14 @@ func update_buffer() -> void:
|
|||
renderer.release(self)
|
||||
current_renderer = null
|
||||
updating = false
|
||||
if current_iteration < get_parameter("iterations"):
|
||||
set_current_iteration(current_iteration+1)
|
||||
if current_iteration <= get_parameter("iterations"):
|
||||
get_tree().call_group("preview", "on_texture_changed", "o%s_loop_tex" % str(get_instance_id()))
|
||||
else:
|
||||
get_tree().call_group("preview", "on_texture_changed", "o%s_tex" % str(get_instance_id()))
|
||||
current_iteration += 1
|
||||
|
||||
func get_globals(texture_name : String) -> Array:
|
||||
var texture_globals : String = "uniform sampler2D %s;\nuniform float %s_size = %d.0;\n" % [ texture_name, texture_name, pow(2, get_parameter("size")) ]
|
||||
var texture_globals : String = "uniform sampler2D %s;\nuniform float %s_size = %d.0;\nuniform float o%s_iteration = 0.0;\n" % [ texture_name, texture_name, pow(2, get_parameter("size")), str(get_instance_id()) ]
|
||||
return [ texture_globals ]
|
||||
|
||||
func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary:
|
||||
|
|
|
@ -274,10 +274,11 @@ func subst(string : String, context : MMGenContext, uv : String = "") -> Diction
|
|||
if source == null:
|
||||
continue
|
||||
var src_attributes = source.generator.get_output_attributes(source.output_index)
|
||||
if src_attributes.has("texture"):
|
||||
variables[input.name+".texture"] = src_attributes.texture
|
||||
if src_attributes.has("texture_size"):
|
||||
variables[input.name+".size"] = src_attributes.texture_size
|
||||
for a in src_attributes.keys():
|
||||
if a == "texture_size":
|
||||
variables[input.name+".size"] = src_attributes.texture_size
|
||||
else:
|
||||
variables[input.name+"."+a] = src_attributes[a]
|
||||
string = replace_variables(string, variables)
|
||||
if shader_model.has("inputs") and typeof(shader_model.inputs) == TYPE_ARRAY:
|
||||
var cont = true
|
||||
|
|
Loading…
Reference in New Issue