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)
|
signal parameter_changed(n, v)
|
||||||
|
|
||||||
|
const DEFAULT_GENERATED_SHADER : Dictionary = { defs="", code="", textures={}, type="f", f="0.0" }
|
||||||
|
|
||||||
class InputPort:
|
class InputPort:
|
||||||
var generator : MMGenBase = null
|
var generator : MMGenBase = null
|
||||||
var input_index : int = 0
|
var input_index : int = 0
|
||||||
@ -232,7 +234,7 @@ func render(output_index : int, size : int, preview : bool = false) -> Object:
|
|||||||
while source is GDScriptFunctionState:
|
while source is GDScriptFunctionState:
|
||||||
source = yield(source, "completed")
|
source = yield(source, "completed")
|
||||||
if source.empty():
|
if source.empty():
|
||||||
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
|
source = DEFAULT_GENERATED_SHADER
|
||||||
var shader : String
|
var shader : String
|
||||||
if preview:
|
if preview:
|
||||||
var output_type = "rgba"
|
var output_type = "rgba"
|
||||||
|
@ -48,7 +48,7 @@ func update_shader() -> void:
|
|||||||
while source is GDScriptFunctionState:
|
while source is GDScriptFunctionState:
|
||||||
source = yield(source, "completed")
|
source = yield(source, "completed")
|
||||||
if source.empty():
|
if source.empty():
|
||||||
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
|
source = DEFAULT_GENERATED_SHADER
|
||||||
material.shader.code = mm_renderer.generate_shader(source)
|
material.shader.code = mm_renderer.generate_shader(source)
|
||||||
if source.has("textures"):
|
if source.has("textures"):
|
||||||
for k in source.textures.keys():
|
for k in source.textures.keys():
|
||||||
|
@ -62,9 +62,10 @@ func get_parameter_defs() -> Array:
|
|||||||
return get_node("gen_parameters").get_parameter_defs()
|
return get_node("gen_parameters").get_parameter_defs()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
func set_parameter(p, v) -> void:
|
func set_parameter(n : String, v) -> void:
|
||||||
|
.set_parameter(n, v)
|
||||||
if has_node("gen_parameters"):
|
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:
|
func get_input_defs() -> Array:
|
||||||
if has_node("gen_inputs"):
|
if has_node("gen_inputs"):
|
||||||
|
@ -95,7 +95,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
|
|||||||
while rv is GDScriptFunctionState:
|
while rv is GDScriptFunctionState:
|
||||||
rv = yield(rv, "completed")
|
rv = yield(rv, "completed")
|
||||||
return rv
|
return rv
|
||||||
return { defs="", code="", textures={} }
|
return DEFAULT_GENERATED_SHADER
|
||||||
|
|
||||||
func _serialize(data: Dictionary) -> Dictionary:
|
func _serialize(data: Dictionary) -> Dictionary:
|
||||||
data.type = "ios"
|
data.type = "ios"
|
||||||
|
@ -98,7 +98,7 @@ func render_textures() -> void:
|
|||||||
while source is GDScriptFunctionState:
|
while source is GDScriptFunctionState:
|
||||||
source = yield(source, "completed")
|
source = yield(source, "completed")
|
||||||
if source.empty():
|
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)
|
shader_materials[t.texture].shader.code = mm_renderer.generate_shader(source)
|
||||||
if source.has("textures"):
|
if source.has("textures"):
|
||||||
for k in source.textures.keys():
|
for k in source.textures.keys():
|
||||||
|
@ -8,7 +8,7 @@ var output : int = 0
|
|||||||
func set_generator(g : MMGenBase, o : int = 0) -> void:
|
func set_generator(g : MMGenBase, o : int = 0) -> void:
|
||||||
if is_instance_valid(generator):
|
if is_instance_valid(generator):
|
||||||
generator.disconnect("parameter_changed", self, "on_parameter_changed")
|
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):
|
if is_instance_valid(g):
|
||||||
generator = g
|
generator = g
|
||||||
output = o
|
output = o
|
||||||
@ -23,7 +23,7 @@ func set_generator(g : MMGenBase, o : int = 0) -> void:
|
|||||||
while source is GDScriptFunctionState:
|
while source is GDScriptFunctionState:
|
||||||
source = yield(source, "completed")
|
source = yield(source, "completed")
|
||||||
if source.empty():
|
if source.empty():
|
||||||
source = { defs="", code="", textures={}, type="f", f="1.0" }
|
source = MMGenBase.DEFAULT_GENERATED_SHADER
|
||||||
else:
|
else:
|
||||||
g = null
|
g = null
|
||||||
for c in get_children():
|
for c in get_children():
|
||||||
|
@ -15,7 +15,7 @@ func get_histogram_texture() -> ImageTexture:
|
|||||||
func set_generator(g : MMGenBase, o : int = 0) -> void:
|
func set_generator(g : MMGenBase, o : int = 0) -> void:
|
||||||
if is_instance_valid(generator):
|
if is_instance_valid(generator):
|
||||||
generator.disconnect("parameter_changed", self, "on_parameter_changed")
|
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):
|
if is_instance_valid(g):
|
||||||
generator = g
|
generator = g
|
||||||
output = o
|
output = o
|
||||||
@ -28,7 +28,7 @@ func set_generator(g : MMGenBase, o : int = 0) -> void:
|
|||||||
while source is GDScriptFunctionState:
|
while source is GDScriptFunctionState:
|
||||||
source = yield(source, "completed")
|
source = yield(source, "completed")
|
||||||
if source.empty():
|
if source.empty():
|
||||||
source = { defs="", code="", textures={}, type="f", f="1.0" }
|
source = MMGenBase.DEFAULT_GENERATED_SHADER
|
||||||
# Update shader
|
# Update shader
|
||||||
$ViewportImage/ColorRect.material.shader.code = MMGenBase.generate_preview_shader(source, source.type, "uniform vec2 size;void fragment() {COLOR = preview_2d(UV);}")
|
$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
|
# Get parameter values from the shader code
|
||||||
|
Loading…
Reference in New Issue
Block a user