mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Implemented lazy buffers update and started refactoring material node.
This commit is contained in:
parent
d643cecebb
commit
f2807f4eff
@ -6,6 +6,17 @@ class_name MMGenBase
|
||||
Base class for texture generators, that defines their API
|
||||
"""
|
||||
|
||||
class InputPort:
|
||||
var generator : MMGenBase = null
|
||||
var input_index : int = 0
|
||||
|
||||
func _init(g : MMGenBase, i : int):
|
||||
generator = g
|
||||
input_index = i
|
||||
|
||||
func to_str():
|
||||
return generator.name+".in("+str(input_index)+")"
|
||||
|
||||
class OutputPort:
|
||||
var generator : MMGenBase = null
|
||||
var output_index : int = 0
|
||||
@ -15,7 +26,7 @@ class OutputPort:
|
||||
output_index = o
|
||||
|
||||
func to_str():
|
||||
return generator.name+"("+str(output_index)+")"
|
||||
return generator.name+".out("+str(output_index)+")"
|
||||
|
||||
var position : Vector2 = Vector2(0, 0)
|
||||
var model = null
|
||||
@ -46,6 +57,13 @@ func get_parameter_defs():
|
||||
|
||||
func set_parameter(n : String, v):
|
||||
parameters[n] = v
|
||||
source_changed(0)
|
||||
|
||||
func source_changed(input_index : int):
|
||||
for i in range(get_output_defs().size()):
|
||||
var target = get_target(i)
|
||||
if target != null:
|
||||
target.generator.source_changed(target.input_index)
|
||||
|
||||
func get_input_defs():
|
||||
return []
|
||||
@ -55,6 +73,9 @@ func get_output_defs():
|
||||
|
||||
func get_source(input_index : int):
|
||||
return get_parent().get_port_source(name, input_index)
|
||||
|
||||
func get_target(output_index : int):
|
||||
return get_parent().get_port_target(name, output_index)
|
||||
|
||||
func get_input_shader(input_index : int):
|
||||
var source = get_source(input_index)
|
||||
|
@ -7,6 +7,8 @@ Texture generator buffers, that render their input in a specific resolution and
|
||||
This is useful when using generators that sample their inputs several times (such as convolutions)
|
||||
"""
|
||||
|
||||
var updated : bool = false
|
||||
|
||||
func _ready():
|
||||
if !parameters.has("size"):
|
||||
parameters.size = 4
|
||||
@ -26,9 +28,12 @@ func get_input_defs():
|
||||
func get_output_defs():
|
||||
return [ { type="rgba" } ]
|
||||
|
||||
func source_changed(input_port_index):
|
||||
updated = false
|
||||
|
||||
func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
var source = get_source(0)
|
||||
if source != null:
|
||||
if source != null and !updated:
|
||||
var status = source.generator.render(source.output_index, context.renderer, pow(2, 4+parameters.size))
|
||||
while status is GDScriptFunctionState:
|
||||
status = yield(status, "completed")
|
||||
@ -36,6 +41,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
var image : Image = context.renderer.get_texture().get_data()
|
||||
texture.create_from_image(image)
|
||||
texture.flags = 0
|
||||
updated = true
|
||||
var rv = ._get_shader_code(uv, output_index, context)
|
||||
while rv is GDScriptFunctionState:
|
||||
rv = yield(rv, "completed")
|
||||
|
@ -12,7 +12,15 @@ func get_port_source(gen_name: String, input_index: int) -> OutputPort:
|
||||
if c.to == gen_name and c.to_port == input_index:
|
||||
var src_gen = get_node(c.from)
|
||||
if src_gen != null:
|
||||
return OutputPort.new(get_node(c.from), c.from_port)
|
||||
return OutputPort.new(src_gen, c.from_port)
|
||||
return null
|
||||
|
||||
func get_port_target(gen_name: String, input_index: int) -> InputPort:
|
||||
for c in connections:
|
||||
if c.from == gen_name and c.from_port == input_index:
|
||||
var tgt_gen = get_node(c.to)
|
||||
if tgt_gen != null:
|
||||
return InputPort.new(tgt_gen, c.to_port)
|
||||
return null
|
||||
|
||||
func remove_generator(generator : MMGenBase):
|
||||
|
@ -28,6 +28,22 @@ const ADDON_TEXTURE_LIST = [
|
||||
func get_type():
|
||||
return "material"
|
||||
|
||||
func get_parameter_defs():
|
||||
return [
|
||||
{ name="albedo_color", label="Albedo", type="color", default={ r=1.0, g=1.0, b=1.0, a=1.0} },
|
||||
{ name="metallic", label="Metallic", type="float", min=0.0, max=1.0, default=1.0 },
|
||||
{ name="roughness", label="Roughness", type="float", min=0.0, max=1.0, default=1.0 },
|
||||
{ name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, default=1.0 }
|
||||
]
|
||||
|
||||
func get_input_defs():
|
||||
return [
|
||||
{ name="albedo_texture", label="", type="rgb" },
|
||||
{ name="metallic_texture", label="", type="f" },
|
||||
{ name="roughness_texture", label="", type="f" },
|
||||
{ name="emission_texture", label="", type="rgb" }
|
||||
]
|
||||
|
||||
func _ready():
|
||||
texture_list = TEXTURE_LIST
|
||||
if Engine.editor_hint:
|
||||
@ -35,6 +51,7 @@ func _ready():
|
||||
for t in texture_list:
|
||||
generated_textures[t.texture] = null
|
||||
material = SpatialMaterial.new()
|
||||
model = material
|
||||
|
||||
func generate_material(renderer : MMGenRenderer):
|
||||
var source = get_source(0)
|
||||
@ -74,10 +91,10 @@ func get_generated_texture(slot, file_prefix = null):
|
||||
|
||||
func update_spatial_material(m, file_prefix = null):
|
||||
var texture
|
||||
m.albedo_color = Color(1, 1, 1)#parameters.albedo_color
|
||||
m.albedo_color = parameters.albedo_color
|
||||
m.albedo_texture = get_generated_texture("albedo", file_prefix)
|
||||
m.metallic = 1#parameters.metallic
|
||||
m.roughness = 1#parameters.roughness
|
||||
m.metallic = parameters.metallic
|
||||
m.roughness = parameters.roughness
|
||||
if Engine.editor_hint:
|
||||
texture = get_generated_texture("mrao", file_prefix)
|
||||
m.metallic_texture = texture
|
||||
@ -90,7 +107,7 @@ func update_spatial_material(m, file_prefix = null):
|
||||
texture = get_generated_texture("emission", file_prefix)
|
||||
if texture != null:
|
||||
m.emission_enabled = true
|
||||
#m.emission_energy = parameters.emission_energy
|
||||
m.emission_energy = parameters.emission_energy
|
||||
m.emission_texture = texture
|
||||
else:
|
||||
m.emission_enabled = false
|
||||
|
@ -64,7 +64,6 @@ func remove_node(node):
|
||||
# Global operations on graph
|
||||
|
||||
func update_tab_title():
|
||||
print("update_tab_title")
|
||||
if !get_parent().has_method("set_tab_title"):
|
||||
print("no set_tab_title method")
|
||||
return
|
||||
|
@ -56,19 +56,19 @@ func update_shaders():
|
||||
get_parent().send_changed_signal()
|
||||
|
||||
func _on_text_changed(new_text, variable):
|
||||
generator.parameters[variable] = float(new_text)
|
||||
generator.set_parameter(variable, float(new_text))
|
||||
update_shaders()
|
||||
|
||||
func _on_value_changed(new_value, variable):
|
||||
generator.parameters[variable] = new_value
|
||||
generator.set_parameter(variable, new_value)
|
||||
update_shaders()
|
||||
|
||||
func _on_color_changed(new_color, variable):
|
||||
generator.parameters[variable] = new_color
|
||||
generator.set_parameter(variable, new_color)
|
||||
update_shaders()
|
||||
|
||||
func _on_gradient_changed(new_gradient, variable):
|
||||
generator.parameters[variable] = new_gradient
|
||||
generator.set_parameter(variable, new_gradient)
|
||||
update_shaders()
|
||||
|
||||
func update_node():
|
||||
|
Loading…
Reference in New Issue
Block a user