diff --git a/addons/material_maker/engine/nodes/gen_iterate_buffer.gd b/addons/material_maker/engine/nodes/gen_iterate_buffer.gd index f000d53ae..aaf9546a7 100644 --- a/addons/material_maker/engine/nodes/gen_iterate_buffer.gd +++ b/addons/material_maker/engine/nodes/gen_iterate_buffer.gd @@ -127,6 +127,9 @@ func do_update_shaders() -> void: set_current_iteration(0) func set_parameter(n : String, v) -> void: + if is_inside_tree(): + if n == "size": + mm_deps.dependency_update("o%s_it_tex_size" % get_instance_id(), pow(2, v)) super.set_parameter(n, v) set_current_iteration(0) @@ -169,8 +172,8 @@ func on_dep_update_buffer(buffer_name : String) -> bool: await get_tree().process_frame mm_deps.dependency_update(buffer_name, null, true) is_rendering = false - print("Bad iteration") - return false + print("Bad iteration for buffer %s (%d > %d)" % [ buffer_name, current_iteration, iterations ]) + return true var check_current_iteration : int = current_iteration var autostop : bool = get_parameter("autostop") @@ -190,20 +193,23 @@ func on_dep_update_buffer(buffer_name : String) -> bool: if check_current_iteration != current_iteration: mm_deps.dependency_update(buffer_name, texture, true) - print("Iteration mismatch for %s" % buffer_name) + push_warning("Iteration mismatch for %s" % buffer_name) return false - #todo texture.flags = 0 + #print("iteration %d" % current_iteration) # Calculate iteration index if autostop and shader_compute.get_difference() == 0: + #print("autostop at %d" % (current_iteration)) set_current_iteration(iterations+1) else: set_current_iteration(current_iteration+1) + if current_iteration <= iterations: mm_deps.dependency_update("o%d_loop_tex" % get_instance_id(), texture, true) else: - mm_deps.dependency_update("o%d_tex" % get_instance_id(), texture, true) + print("updating texture") + mm_deps.dependency_update("o%d_it_tex" % get_instance_id(), texture, true) mm_deps.dependency_update(buffer_name, texture, true) return status @@ -224,14 +230,14 @@ func get_globals__(texture_name : String) -> Array[String]: func get_adjusted_uv(uv : String) -> String: if not get_parameter("filter"): var genname = "o"+str(get_instance_id()) - return "((floor(%s * %s_tex_size)+vec2(0.5))/%s_tex_size)" % [ uv, genname, genname ] + return "((floor(%s * %s_it_tex_size)+vec2(0.5))/%s_it_tex_size)" % [ uv, genname, genname ] else: return uv func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> ShaderCode: var genname = "o"+str(get_instance_id()) - var shader_code = _get_shader_code_lod(uv, output_index, context, is_greyscale, -1.0, "_tex" if output_index == 0 else "_loop_tex") - shader_code.add_uniform("%s_tex_size" % genname, "float", pow(2, get_parameter("size"))) + var shader_code = _get_shader_code_lod(uv, output_index, context, is_greyscale, -1.0, "_it_tex" if output_index == 0 else "_loop_tex") + shader_code.add_uniform("%s_it_tex_size" % genname, "float", pow(2, get_parameter("size"))) return shader_code func get_output_attributes(output_index : int) -> Dictionary: @@ -240,10 +246,10 @@ func get_output_attributes(output_index : int) -> Dictionary: match output_index: 0: attributes.texture = "%s_tex" % genname - attributes.texture_size = "%s_tex_size" % genname + attributes.texture_size = "%s_it_tex_size" % genname 1: attributes.texture = "%s_loop_tex" % genname - attributes.texture_size = "%s_tex_size" % genname + attributes.texture_size = "%s_it_tex_size" % genname attributes.iteration = iteration_param_name return attributes diff --git a/addons/material_maker/engine/nodes/gen_shader.gd b/addons/material_maker/engine/nodes/gen_shader.gd index 196fe3e42..00649e023 100644 --- a/addons/material_maker/engine/nodes/gen_shader.gd +++ b/addons/material_maker/engine/nodes/gen_shader.gd @@ -623,7 +623,7 @@ func replace_input_new(input_name : String, suffix : String, parameters : String if suffix == "variation": return function_name+parameters else: - return function_name+"("+parameters+", 0.0)" + return function_name+"("+parameters+", _seed_variation_)" var source_rv : ShaderCode = source.generator.get_shader_code(parameters, source.output_index, context) rv.add_uniforms(source_rv.uniforms) rv.defs += source_rv.defs @@ -708,7 +708,7 @@ func get_common_replace_variables(uv : String, rv : ShaderCode) -> Dictionary: if seed_locked: variables["seed"] = "seed_"+genname else: - variables["seed"] = "(seed_"+genname+"+fract(_seed_variation_))" + variables["seed"] = "(seed_"+genname+"+_seed_variation_)" variables["node_id"] = str(get_instance_id()) return variables diff --git a/material_maker/panels/preview_2d/preview_2d.gd b/material_maker/panels/preview_2d/preview_2d.gd index fa30a283a..675f173bc 100644 --- a/material_maker/panels/preview_2d/preview_2d.gd +++ b/material_maker/panels/preview_2d/preview_2d.gd @@ -1,7 +1,7 @@ extends ColorRect -@export var shader_context_defs : String = "" # (String, MULTILINE) -@export var shader : String = "" # (String, MULTILINE) +@export_multiline var shader_context_defs : String = "" # (String, MULTILINE) +@export_multiline var shader : String = "" # (String, MULTILINE) var generator : MMGenBase = null var output : int = 0 @@ -40,11 +40,13 @@ func update_export_menu() -> void: func generate_preview_shader(source, template) -> String: return MMGenBase.generate_preview_shader(source, source.output_type, template) -func do_update_material(source, target_material : ShaderMaterial, template): +func do_update_material(source, target_material : ShaderMaterial, template : String): if source.output_type == "": return is_greyscale = source.output_type == "f" # Update shader + if template.find("TIME") != -1: + print("Template has time") # This should not happen var code = generate_preview_shader(source, template) await mm_deps.buffer_create_shader_material("preview_"+str(get_instance_id()), MMShaderMaterial.new(target_material), code) for u in source.uniforms: diff --git a/material_maker/panels/preview_2d/preview_2d.tscn b/material_maker/panels/preview_2d/preview_2d.tscn index 82efd7efd..15d8d55ed 100644 --- a/material_maker/panels/preview_2d/preview_2d.tscn +++ b/material_maker/panels/preview_2d/preview_2d.tscn @@ -27,13 +27,13 @@ shader = "uniform vec2 preview_2d_size; void fragment() { float ms = max(preview_2d_size.x, preview_2d_size.y); - vec2 uv = fract(0.5+1.2*(UV-vec2(0.5))*ms/preview_2d_size.yx); - float is = min(preview_2d_size.x, preview_2d_size.y)/1.2; - vec2 m2 = min(fract(uv), 1.0-fract(uv)); + vec2 uv = 0.5+(UV-vec2(0.5))*ms/preview_2d_size.yx; + float is = min(preview_2d_size.x, preview_2d_size.y); vec4 image = preview_2d(uv); vec3 image_with_background = mix(vec3(mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0)), image.xyz, image.a); - float lines_color = 0.5*(cos(5.0*TIME+100.0*(uv.x+uv.y))+1.0); - COLOR = vec4(mix(image_with_background, vec3(lines_color), step(is*min(m2.x, m2.y), 1.0)), 1.0); + uv -= vec2(0.5); + uv = abs(uv); + COLOR = vec4(image_with_background, step(max(uv.x, uv.y), 0.5)*0.8+0.2); }" [connection signal="resized" from="." to="." method="on_resized"]