Added float parameter filtering and optimization for texture parameters.

This commit is contained in:
RodZill4 2020-03-20 07:44:22 +01:00
parent 3c87f2c491
commit 31545cb20c
4 changed files with 42 additions and 24 deletions

View File

@ -55,10 +55,19 @@ func source_changed(_input_port_index : int) -> void:
update_buffer()
func on_float_parameter_changed(n : String, v : float) -> void:
material.set_shader_param(n, v)
update_buffer()
for p in VisualServer.shader_get_param_list(material.shader.get_rid()):
if p.name == n:
material.set_shader_param(n, v)
update_buffer()
return
func update_buffer():
func on_texture_changed(n : String) -> void:
for p in VisualServer.shader_get_param_list(material.shader.get_rid()):
if p.name == n:
update_buffer()
return
func update_buffer() -> void:
update_again = true
if !updating:
updating = true
@ -71,20 +80,7 @@ func update_buffer():
result.copy_to_texture(texture)
result.release()
updating = false
func __get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary:
var source = get_source(0)
if source != null:
var result = source.generator.render(source.output_index, pow(2, parameters.size))
while result is GDScriptFunctionState:
result = yield(result, "completed")
result.copy_to_texture(texture)
result.release()
texture.flags = Texture.FLAG_MIPMAPS
var rv = ._get_shader_code_lod(uv, output_index, context, 0 if output_index == 0 else parameters.lod)
while rv is GDScriptFunctionState:
rv = yield(rv, "completed")
return rv
get_tree().call_group("preview", "on_texture_changed", "o%s_tex" % str(get_instance_id()))
func _serialize(data: Dictionary) -> Dictionary:
data.type = "buffer"

View File

@ -7,6 +7,7 @@ var export_paths = {}
var material : SpatialMaterial
var shader_materials = {}
var need_update = {}
var need_render = {}
var generated_textures = {}
var updating : bool = false
var update_again : bool = false
@ -43,6 +44,7 @@ func _ready() -> void:
for t in TEXTURE_LIST:
generated_textures[t.texture] = null
need_update[t.texture] = true
need_render[t.texture] = true
shader_materials[t.texture] = ShaderMaterial.new()
shader_materials[t.texture].shader = Shader.new()
material = SpatialMaterial.new()
@ -122,17 +124,34 @@ func render_textures() -> void:
need_update[t.texture] = false
func on_float_parameter_changed(n : String, v : float) -> void:
var image_size = get_image_size()
for t in TEXTURE_LIST:
if generated_textures[t.texture] != null:
shader_materials[t.texture].set_shader_param(n, v)
for p in VisualServer.shader_get_param_list(shader_materials[t.texture].shader.get_rid()):
if p.name == n:
shader_materials[t.texture].set_shader_param(n, v)
need_render[t.texture] = true
update_textures()
break
func on_texture_changed(n : String) -> void:
for t in TEXTURE_LIST:
if generated_textures[t.texture] != null:
for p in VisualServer.shader_get_param_list(shader_materials[t.texture].shader.get_rid()):
if p.name == n:
need_render[t.texture] = true
update_textures()
break
func update_textures() -> void:
update_again = true
if !updating:
var image_size = get_image_size()
updating = true
while update_again:
update_again = false
for t in TEXTURE_LIST:
if generated_textures[t.texture] != null:
if need_render[t.texture]:
var result = mm_renderer.render_material(shader_materials[t.texture], image_size)
while result is GDScriptFunctionState:
result = yield(result, "completed")

View File

@ -82,7 +82,7 @@ func initialize_properties() -> void:
print("unsupported widget "+str(o))
func update_shaders() -> void:
get_parent().send_changed_signal()
#get_parent().send_changed_signal()
update_preview()
func _on_text_changed(new_text, variable) -> void:

View File

@ -4,7 +4,7 @@ export(String, MULTILINE) var shader : String = ""
var generator : MMGenBase = null
func set_generator(g : MMGenBase) -> void:
func set_generator(g : MMGenBase, output : int = 0) -> void:
var source = { defs="", code="", textures={}, type="f", f="1.0" }
if is_instance_valid(g):
generator = g
@ -14,7 +14,7 @@ func set_generator(g : MMGenBase) -> void:
var gen_output_defs = generator.get_output_defs()
if ! gen_output_defs.empty():
var context : MMGenContext = MMGenContext.new()
source = generator.get_shader_code("uv", 0, context)
source = generator.get_shader_code("uv", output, context)
while source is GDScriptFunctionState:
source = yield(source, "completed")
if source.empty():
@ -29,7 +29,10 @@ func set_generator(g : MMGenBase) -> void:
material.set_shader_param(k, source.textures[k])
func on_float_parameter_changed(n : String, v : float) -> void:
material.set_shader_param(n, v)
for p in VisualServer.shader_get_param_list(material.shader.get_rid()):
if p.name == n:
material.set_shader_param(n, v)
return
func on_resized() -> void:
material.set_shader_param("size", rect_size)