2018-07-22 17:20:27 +02:00
|
|
|
tool
|
|
|
|
extends "res://addons/procedural_material/node_base.gd"
|
|
|
|
|
2018-08-02 06:32:08 +02:00
|
|
|
var translate_x = 0.0
|
|
|
|
var translate_y = 0.0
|
2018-07-26 00:08:34 +02:00
|
|
|
var rotate = 0.0
|
2018-08-09 22:19:27 +02:00
|
|
|
var scale_x = 1.0
|
|
|
|
var scale_y = 1.0
|
|
|
|
var repeat = true
|
2018-07-22 17:20:27 +02:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_slot(0, true, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1))
|
2018-08-09 22:19:27 +02:00
|
|
|
initialize_properties([ $HBoxContainer1/translate_x, $HBoxContainer2/translate_y, $HBoxContainer3/rotate, $HBoxContainer4/scale_x, $HBoxContainer5/scale_y, $repeat ])
|
2018-07-22 17:20:27 +02:00
|
|
|
|
2018-07-26 08:31:28 +02:00
|
|
|
func _get_shader_code(uv):
|
2018-07-23 22:18:43 +02:00
|
|
|
var rv = { defs="", code="" }
|
2018-07-22 17:20:27 +02:00
|
|
|
var src = get_source()
|
|
|
|
if src == null:
|
|
|
|
return rv
|
2018-08-25 08:07:22 +02:00
|
|
|
var variant_index = generated_variants.find(uv)
|
|
|
|
if variant_index == -1:
|
|
|
|
variant_index = generated_variants.size()
|
|
|
|
generated_variants.append(uv)
|
|
|
|
var inputs = [ "", "", "", "", "" ]
|
|
|
|
for i in range(5):
|
|
|
|
var tsrc = get_source(i+1)
|
|
|
|
if tsrc != null:
|
|
|
|
var tsrc_code = tsrc.get_shader_code(uv)
|
|
|
|
if generated_variants.size() == 1:
|
|
|
|
rv.defs += tsrc_code.defs
|
|
|
|
rv.code += tsrc_code.code
|
|
|
|
inputs[i] = "*(2.0*(%s)-1.0)" % tsrc_code.f
|
|
|
|
rv.code += "vec2 %s_%d_uv = %s(%s, vec2(%.9f%s, %.9f%s), %.9f%s, vec2(%.9f%s, %.9f%s));\n" % [ name, variant_index, "transform_repeat" if repeat else "transform_norepeat", uv, translate_x, inputs[0], translate_y, inputs[1], PI*rotate/180.0, inputs[2], scale_x, inputs[3], scale_y, inputs[4] ]
|
|
|
|
var src_code = src.get_shader_code("%s_%d_uv" % [ name, variant_index ])
|
|
|
|
if rv.code != "":
|
|
|
|
if generated_variants.size() == 1:
|
|
|
|
rv.defs += src_code.defs
|
|
|
|
rv.code += src_code.code
|
|
|
|
rv.rgb = src_code.rgb
|
2018-07-22 17:20:27 +02:00
|
|
|
return rv
|
2018-08-09 22:19:27 +02:00
|
|
|
|
|
|
|
func deserialize(data):
|
|
|
|
if data.has("scale"):
|
|
|
|
scale_x = data.scale
|
|
|
|
scale_y = data.scale
|
|
|
|
.deserialize(data)
|