Added optimization for color parameters

This commit is contained in:
RodZill4 2020-03-26 21:58:26 +01:00
parent aad3991734
commit cc606137b3
3 changed files with 15 additions and 3 deletions

View File

@ -126,9 +126,16 @@ func set_parameter(n : String, v) -> void:
var parameter_def : Dictionary = get_parameter_def(n)
if parameter_def.has("type"):
if parameter_def.type == "float":
var parameter_name = "p_o%s_%s" % [ str(get_instance_id()), n ]
var parameter_name = "p_o"+str(get_instance_id())+"_"+n
get_tree().call_group("preview", "on_float_parameters_changed", { parameter_name:v })
return
elif parameter_def.type == "color":
var parameter_changes = {}
for f in [ "r", "g", "b", "a" ]:
var parameter_name = "p_o"+str(get_instance_id())+"_"+n+"_"+f
parameter_changes[parameter_name] = v[f]
get_tree().call_group("preview", "on_float_parameters_changed", parameter_changes)
return
elif parameter_def.type == "gradient":
if v.interpolation == old_value.interpolation && v.points.size() == old_value.points.size():
# convert from old format

View File

@ -199,7 +199,7 @@ func subst(string : String, context : MMGenContext, uv : String = "") -> Diction
value = 0
value_string = p.values[value].value
elif p.type == "color":
value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ]
value_string = "vec4(p_%s_%s_r, p_%s_%s_g, p_%s_%s_b, p_%s_%s_a)" % [ genname, p.name, genname, p.name, genname, p.name, genname, p.name ]
elif p.type == "gradient":
value_string = genname+"_"+p.name+"_gradient_fct"
elif p.type == "boolean":
@ -254,6 +254,11 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
for p in shader_model.parameters:
if p.type == "float":
rv.defs += "uniform float p_%s_%s = %.9f;\n" % [ genname, p.name, parameters[p.name] ]
elif p.type == "color":
rv.defs += "uniform float p_%s_%s_r = %.9f;\n" % [ genname, p.name, parameters[p.name].r ]
rv.defs += "uniform float p_%s_%s_g = %.9f;\n" % [ genname, p.name, parameters[p.name].g ]
rv.defs += "uniform float p_%s_%s_b = %.9f;\n" % [ genname, p.name, parameters[p.name].b ]
rv.defs += "uniform float p_%s_%s_a = %.9f;\n" % [ genname, p.name, parameters[p.name].a ]
elif p.type == "gradient":
var g = parameters[p.name]
if !(g is MMGradient):

View File

@ -46,7 +46,7 @@ func on_parameter_changed(n : String, v) -> void:
var p = generator.get_parameter_def(n)
if p.has("type"):
match p.type:
"float", "gradient":
"float", "color", "gradient":
pass
_:
set_generator(generator, output)