mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Added group creation and refactoring.
Moved handling of the "global" definitions of shaders into main shader generation code. Added group creation (does not create inputs yet, and remotes should be cleaned). updated all preview meshes (to fix problems with depth).
This commit is contained in:
parent
c4a0bbc0a8
commit
ff191538f6
@ -91,18 +91,6 @@ func get_input_shader(input_index : int):
|
||||
func get_shader(output_index : int, context):
|
||||
return get_shader_code("UV", output_index, context);
|
||||
|
||||
# this will need an output index for switch
|
||||
func get_globals():
|
||||
var list = []
|
||||
for i in range(10):
|
||||
var source = get_source(i)
|
||||
if source != null:
|
||||
var source_list = source.generator.get_globals()
|
||||
for g in source_list:
|
||||
if list.find(g) == -1:
|
||||
list.append(g)
|
||||
return list
|
||||
|
||||
func render(output_index : int, renderer : MMGenRenderer, size : int):
|
||||
var context : MMGenContext = MMGenContext.new(renderer)
|
||||
var source = get_shader_code("UV", output_index, context)
|
||||
@ -135,7 +123,6 @@ func get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
rv.rgb = "vec3("+rv.f+")"
|
||||
if !rv.has("rgba"):
|
||||
rv.rgba = "vec4("+rv.rgb+", 1.0)"
|
||||
rv.globals = get_globals()
|
||||
return rv
|
||||
|
||||
func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
|
@ -28,7 +28,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
var genname = "o"+str(get_instance_id())
|
||||
var epsilon = 1.0/pow(2, 4+parameters.size)
|
||||
var types = { "rgba": { type="vec4", init="vec4(0.0)" }, "rgb": { type="vec3", init="vec3(0.0)" }, "f": { type="float", init="0.0" } }
|
||||
var rv = { defs="", code="", textures={} }
|
||||
var rv = { globals=[], defs="", code="", textures={} }
|
||||
var source = get_source(0)
|
||||
if source == null:
|
||||
return rv
|
||||
|
@ -12,44 +12,39 @@ func get_type_name():
|
||||
return label
|
||||
|
||||
func get_parameter_defs():
|
||||
var params = get_node("gen_parameters")
|
||||
if params != null:
|
||||
return params.get_parameter_defs()
|
||||
if has_node("gen_parameters"):
|
||||
return get_node("gen_parameters").get_parameter_defs()
|
||||
return []
|
||||
|
||||
func set_parameter(p, v):
|
||||
var params = get_node("gen_parameters")
|
||||
if params != null:
|
||||
return params.set_parameter(p, v)
|
||||
if has_node("gen_parameters"):
|
||||
return get_node("gen_parameters").set_parameter(p, v)
|
||||
|
||||
func get_input_defs():
|
||||
var inputs = get_node("gen_inputs")
|
||||
if inputs != null:
|
||||
return inputs.get_input_defs()
|
||||
if has_node("gen_inputs"):
|
||||
return get_node("gen_inputs").get_input_defs()
|
||||
return []
|
||||
|
||||
func get_output_defs():
|
||||
var outputs = get_node("gen_outputs")
|
||||
if outputs != null:
|
||||
return outputs.get_output_defs()
|
||||
if has_node("gen_outputs"):
|
||||
return get_node("gen_outputs").get_output_defs()
|
||||
return []
|
||||
|
||||
func source_changed(input_index : int):
|
||||
var generator = get_node("gen_inputs")
|
||||
if generator != null:
|
||||
generator.source_changed(input_index)
|
||||
if has_node("gen_inputs"):
|
||||
return get_node("gen_inputs").source_changed(input_index)
|
||||
|
||||
func get_port_source(gen_name: String, input_index: int) -> OutputPort:
|
||||
if gen_name == "gen_inputs":
|
||||
var parent = get_parent()
|
||||
if parent != null and parent.get_type() == "graph":
|
||||
if parent != null and parent.get_script() == get_script():
|
||||
return parent.get_port_source(name, input_index)
|
||||
else:
|
||||
for c in connections:
|
||||
if c.to == gen_name and c.to_port == input_index:
|
||||
var src_gen = get_node(c.from)
|
||||
if src_gen != null:
|
||||
if src_gen.get_type() == "graph":
|
||||
if src_gen.get_script() == get_script():
|
||||
return src_gen.get_port_source("gen_outputs", c.from_port)
|
||||
return OutputPort.new(src_gen, c.from_port)
|
||||
return null
|
||||
@ -63,6 +58,15 @@ func get_port_targets(gen_name: String, output_index: int) -> InputPort:
|
||||
rv.push_back(InputPort.new(tgt_gen, c.to_port))
|
||||
return rv
|
||||
|
||||
func add_generator(generator : MMGenBase):
|
||||
var name = generator.name
|
||||
var index = 1
|
||||
while has_node(name):
|
||||
index += 1
|
||||
name = generator.name + "_" + str(index)
|
||||
generator.name = name
|
||||
add_child(generator)
|
||||
|
||||
func remove_generator(generator : MMGenBase):
|
||||
var new_connections = []
|
||||
for c in connections:
|
||||
@ -112,7 +116,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 { globals=[], defs="", code="", textures={} }
|
||||
|
||||
func _serialize(data):
|
||||
data.label = label
|
||||
@ -124,3 +128,39 @@ func _serialize(data):
|
||||
|
||||
func edit(node):
|
||||
node.get_parent().call_deferred("update_view", self)
|
||||
|
||||
func create_subgraph(generators):
|
||||
var new_graph = get_script().new()
|
||||
new_graph.name = "graph"
|
||||
add_child(new_graph)
|
||||
var names : Array = []
|
||||
for g in generators:
|
||||
names.push_back(g.name)
|
||||
remove_child(g)
|
||||
new_graph.add_generator(g)
|
||||
var new_graph_connections = []
|
||||
var my_new_connections = []
|
||||
var inputs = null
|
||||
var outputs = null
|
||||
for c in connections:
|
||||
if names.find(c.from) != -1 and names.find(c.to) != -1:
|
||||
new_graph_connections.push_back(c)
|
||||
elif names.find(c.from) != -1:
|
||||
if outputs == null:
|
||||
outputs = MMGenIOs.new()
|
||||
outputs.name = "gen_outputs"
|
||||
new_graph.add_generator(outputs)
|
||||
var port_index = outputs.ports.size()
|
||||
outputs.ports.push_back( { name="port"+str(port_index), type="rgba" } )
|
||||
my_new_connections.push_back( { from=new_graph.name, from_port=port_index, to=c.to, to_port=c.to_port } )
|
||||
new_graph_connections.push_back( { from=c.from, from_port=c.from_port, to="gen_outputs", to_port=port_index } )
|
||||
elif names.find(c.to) != -1:
|
||||
print("3: "+str(c))
|
||||
else:
|
||||
my_new_connections.push_back(c)
|
||||
connections = my_new_connections
|
||||
new_graph.connections = new_graph_connections
|
||||
for g in generators:
|
||||
if g is MMGenRemote:
|
||||
g.name = "gen_parameters"
|
||||
break
|
||||
|
@ -17,9 +17,9 @@ func get_type():
|
||||
return "buffer"
|
||||
|
||||
func get_type_name():
|
||||
match mask:
|
||||
1: return "Inputs"
|
||||
2: return "Output"
|
||||
match name:
|
||||
"gen_inputs": return "Inputs"
|
||||
"gen_outputs": return "Outputs"
|
||||
_: return "IOs"
|
||||
return "Buffer"
|
||||
|
||||
|
@ -146,7 +146,7 @@ func update_spatial_material(m, file_prefix = null):
|
||||
if texture != null:
|
||||
m.depth_enabled = true
|
||||
m.depth_deep_parallax = true
|
||||
m.depth_scale = parameters.depth_scale
|
||||
m.depth_scale = parameters.depth_scale * 0.2
|
||||
m.depth_texture = texture
|
||||
else:
|
||||
m.depth_enabled = false
|
||||
@ -155,7 +155,7 @@ func export_textures(prefix, size = null):
|
||||
if size == null:
|
||||
size = int(pow(2, 8+parameters.resolution))
|
||||
for t in texture_list:
|
||||
var texture = generated_textures[t.texture].texture
|
||||
var texture = generated_textures[t.texture]
|
||||
if texture != null:
|
||||
var image = texture.get_data()
|
||||
image.save_png("%s_%s.png" % [ prefix, t.texture ])
|
||||
|
@ -14,14 +14,14 @@ func set_widgets(w):
|
||||
for w in widgets:
|
||||
var param_name = "param"+str(i)
|
||||
if !parameters.has(param_name):
|
||||
parameters["param"+str(i)] = 0
|
||||
parameters[param_name] = 0
|
||||
i += 1
|
||||
|
||||
func get_type():
|
||||
return "remote"
|
||||
|
||||
func get_type_name():
|
||||
return "Remote"
|
||||
return "Parameters" if name == "gen_parameters" else "Remote"
|
||||
|
||||
func get_parameter_defs():
|
||||
var rv = []
|
||||
@ -68,8 +68,6 @@ func set_parameter(p, v):
|
||||
for w in widget.configurations[configurations[v]]:
|
||||
var node = parent.get_node(w.node)
|
||||
if node != null:
|
||||
print(w.value)
|
||||
print(MMType.deserialize_value(w.value))
|
||||
node.set_parameter(w.widget, MMType.deserialize_value(w.value))
|
||||
else:
|
||||
# incorrect configuration index
|
||||
@ -133,9 +131,7 @@ func update_configuration(index, config_name):
|
||||
for w in widget.linked_widgets:
|
||||
var g = parent.get_node(w.node)
|
||||
if g != null:
|
||||
print(g.parameters[w.widget])
|
||||
var value = MMType.serialize_value(g.parameters[w.widget])
|
||||
print(value)
|
||||
c.push_back({ node=w.node, widget=w.widget, value=value })
|
||||
widget.configurations[config_name] = c
|
||||
emit_signal("parameter_changed", "", null)
|
||||
|
@ -61,6 +61,7 @@ func find_keyword_call(string, keyword):
|
||||
return ""
|
||||
|
||||
func replace_input(string, context, input, type, src, default):
|
||||
var required_globals = []
|
||||
var required_defs = ""
|
||||
var required_code = ""
|
||||
var required_textures = {}
|
||||
@ -83,11 +84,17 @@ func replace_input(string, context, input, type, src, default):
|
||||
while src_code is GDScriptFunctionState:
|
||||
src_code = yield(src_code, "completed")
|
||||
src_code.string = src_code[type]
|
||||
# Add global definitions
|
||||
for d in src_code.globals:
|
||||
if required_globals.find(d) == -1:
|
||||
required_globals.push_back(d)
|
||||
# Add generated definitions
|
||||
required_defs += src_code.defs
|
||||
# Add generated code
|
||||
required_code += src_code.code
|
||||
required_textures = src_code.textures
|
||||
string = string.replace("$%s(%s)" % [ input, uv ], src_code.string)
|
||||
return { string=string, defs=required_defs, code=required_code, textures=required_textures, new_pass_required=new_pass_required }
|
||||
return { string=string, globals=required_globals, defs=required_defs, code=required_code, textures=required_textures, new_pass_required=new_pass_required }
|
||||
|
||||
func is_word_letter(l):
|
||||
return "azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890_".find(l) != -1
|
||||
@ -112,6 +119,7 @@ func replace_variable(string, variable, value):
|
||||
|
||||
func subst(string, context, uv = ""):
|
||||
var genname = "o"+str(get_instance_id())
|
||||
var required_globals = []
|
||||
var required_defs = ""
|
||||
var required_code = ""
|
||||
var required_textures = {}
|
||||
@ -157,17 +165,23 @@ func subst(string, context, uv = ""):
|
||||
if result.new_pass_required:
|
||||
new_pass_required = true
|
||||
string = result.string
|
||||
# Add global definitions
|
||||
for d in result.globals:
|
||||
if required_globals.find(d) == -1:
|
||||
required_globals.push_back(d)
|
||||
# Add generated definitions
|
||||
required_defs += result.defs
|
||||
# Add generated code
|
||||
required_code += result.code
|
||||
for t in result.textures.keys():
|
||||
required_textures[t] = result.textures[t]
|
||||
cont = changed and new_pass_required
|
||||
return { string=string, defs=required_defs, code=required_code, textures=required_textures }
|
||||
return { string=string, globals=required_globals, defs=required_defs, code=required_code, textures=required_textures }
|
||||
|
||||
func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
var genname = "o"+str(get_instance_id())
|
||||
var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ]
|
||||
var rv = { defs="", code="", textures={} }
|
||||
var rv = { globals=[], defs="", code="", textures={} }
|
||||
var variant_string = uv+","+str(output_index)
|
||||
if shader_model != null and shader_model.has("outputs") and shader_model.outputs.size() > output_index:
|
||||
var output = shader_model.outputs[output_index]
|
||||
@ -194,7 +208,13 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
var subst_output = subst(output[t.field], context, uv)
|
||||
while subst_output is GDScriptFunctionState:
|
||||
subst_output = yield(subst_output, "completed")
|
||||
# Add global definitions
|
||||
for d in subst_output.globals:
|
||||
if rv.globals.find(d) == -1:
|
||||
rv.globals.push_back(d)
|
||||
# Add generated definitions
|
||||
rv.defs += subst_output.defs
|
||||
# Add generated code
|
||||
rv.code += subst_output.code
|
||||
rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, genname, output_index, variant_index, t.field, subst_output.string ]
|
||||
for t in subst_output.textures.keys():
|
||||
@ -202,14 +222,10 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
for t in output_info:
|
||||
if output.has(t.field):
|
||||
rv[t.field] = "%s_%d_%d_%s" % [ genname, output_index, variant_index, t.field ]
|
||||
if shader_model.has("global") && rv.globals.find(shader_model.global) == -1:
|
||||
rv.globals.push_back(shader_model.global)
|
||||
return rv
|
||||
|
||||
func get_globals():
|
||||
var list = .get_globals()
|
||||
if typeof(shader_model) == TYPE_DICTIONARY and shader_model.has("global") and list.find(shader_model.global) == -1:
|
||||
list.append(shader_model.global)
|
||||
return list
|
||||
|
||||
func _serialize(data):
|
||||
data.shader_model = shader_model
|
||||
return data
|
||||
|
@ -41,3 +41,6 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
rv = yield(rv, "completed")
|
||||
return rv
|
||||
return { defs="", code="", textures={} }
|
||||
|
||||
func _serialize(data):
|
||||
return data
|
||||
|
@ -13,7 +13,7 @@ func get_output_defs():
|
||||
|
||||
func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
var genname = "o"+str(get_instance_id())
|
||||
var rv = { defs="", code="" }
|
||||
var rv = { globals=[], defs="", code="" }
|
||||
var texture_name = genname+"_tex"
|
||||
var variant_index = context.get_variant(self, uv)
|
||||
if variant_index == -1:
|
||||
|
@ -16,15 +16,9 @@ static func add_to_gen_graph(gen_graph, generators, connections):
|
||||
var g = create_gen(n)
|
||||
if g != null:
|
||||
var orig_name = g.name
|
||||
var name = g.name
|
||||
var index = 1
|
||||
while gen_graph.has_node(name):
|
||||
index += 1
|
||||
name = g.name + "_" + str(index)
|
||||
g.name = name
|
||||
gen_graph.add_child(g)
|
||||
gen_graph.add_generator(g)
|
||||
rv.generators.append(g)
|
||||
gennames[orig_name] = name
|
||||
gennames[orig_name] = g.name
|
||||
for c in connections:
|
||||
if gennames.has(c.from) and gennames.has(c.to):
|
||||
c.from = gennames[c.from]
|
||||
|
@ -26,7 +26,7 @@ static func generate_shader(src_code):
|
||||
for g in src_code.globals:
|
||||
code += g
|
||||
var shader_code = src_code.defs
|
||||
shader_code += "void fragment() {\n"
|
||||
shader_code += "\nvoid fragment() {\n"
|
||||
shader_code += src_code.code
|
||||
shader_code += "COLOR = "+src_code.rgba+";\n"
|
||||
shader_code += "}\n"
|
||||
|
1
addons/material_maker/examples/tiles.ptex
Normal file
1
addons/material_maker/examples/tiles.ptex
Normal file
@ -0,0 +1 @@
|
||||
{"connections":[{"from":"shape","from_port":0,"to":"blend","to_port":0},{"from":"pattern","from_port":0,"to":"blend","to_port":1},{"from":"blend","from_port":0,"to":"transform","to_port":0},{"from":"transform_2","from_port":0,"to":"blend_2","to_port":1},{"from":"transform","from_port":0,"to":"blend_2","to_port":0},{"from":"bricks","from_port":1,"to":"transform_2_2","to_port":0},{"from":"transform_2_2","from_port":0,"to":"blend_3","to_port":0},{"from":"bricks","from_port":1,"to":"blend_3","to_port":1},{"from":"transform_2","from_port":0,"to":"blend_4","to_port":0},{"from":"transform","from_port":0,"to":"blend_4","to_port":1},{"from":"transform","from_port":0,"to":"transform_2","to_port":0},{"from":"blend_4","from_port":0,"to":"colorize","to_port":0},{"from":"colorize","from_port":0,"to":"blend_3","to_port":2},{"from":"blend_2","from_port":0,"to":"normal_map","to_port":0},{"from":"normal_map","from_port":0,"to":"Material","to_port":4},{"from":"blend_3","from_port":0,"to":"colorize_2","to_port":0},{"from":"colorize_2","from_port":0,"to":"Material","to_port":0}],"label":"Graph","name":"@@39","node_position":{"x":0,"y":0},"nodes":[{"name":"Material","node_position":{"x":510,"y":-55},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":0.45,"metallic":1,"normal_scale":2.15,"roughness":1},"type":"material"},{"name":"shape","node_position":{"x":-624.5,"y":-157.5},"parameters":{"edge":0.0625,"radius":1,"shape":0,"sides":6},"type":"shape"},{"name":"transform","node_position":{"x":-445.5,"y":-87.5},"parameters":{"repeat":true,"rotate":0,"scale_x":0.125,"scale_y":0.125,"translate_x":0,"translate_y":0},"type":"transform"},{"name":"pattern","node_position":{"x":-726.5,"y":-55.5},"parameters":{"mix":0,"x_scale":2,"x_wave":4,"y_scale":1,"y_wave":3},"type":"pattern"},{"name":"blend","node_position":{"x":-444.240479,"y":-198.5},"parameters":{"amount":1,"blend_type":2},"type":"blend"},{"name":"transform_2","node_position":{"x":-222.240479,"y":-85.5},"parameters":{"repeat":true,"rotate":0,"scale_x":1,"scale_y":1,"translate_x":0.06,"translate_y":0.06},"type":"transform"},{"name":"blend_2","node_position":{"x":-167.240479,"y":-198.5},"parameters":{"amount":1,"blend_type":9},"type":"blend"},{"name":"bricks","node_position":{"x":-506.407684,"y":150.5},"parameters":{"bevel":0,"columns":8,"mortar":0.1,"pattern":0,"repeat":1,"row_offset":0,"rows":8},"type":"bricks"},{"name":"blend_3","node_position":{"x":2.592316,"y":168.5},"parameters":{"amount":1,"blend_type":0},"type":"blend"},{"name":"transform_2_2","node_position":{"x":-262.407715,"y":140},"parameters":{"repeat":true,"rotate":0,"scale_x":1,"scale_y":1,"translate_x":0.56,"translate_y":0.56},"type":"transform"},{"name":"blend_4","node_position":{"x":5.592316,"y":65.5},"parameters":{"amount":1,"blend_type":11},"type":"blend"},{"name":"colorize","node_position":{"x":-14.407684,"y":262.5},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":0.072727,"r":1}],"type":"Gradient"}},"type":"colorize"},{"name":"normal_map","node_position":{"x":83.448486,"y":-87.5},"parameters":{"amount":0.5,"param0":5,"param1":0.69,"size":4},"type":"normal_map"},{"name":"colorize_2","node_position":{"x":217.448486,"y":41.5},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0.375,"pos":0,"r":1},{"a":1,"b":0,"g":0.300293,"pos":1,"r":0.640625}],"type":"Gradient"}},"type":"colorize"}],"parameters":{},"type":"graph"}
|
@ -94,11 +94,25 @@ func clear_view():
|
||||
remove_child(c)
|
||||
c.free()
|
||||
|
||||
# Center view
|
||||
|
||||
func center_view():
|
||||
var center = Vector2(0, 0)
|
||||
var node_count = 0
|
||||
for c in get_children():
|
||||
if c is GraphNode:
|
||||
center += c.offset + 0.5*c.rect_size
|
||||
node_count += 1
|
||||
if node_count > 0:
|
||||
center /= node_count
|
||||
scroll_offset = center - 0.5*rect_size
|
||||
|
||||
func update_view(g):
|
||||
clear_view()
|
||||
generator = g
|
||||
update_graph(generator.get_children(), generator.connections)
|
||||
$ButtonUp.visible = generator != top_generator
|
||||
center_view()
|
||||
|
||||
func clear_material():
|
||||
if top_generator != null:
|
||||
@ -176,11 +190,18 @@ func export_textures(size = null):
|
||||
if save_path != null:
|
||||
var prefix = save_path.left(save_path.rfind("."))
|
||||
for c in get_children():
|
||||
if c is GraphNode and c.has_method("export_textures"):
|
||||
c.export_textures(prefix, size)
|
||||
if c is GraphNode and c.generator.has_method("export_textures"):
|
||||
c.generator.export_textures(prefix, size)
|
||||
|
||||
# Cut / copy / paste
|
||||
|
||||
func get_selected_nodes():
|
||||
var selected_nodes = []
|
||||
for n in get_children():
|
||||
if n is GraphNode and n.selected:
|
||||
selected_nodes.append(n)
|
||||
return selected_nodes
|
||||
|
||||
func remove_selection():
|
||||
for c in get_children():
|
||||
if c is GraphNode and c.selected and c.name != "Material":
|
||||
@ -235,19 +256,6 @@ func paste(pos = Vector2(0, 0)):
|
||||
for c in create_nodes(data, scroll_offset+0.5*rect_size):
|
||||
c.selected = true
|
||||
|
||||
# Center view
|
||||
|
||||
func center_view():
|
||||
var center = Vector2(0, 0)
|
||||
var node_count = 0
|
||||
for c in get_children():
|
||||
if c is GraphNode:
|
||||
center += c.offset + 0.5*c.rect_size
|
||||
node_count += 1
|
||||
if node_count > 0:
|
||||
center /= node_count
|
||||
scroll_offset = center - 0.5*rect_size
|
||||
|
||||
# Delay after graph update
|
||||
|
||||
func send_changed_signal():
|
||||
@ -272,3 +280,12 @@ func drop_data(position, data):
|
||||
func on_ButtonUp_pressed():
|
||||
if generator != top_generator && generator.get_parent() is MMGenGraph:
|
||||
call_deferred("update_view", generator.get_parent())
|
||||
|
||||
# Create subgraph
|
||||
|
||||
func create_subgraph():
|
||||
var generators = []
|
||||
for n in get_selected_nodes():
|
||||
generators.push_back(n.generator)
|
||||
generator.create_subgraph(generators)
|
||||
update_view(generator)
|
||||
|
@ -8,6 +8,7 @@ var editor_interface = null
|
||||
var current_tab = null
|
||||
|
||||
onready var renderer = $Renderer
|
||||
onready var projects = $VBoxContainer/HBoxContainer/Projects
|
||||
|
||||
const MENU = [
|
||||
{ menu="File", command="new_material", description="New material" },
|
||||
@ -25,8 +26,8 @@ const MENU = [
|
||||
{ menu="Edit", command="edit_cut", shortcut="Control+X", description="Cut" },
|
||||
{ menu="Edit", command="edit_copy", shortcut="Control+C", description="Copy" },
|
||||
{ menu="Edit", command="edit_paste", shortcut="Control+V", description="Paste" },
|
||||
{ menu="Tools", command="create_subgraph", description="Create subgraph" },
|
||||
{ menu="Tools", command="make_selected_nodes_editable", description="Make selected nodes editable" },
|
||||
{ menu="Tools", command="create_subgraph", shortcut="Control+G", description="Create subgraph" },
|
||||
{ menu="Tools", command="make_selected_nodes_editable", shortcut="Control+F", description="Make selected nodes editable" },
|
||||
{ menu="Tools", command="add_to_user_library", description="Add selected node to user library" },
|
||||
{ menu="Tools", command="save_user_library", description="Save user library" },
|
||||
{ menu="Help", command="show_doc", description="User manual" },
|
||||
@ -48,7 +49,7 @@ func _ready():
|
||||
new_material()
|
||||
|
||||
func get_current_graph_edit():
|
||||
var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
|
||||
var graph_edit = projects.get_current_tab_control()
|
||||
if graph_edit != null and graph_edit is GraphEdit:
|
||||
return graph_edit
|
||||
return null
|
||||
@ -135,8 +136,8 @@ func new_pane():
|
||||
graph_edit.node_factory = $NodeFactory
|
||||
graph_edit.renderer = $Renderer
|
||||
graph_edit.editor_interface = editor_interface
|
||||
$VBoxContainer/HBoxContainer/Projects.add_child(graph_edit)
|
||||
$VBoxContainer/HBoxContainer/Projects.current_tab = graph_edit.get_index()
|
||||
projects.add_child(graph_edit)
|
||||
projects.current_tab = graph_edit.get_index()
|
||||
return graph_edit
|
||||
|
||||
func new_material():
|
||||
@ -196,7 +197,7 @@ func save_material_as():
|
||||
dialog.popup_centered()
|
||||
|
||||
func close_material():
|
||||
$VBoxContainer/HBoxContainer/Projects.close_tab()
|
||||
projects.close_tab()
|
||||
|
||||
func export_material():
|
||||
var graph_edit = get_current_graph_edit()
|
||||
@ -215,6 +216,7 @@ func quit():
|
||||
else:
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func edit_cut():
|
||||
var graph_edit = get_current_graph_edit()
|
||||
if graph_edit != null:
|
||||
@ -244,21 +246,14 @@ func edit_paste_is_disabled():
|
||||
func get_selected_nodes():
|
||||
var graph_edit = get_current_graph_edit()
|
||||
if graph_edit != null:
|
||||
var selected_nodes = []
|
||||
for n in graph_edit.get_children():
|
||||
if n is GraphNode and n.selected:
|
||||
selected_nodes.append(n)
|
||||
return selected_nodes
|
||||
return graph_edit.get_selected_nodes()
|
||||
else:
|
||||
return []
|
||||
|
||||
func create_subgraph():
|
||||
var graph_edit = get_current_graph_edit()
|
||||
var selected_nodes = get_selected_nodes()
|
||||
if !selected_nodes.empty():
|
||||
for n in selected_nodes:
|
||||
print(n.name)
|
||||
# TODO !
|
||||
if graph_edit != null:
|
||||
graph_edit.create_subgraph()
|
||||
|
||||
func make_selected_nodes_editable():
|
||||
var selected_nodes = get_selected_nodes()
|
||||
@ -326,16 +321,12 @@ func _on_LoadRecent_id_pressed(id):
|
||||
# Preview
|
||||
|
||||
func update_preview():
|
||||
var material_node = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control().get_node("node_Material")
|
||||
if material_node != null:
|
||||
var status = material_node.generator.render_textures(renderer)
|
||||
while status is GDScriptFunctionState:
|
||||
status = yield(status, "completed")
|
||||
material_node.generator.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials())
|
||||
update_preview_2d()
|
||||
update_preview_3d()
|
||||
|
||||
func update_preview_2d(node = null):
|
||||
var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
|
||||
var graph_edit = get_current_graph_edit()
|
||||
if graph_edit != null:
|
||||
var preview = $VBoxContainer/HBoxContainer/VBoxContainer/Preview
|
||||
if node == null:
|
||||
for n in graph_edit.get_children():
|
||||
@ -352,8 +343,17 @@ func update_preview_2d(node = null):
|
||||
tex.create_from_image(image)
|
||||
preview.set_2d(tex)
|
||||
|
||||
func update_preview_3d():
|
||||
var graph_edit = get_current_graph_edit()
|
||||
if graph_edit != null and graph_edit.top_generator != null and graph_edit.top_generator.has_node("Material"):
|
||||
var gen_material = graph_edit.top_generator.get_node("Material")
|
||||
var status = gen_material.render_textures(renderer)
|
||||
while status is GDScriptFunctionState:
|
||||
status = yield(status, "completed")
|
||||
gen_material.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials())
|
||||
|
||||
func _on_Projects_tab_changed(tab):
|
||||
var new_tab = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
|
||||
var new_tab = projects.get_current_tab_control()
|
||||
if new_tab != current_tab:
|
||||
if new_tab != null:
|
||||
for c in get_incoming_connections():
|
||||
|
@ -42,14 +42,14 @@ margin_left = 79.0
|
||||
margin_right = 125.0
|
||||
margin_bottom = 20.0
|
||||
text = "Tools"
|
||||
items = [ "Make selected nodes editable", null, 0, false, false, 15, 0, null, "", false, "Add selected node to user library", null, 0, false, false, 16, 0, null, "", false, "Save user library", null, 0, false, false, 17, 0, null, "", false ]
|
||||
items = [ "Create subgraph", null, 0, false, false, 15, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 16, 268435526, null, "", false, "Add selected node to user library", null, 0, false, false, 17, 0, null, "", false, "Save user library", null, 0, false, false, 18, 0, null, "", false ]
|
||||
|
||||
[node name="Help" type="MenuButton" parent="VBoxContainer/Menu"]
|
||||
margin_left = 129.0
|
||||
margin_right = 171.0
|
||||
margin_bottom = 20.0
|
||||
text = "Help"
|
||||
items = [ "User manual", null, 0, false, false, 18, 0, null, "", false, "Report a bug", null, 0, false, false, 19, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 21, 0, null, "", false ]
|
||||
items = [ "User manual", null, 0, false, false, 19, 0, null, "", false, "Report a bug", null, 0, false, false, 20, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 22, 0, null, "", false ]
|
||||
|
||||
[node name="HBoxContainer" type="HSplitContainer" parent="VBoxContainer"]
|
||||
margin_top = 24.0
|
||||
@ -100,6 +100,7 @@ debug_path = null
|
||||
|
||||
[node name="NodeFactory" type="Node" parent="."]
|
||||
script = ExtResource( 6 )
|
||||
[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="update_preview_3d"]
|
||||
[connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/Projects" to="." method="new_material"]
|
||||
[connection signal="resized" from="VBoxContainer/HBoxContainer/Projects" to="VBoxContainer/HBoxContainer/Projects" method="_on_Projects_resized"]
|
||||
[connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects" to="." method="_on_Projects_tab_changed"]
|
||||
|
@ -50,6 +50,7 @@ func initialize_properties():
|
||||
if parameter_names.find(c) == -1:
|
||||
continue
|
||||
var o = controls[c]
|
||||
if generator.parameters.has(c):
|
||||
on_parameter_changed(c, generator.parameters[c])
|
||||
if o is LineEdit:
|
||||
o.connect("text_changed", self, "_on_text_changed", [ o.name ])
|
||||
@ -134,11 +135,8 @@ func update_node():
|
||||
# Clean node
|
||||
var custom_node_buttons = null
|
||||
for c in get_children():
|
||||
if c.name != "CustomNodeButtons":
|
||||
remove_child(c)
|
||||
c.queue_free()
|
||||
else:
|
||||
custom_node_buttons = c
|
||||
yield(get_tree(), "idle_frame")
|
||||
rect_size = Vector2(0, 0)
|
||||
# Rebuild node
|
||||
title = generator.get_type_name()
|
||||
|
1
addons/material_maker/nodes/kaleidoscope.mmg
Normal file
1
addons/material_maker/nodes/kaleidoscope.mmg
Normal file
@ -0,0 +1 @@
|
||||
{"name":"kaleidoscope","node_position":{"x":0,"y":0},"parameters":{"count":7,"direction":0,"offset":0},"shader_model":{"global":"vec2 kal_rotate(vec2 uv, float count) {\n\tuv -= vec2(0.5);\n\tfloat l = length(uv);\n\tfloat a = mod(atan(uv.y, uv.x), 6.28318530718/count);\n\treturn vec2(0.5)+l*vec2(cos(a), sin(a));\n}","inputs":[{"default":"vec4($uv, 0, 1)","label":"","name":"i","type":"rgba"}],"instance":"","name":"Kaleidoscope","outputs":[{"rgba":"$i(kal_rotate($uv, $count))","type":"rgba"}],"parameters":[{"default":0,"label":"","max":10,"min":2,"name":"count","step":1,"type":"float","widget":"spinbox"}]},"type":"shader"}
|
@ -1 +1 @@
|
||||
{"connections":[{"from":"nm_convolution","from_port":0,"to":"nm_postprocess","to_port":0},{"from":"nm_postprocess","from_port":0,"to":"gen_outputs","to_port":0},{"from":"gen_inputs","from_port":0,"to":"buffer","to_port":0},{"from":"buffer","from_port":0,"to":"nm_convolution","to_port":0}],"label":"Normal Map","name":"normal_map","node_position":{"x":0,"y":0},"nodes":[{"mask":3,"name":"gen_inputs","node_position":{"x":-839.25,"y":177.25},"parameters":{"size":4},"ports":[{"name":"in","type":"rgba"}],"type":"ios"},{"mask":3,"name":"gen_outputs","node_position":{"x":-434.25,"y":318.25},"parameters":{"size":4},"ports":[{"name":"in","type":"rgba"}],"type":"ios"},{"convolution_params":{"input_type":"f","matrix":[[[-1,-1,0],[0,-2,0],[1,-1,0]],[[-2,0,0],0,[2,0,0]],[[-1,1,0],[0,2,0],[1,1,0]]],"output_type":"rgb","x":1,"y":1},"name":"nm_convolution","node_position":{"x":-669.25,"y":245.25},"parameters":{"size":5},"type":"shader"},{"name":"nm_postprocess","node_position":{"x":-678.25,"y":315.25},"parameters":{"amount":0.99,"size":5},"shader_model":{"global":"","inputs":[{"default":"vec3(0.0)","label":"","name":"in","type":"rgb"}],"instance":"","name":"NormalMapPostProcess","outputs":[{"rgb":"0.5*normalize($in($uv)*$amount*$size/128.0-vec3(0.0, 0.0, 1.0))+vec3(0.5)","type":"rgb"}],"parameters":[{"default":8,"first":4,"label":"","last":11,"name":"size","type":"size"},{"default":1,"label":"","max":2,"min":0,"name":"amount","step":0.005,"type":"float"}]},"type":"shader"},{"name":"buffer","node_position":{"x":-669.663818,"y":174.60614},"parameters":{"size":5},"type":"buffer"},{"name":"gen_parameters","node_position":{"x":-702.910156,"y":23.083313},"parameters":{"param0":5,"param1":0.99},"type":"remote","widgets":[{"label":"Unnamed","linked_widgets":[{"node":"buffer","widget":"size"},{"node":"nm_convolution","widget":"size"},{"node":"nm_postprocess","widget":"size"}],"type":"linked_control"},{"label":"Unnamed","linked_widgets":[{"node":"nm_postprocess","widget":"amount"}],"type":"linked_control"}]}],"parameters":{"amount":0.35,"param0":5,"param1":0.99,"size":4},"type":"graph"}
|
||||
{"connections":[{"from":"nm_convolution","from_port":0,"to":"nm_postprocess","to_port":0},{"from":"nm_postprocess","from_port":0,"to":"gen_outputs","to_port":0},{"from":"gen_inputs","from_port":0,"to":"buffer","to_port":0},{"from":"buffer","from_port":0,"to":"nm_convolution","to_port":0}],"label":"Normal Map","name":"normal_map","node_position":{"x":0,"y":0},"nodes":[{"mask":3,"name":"gen_inputs","node_position":{"x":-839.25,"y":177.25},"parameters":{"size":4},"ports":[{"name":"in","type":"rgba"}],"type":"ios"},{"mask":3,"name":"gen_outputs","node_position":{"x":-434.25,"y":318.25},"parameters":{"size":4},"ports":[{"name":"in","type":"rgba"}],"type":"ios"},{"convolution_params":{"input_type":"f","matrix":[[[-1,-1,0],[0,-2,0],[1,-1,0]],[[-2,0,0],0,[2,0,0]],[[-1,1,0],[0,2,0],[1,1,0]]],"output_type":"rgb","x":1,"y":1},"name":"nm_convolution","node_position":{"x":-669.25,"y":245.25},"parameters":{"size":5},"type":"shader"},{"name":"nm_postprocess","node_position":{"x":-678.25,"y":315.25},"parameters":{"amount":0.99,"size":5},"shader_model":{"global":"","inputs":[{"default":"vec3(0.0)","label":"","name":"in","type":"rgb"}],"instance":"","name":"NormalMapPostProcess","outputs":[{"rgb":"0.5*normalize($in($uv)*$amount*$size/128.0-vec3(0.0, 0.0, 1.0))+vec3(0.5)","type":"rgb"}],"parameters":[{"default":9,"first":4,"label":"","last":11,"name":"size","type":"size"},{"default":1,"label":"","max":2,"min":0,"name":"amount","step":0.005,"type":"float"}]},"type":"shader"},{"name":"buffer","node_position":{"x":-669.663818,"y":174.60614},"parameters":{"size":5},"type":"buffer"},{"name":"gen_parameters","node_position":{"x":-713.910156,"y":24.083313},"parameters":{"param0":5,"param1":0.99},"type":"remote","widgets":[{"label":"Unnamed","linked_widgets":[{"node":"buffer","widget":"size"},{"node":"nm_convolution","widget":"size"},{"node":"nm_postprocess","widget":"size"}],"type":"linked_control"},{"label":"Unnamed","linked_widgets":[{"node":"nm_postprocess","widget":"amount"}],"type":"linked_control"}]}],"parameters":{"amount":0.35,"param0":5,"param1":0.99,"size":4},"type":"graph"}
|
@ -28,6 +28,7 @@ func update_node():
|
||||
for c in grid.get_children():
|
||||
c.queue_free()
|
||||
yield(get_tree(), "idle_frame")
|
||||
title = generator.get_type_name()
|
||||
controls = {}
|
||||
for p in generator.get_parameter_defs():
|
||||
var control = create_parameter_control(p)
|
||||
@ -101,7 +102,6 @@ func _on_Link_pressed(index):
|
||||
link.pick(grid.get_child(index*4+1), generator, index)
|
||||
|
||||
func _on_Remote_resize_request(new_minsize):
|
||||
print("_on_Remote_resize_request")
|
||||
rect_size = new_minsize
|
||||
|
||||
func _on_HBoxContainer_minimum_size_changed():
|
||||
|
@ -7,13 +7,18 @@ const ENVIRONMENTS = [
|
||||
"experiment", "lobby", "night", "park", "schelde"
|
||||
]
|
||||
|
||||
onready var objects = $MaterialPreview/Objects
|
||||
onready var current_object = objects.get_child(0)
|
||||
|
||||
signal need_update
|
||||
|
||||
func _ready():
|
||||
var m
|
||||
m = $MaterialPreview/Objects/Cube.get_surface_material(0).duplicate()
|
||||
$MaterialPreview/Objects/Cube.set_surface_material(0, m)
|
||||
$MaterialPreview/Objects/Cylinder.set_surface_material(0, m)
|
||||
m = $MaterialPreview/Objects/Sphere.get_surface_material(0).duplicate()
|
||||
$MaterialPreview/Objects/Sphere.set_surface_material(0, m)
|
||||
current_object.visible = true
|
||||
$Config/Model.clear()
|
||||
for o in objects.get_children():
|
||||
var m = o.get_surface_material(0)
|
||||
o.set_surface_material(0, m.duplicate())
|
||||
$Config/Model.add_item(o.name)
|
||||
$ObjectRotate.play("rotate")
|
||||
$Preview2D.material = $Preview2D.material.duplicate(true)
|
||||
_on_Environment_item_selected($Config/Environment.selected)
|
||||
@ -23,12 +28,13 @@ func _on_Environment_item_selected(id):
|
||||
$MaterialPreview/WorldEnvironment.environment.background_sky.panorama = load("res://addons/material_maker/panoramas/"+ENVIRONMENTS[id]+".hdr")
|
||||
|
||||
func _on_Model_item_selected(id):
|
||||
var model = $Config/Model.get_item_text(id)
|
||||
for c in $MaterialPreview/Objects.get_children():
|
||||
c.visible = (c.get_name() == model)
|
||||
current_object.visible = false
|
||||
current_object = objects.get_child(id)
|
||||
current_object.visible = true
|
||||
emit_signal("need_update")
|
||||
|
||||
func get_materials():
|
||||
return [ $MaterialPreview/Objects/Cube.get_surface_material(0), $MaterialPreview/Objects/Sphere.get_surface_material(0) ]
|
||||
return [ current_object.get_surface_material(0) ]
|
||||
|
||||
func set_2d(tex: Texture):
|
||||
$Preview2D.material.set_shader_param("tex", tex)
|
||||
@ -46,5 +52,3 @@ func _on_Preview2D_gui_input(ev : InputEvent):
|
||||
if ev is InputEventMouseButton and ev.button_index == 1 and ev.pressed:
|
||||
preview_maximized = !preview_maximized
|
||||
_on_Preview_resized()
|
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
65
addons/material_maker/preview_objects.tscn
Normal file
65
addons/material_maker/preview_objects.tscn
Normal file
@ -0,0 +1,65 @@
|
||||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://rodz_labs_logo.png" type="Texture" id=1]
|
||||
|
||||
[sub_resource type="CubeMesh" id=1]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=2]
|
||||
albedo_texture = ExtResource( 1 )
|
||||
uv1_scale = Vector3( 3, 2, 1 )
|
||||
|
||||
[sub_resource type="CylinderMesh" id=3]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=4]
|
||||
albedo_texture = ExtResource( 1 )
|
||||
uv1_scale = Vector3( 2, 2, 2 )
|
||||
|
||||
[sub_resource type="SphereMesh" id=5]
|
||||
radius = 1.5
|
||||
height = 3.0
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=6]
|
||||
albedo_texture = ExtResource( 1 )
|
||||
uv1_scale = Vector3( 2, 2, 2 )
|
||||
uv1_offset = Vector3( 0, 0.5, 0 )
|
||||
|
||||
[sub_resource type="PlaneMesh" id=7]
|
||||
size = Vector2( 3, 3 )
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=8]
|
||||
albedo_texture = ExtResource( 1 )
|
||||
|
||||
[sub_resource type="PlaneMesh" id=9]
|
||||
size = Vector2( 12, 12 )
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=10]
|
||||
albedo_texture = ExtResource( 1 )
|
||||
uv1_scale = Vector3( 4, 4, 4 )
|
||||
|
||||
[node name="Objects" type="Spatial"]
|
||||
transform = Transform( -0.685898, 0, 0.727691, 0, 1, 0, -0.727691, 0, -0.685898, 0, 0, 0 )
|
||||
|
||||
[node name="Cube" type="MeshInstance" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = SubResource( 2 )
|
||||
|
||||
[node name="Cylinder" type="MeshInstance" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource( 3 )
|
||||
material/0 = SubResource( 4 )
|
||||
|
||||
[node name="Sphere" type="MeshInstance" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource( 5 )
|
||||
material/0 = SubResource( 6 )
|
||||
|
||||
[node name="Quad" type="MeshInstance" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource( 7 )
|
||||
material/0 = SubResource( 8 )
|
||||
|
||||
[node name="Plane" type="MeshInstance" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource( 9 )
|
||||
material/0 = SubResource( 10 )
|
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 15 KiB |
Loading…
Reference in New Issue
Block a user