mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Fixed default shader data used when shader generation fails
This commit is contained in:
parent
dc59af0c4e
commit
14683e25af
@ -8,6 +8,8 @@ Base class for texture generators, that defines their API
|
||||
|
||||
signal parameter_changed(n, v)
|
||||
|
||||
const DEFAULT_GENERATED_SHADER : Dictionary = { defs="", code="", textures={}, type="f", f="0.0" }
|
||||
|
||||
class InputPort:
|
||||
var generator : MMGenBase = null
|
||||
var input_index : int = 0
|
||||
@ -232,7 +234,7 @@ func render(output_index : int, size : int, preview : bool = false) -> Object:
|
||||
while source is GDScriptFunctionState:
|
||||
source = yield(source, "completed")
|
||||
if source.empty():
|
||||
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
|
||||
source = DEFAULT_GENERATED_SHADER
|
||||
var shader : String
|
||||
if preview:
|
||||
var output_type = "rgba"
|
||||
|
@ -48,7 +48,7 @@ func update_shader() -> void:
|
||||
while source is GDScriptFunctionState:
|
||||
source = yield(source, "completed")
|
||||
if source.empty():
|
||||
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
|
||||
source = DEFAULT_GENERATED_SHADER
|
||||
material.shader.code = mm_renderer.generate_shader(source)
|
||||
if source.has("textures"):
|
||||
for k in source.textures.keys():
|
||||
|
@ -62,9 +62,10 @@ func get_parameter_defs() -> Array:
|
||||
return get_node("gen_parameters").get_parameter_defs()
|
||||
return []
|
||||
|
||||
func set_parameter(p, v) -> void:
|
||||
func set_parameter(n : String, v) -> void:
|
||||
.set_parameter(n, v)
|
||||
if has_node("gen_parameters"):
|
||||
get_node("gen_parameters").set_parameter(p, v)
|
||||
get_node("gen_parameters").set_parameter(n, v)
|
||||
|
||||
func get_input_defs() -> Array:
|
||||
if has_node("gen_inputs"):
|
||||
|
@ -95,7 +95,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
|
||||
while rv is GDScriptFunctionState:
|
||||
rv = yield(rv, "completed")
|
||||
return rv
|
||||
return { defs="", code="", textures={} }
|
||||
return DEFAULT_GENERATED_SHADER
|
||||
|
||||
func _serialize(data: Dictionary) -> Dictionary:
|
||||
data.type = "ios"
|
||||
|
@ -98,7 +98,7 @@ func render_textures() -> void:
|
||||
while source is GDScriptFunctionState:
|
||||
source = yield(source, "completed")
|
||||
if source.empty():
|
||||
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
|
||||
source = DEFAULT_GENERATED_SHADER
|
||||
shader_materials[t.texture].shader.code = mm_renderer.generate_shader(source)
|
||||
if source.has("textures"):
|
||||
for k in source.textures.keys():
|
||||
|
@ -8,7 +8,7 @@ var output : int = 0
|
||||
func set_generator(g : MMGenBase, o : int = 0) -> void:
|
||||
if is_instance_valid(generator):
|
||||
generator.disconnect("parameter_changed", self, "on_parameter_changed")
|
||||
var source = { defs="", code="", textures={}, type="f", f="1.0" }
|
||||
var source = MMGenBase.DEFAULT_GENERATED_SHADER
|
||||
if is_instance_valid(g):
|
||||
generator = g
|
||||
output = o
|
||||
@ -23,7 +23,7 @@ func set_generator(g : MMGenBase, o : int = 0) -> void:
|
||||
while source is GDScriptFunctionState:
|
||||
source = yield(source, "completed")
|
||||
if source.empty():
|
||||
source = { defs="", code="", textures={}, type="f", f="1.0" }
|
||||
source = MMGenBase.DEFAULT_GENERATED_SHADER
|
||||
else:
|
||||
g = null
|
||||
for c in get_children():
|
||||
|
@ -15,7 +15,7 @@ func get_histogram_texture() -> ImageTexture:
|
||||
func set_generator(g : MMGenBase, o : int = 0) -> void:
|
||||
if is_instance_valid(generator):
|
||||
generator.disconnect("parameter_changed", self, "on_parameter_changed")
|
||||
var source = { defs="", code="", textures={}, type="f", f="1.0" }
|
||||
var source = MMGenBase.DEFAULT_GENERATED_SHADER
|
||||
if is_instance_valid(g):
|
||||
generator = g
|
||||
output = o
|
||||
@ -28,7 +28,7 @@ func set_generator(g : MMGenBase, o : int = 0) -> void:
|
||||
while source is GDScriptFunctionState:
|
||||
source = yield(source, "completed")
|
||||
if source.empty():
|
||||
source = { defs="", code="", textures={}, type="f", f="1.0" }
|
||||
source = MMGenBase.DEFAULT_GENERATED_SHADER
|
||||
# Update shader
|
||||
$ViewportImage/ColorRect.material.shader.code = MMGenBase.generate_preview_shader(source, source.type, "uniform vec2 size;void fragment() {COLOR = preview_2d(UV);}")
|
||||
# Get parameter values from the shader code
|
||||
|
Loading…
Reference in New Issue
Block a user