2019-11-02 08:43:54 +01:00
|
|
|
extends MMGraphNodeBase
|
|
|
|
|
|
|
|
static func generate_shader(src_code) -> String:
|
|
|
|
var code
|
|
|
|
code = ""
|
|
|
|
var file = File.new()
|
|
|
|
file.open("res://addons/material_maker/common.shader", File.READ)
|
|
|
|
code += file.get_as_text()
|
|
|
|
code += "\n"
|
|
|
|
if src_code.has("textures"):
|
|
|
|
for t in src_code.textures.keys():
|
|
|
|
code += "uniform sampler2D "+t+";\n"
|
|
|
|
if src_code.has("globals"):
|
|
|
|
for g in src_code.globals:
|
|
|
|
code += g
|
|
|
|
var shader_code = src_code.defs
|
|
|
|
shader_code += "\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\nvec2 UV = fragCoord/iResolution.xy;\n"
|
|
|
|
shader_code += src_code.code
|
|
|
|
shader_code += "fragColor = "+src_code.rgba+";\n"
|
|
|
|
shader_code += "}\n"
|
|
|
|
#print("GENERATED SHADER:\n"+shader_code)
|
|
|
|
code += shader_code
|
|
|
|
return code
|
|
|
|
|
2019-11-06 23:49:26 +01:00
|
|
|
func _on_Button_pressed() -> void:
|
2019-11-02 08:43:54 +01:00
|
|
|
var src = generator.get_source(0)
|
|
|
|
if src != null:
|
2019-11-06 23:49:26 +01:00
|
|
|
var context : MMGenContext = MMGenContext.new()
|
2019-11-02 08:43:54 +01:00
|
|
|
var source = src.generator.get_shader_code("UV", src.output_index, context)
|
|
|
|
var popup = preload("res://addons/material_maker/nodes/debug/debug_popup.tscn").instance()
|
|
|
|
get_parent().add_child(popup)
|
|
|
|
popup.show_code(generate_shader(source))
|