Generic node updates

- Added support for inputs and alternate syntax for parameters ($foo instead of $(foo))
- Added support for default input values ($uv can be used for non uniform defaults)
This commit is contained in:
RodZill4 2018-11-19 23:09:22 +01:00
parent f06ffaf9f7
commit 3bb9dd50db
6 changed files with 61 additions and 40 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"connections":[{"from":"bricks_0","from_port":0,"to":"blend_0","to_port":0},{"from":"perlin_0","from_port":0,"to":"blend_0","to_port":1},{"from":"normal_map_0","from_port":0,"to":"Material","to_port":4},{"from":"perlin_1","from_port":0,"to":"colorize_2","to_port":0},{"from":"colorize_0","from_port":0,"to":"blend_1","to_port":1},{"from":"perlin_2","from_port":0,"to":"colorize_3","to_port":0},{"from":"colorize_3","from_port":0,"to":"blend_1","to_port":2},{"from":"blend_1","from_port":0,"to":"Material","to_port":0},{"from":"colorize_3","from_port":0,"to":"blend_2","to_port":0},{"from":"blend_2","from_port":0,"to":"Material","to_port":2},{"from":"blend_0","from_port":0,"to":"colorize_0","to_port":0},{"from":"blend_0","from_port":0,"to":"colorize_5","to_port":0},{"from":"colorize_5","from_port":0,"to":"normal_map_0","to_port":0},{"from":"uniform_1","from_port":0,"to":"Material","to_port":1},{"from":"uniform_0","from_port":0,"to":"blend_2","to_port":1},{"from":"perlin_1","from_port":0,"to":"colorize_1","to_port":0},{"from":"combine_0","from_port":0,"to":"export_0","to_port":0},{"from":"uniform_1","from_port":0,"to":"combine_0","to_port":0},{"from":"blend_2","from_port":0,"to":"combine_0","to_port":1},{"from":"colorize_2","from_port":0,"to":"blend_1","to_port":0}],"nodes":[{"name":"Material","node_position":{"x":938,"y":96},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"},{"name":"colorize_3","node_position":{"x":487.633789,"y":65},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0.518182,"r":0},{"a":1,"b":1,"g":1,"pos":0.709091,"r":1}],"type":"Gradient"}},"type":"colorize"},{"name":"bricks_0","node_position":{"x":-1,"y":30.5},"parameters":{"bevel":0,"columns":5,"mortar":0.02,"pattern":0,"repeat":1,"row_offset":0.5,"rows":1},"type":"bricks"},{"name":"colorize_0","node_position":{"x":472,"y":-41.5},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0.336914,"pos":0,"r":0.598958},{"a":1,"b":0,"g":0.454102,"pos":0.118182,"r":0.807292},{"a":1,"b":0,"g":0.37793,"pos":0.245455,"r":0.671875},{"a":1,"b":0,"g":0.427734,"pos":0.345455,"r":0.760417},{"a":1,"b":0.017795,"g":0.488254,"pos":0.527273,"r":0.854167},{"a":1,"b":0,"g":0.37793,"pos":0.645455,"r":0.671875},{"a":1,"b":0,"g":0.439453,"pos":0.845455,"r":0.78125},{"a":1,"b":0,"g":0.357422,"pos":1,"r":0.635417}],"type":"Gradient"}},"type":"colorize"},{"name":"perlin_1","node_position":{"x":110.633789,"y":-143.5},"parameters":{"iterations":7,"persistence":0.55,"scale_x":4,"scale_y":4},"type":"perlin"},{"name":"blend_2","node_position":{"x":690.633789,"y":201.5},"parameters":{"amount":0.4,"blend_type":0},"type":"blend"},{"name":"perlin_2","node_position":{"x":232.633789,"y":40},"parameters":{"iterations":6,"persistence":0.65,"scale_x":4,"scale_y":4},"type":"perlin"},{"name":"normal_map_0","node_position":{"x":724.633789,"y":345.5},"parameters":{"amount":0.15,"size":2},"type":"normal_map"},{"name":"blend_1","node_position":{"x":707.633789,"y":-68},"parameters":{"amount":0.5,"blend_type":0},"type":"blend"},{"name":"blend_0","node_position":{"x":271,"y":306.5},"parameters":{"amount":1,"blend_type":2},"type":"blend"},{"name":"colorize_5","node_position":{"x":503,"y":336.5},"parameters":{"gradient":{"points":[{"a":1,"b":1,"g":1,"pos":0,"r":1},{"a":1,"b":0,"g":0,"pos":1,"r":0}],"type":"Gradient"}},"type":"colorize"},{"name":"uniform_1","node_position":{"x":753,"y":116},"parameters":{"color":{"a":1,"b":0,"g":0,"r":0,"type":"Color"}},"type":"uniform"},{"name":"uniform_0","node_position":{"x":540,"y":234},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"}},"type":"uniform"},{"name":"colorize_2","node_position":{"x":454.633789,"y":-189.5},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0.515625},{"a":1,"b":0,"g":0,"pos":0.145455,"r":0.25},{"a":1,"b":0,"g":0,"pos":0.445455,"r":0.515625},{"a":1,"b":0.013184,"g":0.013184,"pos":0.745455,"r":0.28125},{"a":1,"b":0,"g":0,"pos":1,"r":0.322917}],"type":"Gradient"}},"type":"colorize"},{"name":"colorize_1","node_position":{"x":461.329102,"y":-116.699997},"parameters":{"gradient":{"points":[{"a":1,"b":0.034912,"g":0.129532,"pos":0,"r":0.203125},{"a":1,"b":0.038791,"g":0.074319,"pos":1,"r":0.114583}],"type":"Gradient"}},"type":"colorize"},{"name":"export_0","node_position":{"x":1090.329102,"y":-76.5},"parameters":{"resolution":1},"suffix":"mr","type":"export"},{"name":"combine_0","node_position":{"x":942.329102,"y":-55.5},"parameters":{},"type":"combine"},{"name":"perlin_0","node_position":{"x":12,"y":243.5},"parameters":{"iterations":6,"persistence":0.7,"scale_x":20,"scale_y":3},"type":"perlin"}]}
{"connections":[{"from":"bricks_0","from_port":0,"to":"blend_0","to_port":0},{"from":"perlin_0","from_port":0,"to":"blend_0","to_port":1},{"from":"normal_map_0","from_port":0,"to":"Material","to_port":4},{"from":"perlin_1","from_port":0,"to":"colorize_2","to_port":0},{"from":"colorize_0","from_port":0,"to":"blend_1","to_port":1},{"from":"perlin_2","from_port":0,"to":"colorize_3","to_port":0},{"from":"colorize_3","from_port":0,"to":"blend_1","to_port":2},{"from":"blend_1","from_port":0,"to":"Material","to_port":0},{"from":"colorize_3","from_port":0,"to":"blend_2","to_port":0},{"from":"blend_2","from_port":0,"to":"Material","to_port":2},{"from":"blend_0","from_port":0,"to":"colorize_0","to_port":0},{"from":"blend_0","from_port":0,"to":"colorize_5","to_port":0},{"from":"colorize_5","from_port":0,"to":"normal_map_0","to_port":0},{"from":"uniform_1","from_port":0,"to":"Material","to_port":1},{"from":"uniform_0","from_port":0,"to":"blend_2","to_port":1},{"from":"perlin_1","from_port":0,"to":"colorize_1","to_port":0},{"from":"combine_0","from_port":0,"to":"export_0","to_port":0},{"from":"uniform_1","from_port":0,"to":"combine_0","to_port":0},{"from":"blend_2","from_port":0,"to":"combine_0","to_port":1},{"from":"colorize_2","from_port":0,"to":"blend_1","to_port":0}],"nodes":[{"name":"Material","node_position":{"x":938,"y":96},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"},{"name":"colorize_3","node_position":{"x":487.633789,"y":65},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0.518182,"r":0},{"a":1,"b":1,"g":1,"pos":0.709091,"r":1}],"type":"Gradient"}},"type":"colorize"},{"name":"bricks_0","node_position":{"x":-1,"y":30.5},"parameters":{"bevel":0.007813,"columns":5,"mortar":0.007813,"pattern":0,"repeat":1,"row_offset":0.5,"rows":1},"type":"bricks"},{"name":"colorize_0","node_position":{"x":472,"y":-41.5},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0.336914,"pos":0,"r":0.598958},{"a":1,"b":0,"g":0.454102,"pos":0.118182,"r":0.807292},{"a":1,"b":0,"g":0.37793,"pos":0.245455,"r":0.671875},{"a":1,"b":0,"g":0.427734,"pos":0.345455,"r":0.760417},{"a":1,"b":0.017795,"g":0.488254,"pos":0.527273,"r":0.854167},{"a":1,"b":0,"g":0.37793,"pos":0.645455,"r":0.671875},{"a":1,"b":0,"g":0.439453,"pos":0.845455,"r":0.78125},{"a":1,"b":0,"g":0.357422,"pos":1,"r":0.635417}],"type":"Gradient"}},"type":"colorize"},{"name":"perlin_1","node_position":{"x":110.633789,"y":-143.5},"parameters":{"iterations":7,"persistence":0.55,"scale_x":4,"scale_y":4},"type":"perlin"},{"name":"blend_2","node_position":{"x":690.633789,"y":201.5},"parameters":{"amount":0.4,"blend_type":0},"type":"blend"},{"name":"perlin_2","node_position":{"x":232.633789,"y":40},"parameters":{"iterations":6,"persistence":0.65,"scale_x":4,"scale_y":4},"type":"perlin"},{"name":"normal_map_0","node_position":{"x":724.633789,"y":345.5},"parameters":{"amount":0.15,"size":4},"type":"normal_map"},{"name":"blend_1","node_position":{"x":707.633789,"y":-68},"parameters":{"amount":0.5,"blend_type":0},"type":"blend"},{"name":"blend_0","node_position":{"x":271,"y":306.5},"parameters":{"amount":1,"blend_type":2},"type":"blend"},{"name":"colorize_5","node_position":{"x":503,"y":336.5},"parameters":{"gradient":{"points":[{"a":1,"b":1,"g":1,"pos":0,"r":1},{"a":1,"b":0,"g":0,"pos":1,"r":0}],"type":"Gradient"}},"type":"colorize"},{"name":"uniform_1","node_position":{"x":753,"y":116},"parameters":{"color":{"a":1,"b":0,"g":0,"r":0,"type":"Color"}},"type":"uniform"},{"name":"uniform_0","node_position":{"x":540,"y":234},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"}},"type":"uniform"},{"name":"colorize_2","node_position":{"x":454.633789,"y":-189.5},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0.515625},{"a":1,"b":0,"g":0,"pos":0.145455,"r":0.25},{"a":1,"b":0,"g":0,"pos":0.445455,"r":0.515625},{"a":1,"b":0.013184,"g":0.013184,"pos":0.745455,"r":0.28125},{"a":1,"b":0,"g":0,"pos":1,"r":0.322917}],"type":"Gradient"}},"type":"colorize"},{"name":"colorize_1","node_position":{"x":461.329102,"y":-116.699997},"parameters":{"gradient":{"points":[{"a":1,"b":0.034912,"g":0.129532,"pos":0,"r":0.203125},{"a":1,"b":0.038791,"g":0.074319,"pos":1,"r":0.114583}],"type":"Gradient"}},"type":"colorize"},{"name":"export_0","node_position":{"x":1090.329102,"y":-76.5},"parameters":{"resolution":1},"suffix":"mr","type":"export"},{"name":"combine_0","node_position":{"x":942.329102,"y":-55.5},"parameters":{},"type":"combine"},{"name":"perlin_0","node_position":{"x":12,"y":243.5},"parameters":{"iterations":6,"persistence":0.7,"scale_x":20,"scale_y":3},"type":"perlin"}]}

View File

@ -1 +1 @@
{"connections":[{"from":"bricks_0","from_port":0,"to":"colorize_0","to_port":0},{"from":"colorize_0","from_port":0,"to":"blend_0","to_port":0},{"from":"blend_0","from_port":0,"to":"Material","to_port":0},{"from":"blend_0","from_port":0,"to":"colorize_1","to_port":0},{"from":"colorize_1","from_port":0,"to":"normal_map_0","to_port":0},{"from":"normal_map_0","from_port":0,"to":"Material","to_port":4},{"from":"blend_0","from_port":0,"to":"Material","to_port":2},{"from":"uniform_0","from_port":0,"to":"Material","to_port":1},{"from":"uniform_0","from_port":0,"to":"combine_0","to_port":0},{"from":"blend_0","from_port":0,"to":"combine_0","to_port":1},{"from":"combine_0","from_port":0,"to":"export_0","to_port":0},{"from":"transform_1","from_port":0,"to":"blend_0","to_port":1},{"from":"perlin_0","from_port":0,"to":"transform_1","to_port":0},{"from":"bricks_0","from_port":1,"to":"decompose_0","to_port":0},{"from":"decompose_0","from_port":0,"to":"transform_1","to_port":1},{"from":"decompose_0","from_port":1,"to":"transform_1","to_port":2}],"nodes":[{"name":"colorize_0","node_position":{"x":524,"y":-100.75},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":0.213623,"g":0.391325,"pos":0.145455,"r":0.651042}],"type":"Gradient"}},"type":"colorize"},{"name":"normal_map_0","node_position":{"x":740,"y":135.25},"parameters":{"amount":0.5,"size":2},"type":"normal_map"},{"name":"colorize_1","node_position":{"x":710,"y":208.25},"parameters":{"gradient":{"points":[{"a":1,"b":1,"g":1,"pos":0,"r":1},{"a":1,"b":0,"g":0,"pos":1,"r":0}],"type":"Gradient"}},"type":"colorize"},{"name":"uniform_0","node_position":{"x":718,"y":73},"parameters":{"color":{"a":1,"b":0,"g":0,"r":0,"type":"Color"}},"type":"uniform"},{"name":"Material","node_position":{"x":930,"y":38},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"},{"name":"combine_0","node_position":{"x":866,"y":-78},"parameters":{},"type":"combine"},{"name":"export_0","node_position":{"x":1053,"y":-62},"parameters":{"resolution":1},"suffix":"mr","type":"export"},{"name":"perlin_0","node_position":{"x":69,"y":81.25},"parameters":{"iterations":7,"persistence":0.75,"scale_x":4,"scale_y":20},"type":"perlin"},{"name":"decompose_0","node_position":{"x":97,"y":236},"parameters":{},"type":"decompose"},{"name":"bricks_0","node_position":{"x":79,"y":-124.75},"parameters":{"bevel":0,"columns":1,"mortar":0.02,"pattern":0,"repeat":1,"row_offset":0.5,"rows":10},"type":"bricks"},{"name":"transform_1","node_position":{"x":290,"y":120},"parameters":{"repeat":true,"rotate":0,"scale_x":1,"scale_y":1,"translate_x":1,"translate_y":1},"type":"transform"},{"name":"blend_0","node_position":{"x":535,"y":2.25},"parameters":{"amount":0.5,"blend_type":0},"type":"blend"}]}
{"connections":[{"from":"bricks_0","from_port":0,"to":"colorize_0","to_port":0},{"from":"colorize_0","from_port":0,"to":"blend_0","to_port":0},{"from":"blend_0","from_port":0,"to":"Material","to_port":0},{"from":"blend_0","from_port":0,"to":"colorize_1","to_port":0},{"from":"colorize_1","from_port":0,"to":"normal_map_0","to_port":0},{"from":"normal_map_0","from_port":0,"to":"Material","to_port":4},{"from":"blend_0","from_port":0,"to":"Material","to_port":2},{"from":"uniform_0","from_port":0,"to":"Material","to_port":1},{"from":"uniform_0","from_port":0,"to":"combine_0","to_port":0},{"from":"blend_0","from_port":0,"to":"combine_0","to_port":1},{"from":"combine_0","from_port":0,"to":"export_0","to_port":0},{"from":"transform_1","from_port":0,"to":"blend_0","to_port":1},{"from":"perlin_0","from_port":0,"to":"transform_1","to_port":0},{"from":"bricks_0","from_port":1,"to":"decompose_0","to_port":0},{"from":"decompose_0","from_port":0,"to":"transform_1","to_port":1},{"from":"decompose_0","from_port":1,"to":"transform_1","to_port":2}],"nodes":[{"name":"colorize_0","node_position":{"x":524,"y":-100.75},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":0.213623,"g":0.391325,"pos":0.145455,"r":0.651042}],"type":"Gradient"}},"type":"colorize"},{"name":"normal_map_0","node_position":{"x":740,"y":135.25},"parameters":{"amount":0.3,"size":4},"type":"normal_map"},{"name":"colorize_1","node_position":{"x":710,"y":208.25},"parameters":{"gradient":{"points":[{"a":1,"b":1,"g":1,"pos":0,"r":1},{"a":1,"b":0,"g":0,"pos":1,"r":0}],"type":"Gradient"}},"type":"colorize"},{"name":"uniform_0","node_position":{"x":718,"y":73},"parameters":{"color":{"a":1,"b":0,"g":0,"r":0,"type":"Color"}},"type":"uniform"},{"name":"Material","node_position":{"x":930,"y":38},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"},{"name":"combine_0","node_position":{"x":866,"y":-78},"parameters":{},"type":"combine"},{"name":"export_0","node_position":{"x":1053,"y":-62},"parameters":{"resolution":1},"suffix":"mr","type":"export"},{"name":"perlin_0","node_position":{"x":69,"y":81.25},"parameters":{"iterations":6,"persistence":0.75,"scale_x":4,"scale_y":20},"type":"perlin"},{"name":"decompose_0","node_position":{"x":97,"y":236},"parameters":{},"type":"decompose"},{"name":"bricks_0","node_position":{"x":79,"y":-124.75},"parameters":{"bevel":0,"columns":1,"mortar":0.02,"pattern":0,"repeat":1,"row_offset":0.5,"rows":10},"type":"bricks"},{"name":"transform_1","node_position":{"x":290,"y":120},"parameters":{"repeat":true,"rotate":0,"scale_x":1,"scale_y":1,"translate_x":1,"translate_y":1},"type":"transform"},{"name":"blend_0","node_position":{"x":535,"y":2.25},"parameters":{"amount":0.5,"blend_type":0},"type":"blend"}]}

View File

@ -1 +1 @@
{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec3(1.0)","label":"","name":"in","type":"rgb"}],"instance":"vec3 $(name)_f(vec3 c) {\n\tvec3 hsv = rgb_to_hsv(c);\n\treturn hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0)));\n}","name":"AdjustHSV","outputs":[{"rgb":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]}
{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec3($uv.x, $uv.y, 0.0)","label":"","name":"in","type":"rgb"}],"instance":"vec3 $(name)_f(vec3 c) {\n\tvec3 hsv = rgb_to_hsv(c);\n\treturn hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0)));\n}","name":"AdjustHSV","outputs":[{"rgb":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]}

View File

@ -142,48 +142,72 @@ func update_node(data):
if custom_node_buttons != null:
move_child(custom_node_buttons, get_child_count()-1)
func replace_input(string, input, type, src, context = null):
var required_defs = ""
var required_code = ""
var keyword = "$%s(" % input
while true:
var position = string.find(keyword)
func find_keyword_call(string, keyword):
var search_string = "$%s(" % keyword
var position = string.find(search_string)
if position == -1:
break
return null
var parenthesis_level = 0
var parameter_begin = position+keyword.length()
var parameter_begin = position+search_string.length()
var parameter_end = -1
for i in range(parameter_begin, string.length()):
if string[i] == '(':
parenthesis_level += 1
elif string[i] == ')':
if parenthesis_level == 0:
parameter_end = i
break
else:
return string.substr(parameter_begin, i-parameter_begin)
parenthesis_level -= 1
if parameter_end != -1:
var uv = string.substr(parameter_begin, parameter_end-parameter_begin)
var src_code = src.get_shader_code(uv)
required_defs += src_code.defs
required_code += src_code.code
string = string.replace(string.substr(position, parameter_end-position+1), src_code[type])
else:
return ""
func replace_input(string, input, type, src, default):
var required_defs = ""
var required_code = ""
while true:
var uv = find_keyword_call(string, input)
if uv == null:
break
elif uv == "":
print("syntax error")
break
var src_code
if src == null:
src_code = subst(default, "(%s)" % uv)
else:
src_code = src.get_shader_code(uv)
src_code.string = src_code[type]
required_defs += src_code.defs
required_code += src_code.code
string = string.replace("$%s(%s)" % [ input, uv ], src_code.string)
return { string=string, defs=required_defs, code=required_code }
func is_word_letter(l):
return "azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890_".find(l) != -1
func replace_variable(string, variable, value):
string = string.replace("$(%s)" % variable, value)
return string
var keyword_size = variable.length()+1
var new_string = ""
while !string.empty():
var pos = string.find("$"+variable)
if pos == -1:
new_string += string
break
new_string += string.left(pos)
string = string.right(pos)
if string.empty() or !is_word_letter(string[0]):
new_string += value
else:
new_string += "$"+variable
string = string.right(keyword_size)
return new_string
func subst(string, uv = "", context = null):
func subst(string, uv = ""):
var required_defs = ""
var required_code = ""
string = replace_variable(string, "name", name)
string = replace_variable(string, "seed", str(get_seed()))
if uv != "":
string = replace_variable(string, "uv", uv)
string = replace_variable(string, "uv", "("+uv+")")
if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY:
for p in model_data.parameters:
if !p.has("name") or !p.has("type"):
@ -204,10 +228,7 @@ func subst(string, uv = "", context = null):
for i in range(model_data.inputs.size()):
var input = model_data.inputs[i]
var source = get_source(i)
if source == null:
string = replace_variable(string, input.name, input.default)
else:
var result = replace_input(string, input.name, input.type, source, context)
var result = replace_input(string, input.name, input.type, source, input.default)
string = result.string
required_defs += result.defs
required_code += result.code
@ -227,7 +248,7 @@ func _get_shader_code(uv, slot = 0):
generated_variants.append(variant_string)
for t in output_info:
if output.has(t.field):
var subst_output = subst(output[t.field], uv, rv)
var subst_output = subst(output[t.field], uv)
rv.defs += subst_output.defs
rv.code += subst_output.code
rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, name, slot, variant_index, t.field, subst_output.string ]

View File

@ -143,7 +143,7 @@ hint_tooltip = "Default value"
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 1
size_flags_horizontal = 1
size_flags_horizontal = 3
size_flags_vertical = 1
text = "0.0"
focus_mode = 2
@ -152,7 +152,7 @@ placeholder_alpha = 0.6
caret_blink = false
caret_blink_speed = 0.65
caret_position = 0
_sections_unfolded = [ "Hint", "Rect" ]
_sections_unfolded = [ "Hint", "Rect", "Size Flags" ]
[connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"]