Fixed switch node (so it supports all port types) + minor bug fixes

This commit is contained in:
Rodolphe Suescun 2019-12-25 10:36:45 +01:00
parent 509853e743
commit 1799ade2f2
7 changed files with 22 additions and 10 deletions

View File

@ -44,7 +44,8 @@ const PORT_TYPES : Dictionary = {
rgb = { type="vec3", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 1.0) },
rgba = { type="vec4", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.0, 0.5, 0.0, 0.5) },
sdf2d = { type="float", paramdefs="vec2 uv", params="uv", slot_type=1, color=Color(1.0, 0.5, 0.0) },
sdf3d = { type="float", paramdefs="vec3 p", params="p", slot_type=2, color=Color(1.0, 0.0, 0.0) }
sdf3d = { type="float", paramdefs="vec3 p", params="p", slot_type=2, color=Color(1.0, 0.0, 0.0) },
any = { slot_type=42, color=Color(1.0, 1.0, 1.0) }
}
func _ready() -> void:

View File

@ -34,14 +34,14 @@ func get_input_defs() -> Array:
for c in range(parameters.choices):
for o in range(parameters.outputs):
var n = PoolByteArray([65+o]).get_string_from_ascii()+str(c)
rv.push_back({ name=n, label=n, type="rgba" })
rv.push_back({ name=n, label=n, type="any" })
return rv
func get_output_defs() -> Array:
var rv : Array = []
for o in range(parameters.outputs):
var n = PoolByteArray([65+o]).get_string_from_ascii()
rv.push_back({ name=n, type="rgba" })
rv.push_back({ name=n, type="any" })
return rv
func set_parameter(p, v) -> void:

View File

@ -117,6 +117,7 @@ static func generate_combined_shader(red_code, green_code, blue_code) -> String:
code += "\n"
var globals = []
var textures = {}
var output = []
for c in [ red_code, green_code, blue_code ]:
if c.has("textures"):
for t in c.textures.keys():
@ -125,6 +126,10 @@ static func generate_combined_shader(red_code, green_code, blue_code) -> String:
for g in c.globals:
if globals.find(g) == -1:
globals.push_back(g)
if c.has("f"):
output.push_back(c.f)
else:
output.push_back("1.0")
for t in textures.keys():
code += "uniform sampler2D "+t+";\n"
for g in globals:
@ -137,7 +142,7 @@ static func generate_combined_shader(red_code, green_code, blue_code) -> String:
shader_code += red_code.code
shader_code += green_code.code
shader_code += blue_code.code
shader_code += "COLOR = vec4("+red_code.f+", "+green_code.f+", "+blue_code.f+", 1.0);\n"
shader_code += "COLOR = vec4("+output[0]+", "+output[1]+", "+output[2]+", 1.0);\n"
shader_code += "}\n"
#print("GENERATED COMBINED SHADER:\n"+shader_code)
code += shader_code

View File

@ -22,6 +22,9 @@ signal graph_changed
func _ready() -> void:
OS.low_processor_usage_mode = true
center_view()
for t in range(5):
add_valid_connection_type(t, 42)
add_valid_connection_type(42, t)
func _gui_input(event) -> void:
if event is InputEventKey and event.pressed:

View File

@ -64,8 +64,10 @@ func get_preview_texture(data : Dictionary) -> ImageTexture:
image_path = ProjectSettings.globalize_path(image_path)
t = ImageTexture.new()
var image : Image = Image.new()
image.load(image_path)
if image.load(image_path) == OK:
t.create_from_image(image)
else:
print("Cannot load image "+image_path)
return t
return null

View File

@ -134,7 +134,7 @@ func create_parameter_control(p : Dictionary) -> Control:
return control
func save_preview_widget() -> void:
if preview != null:
if preview != null and preview.get_parent() == self:
remove_child(preview)
if preview_timer != null:
preview_timer.stop()

View File

@ -69,7 +69,9 @@ func update_node() -> void:
var space = Control.new()
space.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
sizer.add_child(space)
sizer.add_child(preload("res://addons/material_maker/widgets/preview_button.tscn").instance())
var button = preload("res://addons/material_maker/widgets/preview_button.tscn").instance()
sizer.add_child(button)
button.connect("toggled", self, "on_preview_button", [ get_child_count()-1 ])
add_child(sizer)
rect_size = Vector2(0, 0)
for i in range(get_child_count()):
@ -79,13 +81,12 @@ func update_node() -> void:
if i < 5:
has_output = i < output_count
sizer.get_child(sizer.get_child_count()-1).visible = has_output
sizer.get_child(sizer.get_child_count()-1).connect("toggled", self, "on_preview_button", [ i ])
if i >= input_count:
sizer.get_child(0).text = ""
has_input = false
else:
sizer.get_child(0).text = PoolByteArray([65+i%int(output_count)]).get_string_from_ascii()+str(1+i/int(output_count))
sizer.get_child(0).add_color_override("font_color", Color(1.0, 1.0, 1.0) if i/int(output_count) == generator.parameters.source else Color(0.5, 0.5, 0.5))
set_slot(i, has_input, 0, Color(0.0, 0.5, 0.0, 0.5), has_output, 0, Color(0.0, 0.5, 0.0, 0.5))
set_slot(i, has_input, 42, Color(1.0, 1.0, 1.0, 1.0), has_output, 42, Color(1.0, 1.0, 1.0, 1.0))
# Preview
restore_preview_widget()