material-maker/addons/procedural_material/graph_edit.gd
RodZill4 10ea905090 Many changes & fixes...
- shader updates are delayed by .25 seconds to avouid UI freeze
- fixed GraphNode initialization upon loading
- started obsoleting get_source_rgb and get_source_f functions
- updated colorize node to use gradient
- image node can now be loaded/saved
- removed iqnoise node
- rewrote perlin shader to support a seed parameter (seed is calculated from the node's position, so just move it to reseed)
- Added voronoi noise node
- updated code to use % formats instead of concatenating strings (should solve type problems in shaders)
- reworked the context menu (now has submenus)
- fixes in the gradient editor
2018-07-28 09:37:51 +02:00

59 lines
1.5 KiB
GDScript

tool
extends GraphEdit
signal graph_changed
func _ready():
pass
func get_source(node, port):
for c in get_connection_list():
if c.to == node && c.to_port == port:
return { node=c.from, slot=c.from_port }
func remove_node(node):
for c in get_connection_list():
if c.from == node or c.to == node:
disconnect_node(c.from, c.from_port, c.to, c.to_port)
func send_changed_signal():
$Timer.start()
func do_send_changed_signal():
emit_signal("graph_changed")
func generate_shader(node, shader_type = 0):
var code
if shader_type == 1:
code = "shader_type spatial;\n\n"
else:
code = "shader_type canvas_item;\n\n"
var file = File.new()
file.open("res://addons/procedural_material/shader_header.txt", File.READ)
code += file.get_as_text()
code += "\n"
for c in get_children():
if c is GraphNode:
c.generated = false
c.generated_variants = []
var src_code = node.get_shader_code("UV")
var shader_code = src_code.defs
shader_code += "void fragment() {\n"
shader_code += src_code.code
if shader_type == 1:
if src_code.has("albedo"):
shader_code += "ALBEDO = "+src_code.albedo+";\n"
if src_code.has("normal_map"):
shader_code += "NORMALMAP = "+src_code.normal_map+";\n"
else:
if src_code.has("rgb"):
shader_code += "COLOR = vec4("+src_code.rgb+", 1.0);\n"
elif src_code.has("f"):
shader_code += "COLOR = vec4(vec3("+src_code.f+"), 1.0);\n"
else:
shader_code += "COLOR = vec4(1.0);\n"
shader_code += "}\n"
#print("GENERATED SHADER:\n"+shader_code)
code += shader_code
return code