2018-08-01 07:50:58 +02:00
|
|
|
tool
|
2018-09-03 21:35:44 +02:00
|
|
|
extends "res://addons/material_maker/node_base.gd"
|
2018-08-01 07:50:58 +02:00
|
|
|
|
2018-08-12 19:25:18 +02:00
|
|
|
const WAVE_FCT = [ "wave_sin", "wave_triangle", "wave_square", "fract", "wave_constant" ]
|
2018-08-01 07:50:58 +02:00
|
|
|
const MIX_FCT = [ "mix_multiply", "mix_add", "mix_max", "mix_min", "mix_xor", "mix_pow" ]
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
initialize_properties([ $HBoxContainer0/mix, $HBoxContainer1/x_wave, $HBoxContainer1/x_scale, $HBoxContainer2/y_wave, $HBoxContainer2/y_scale ])
|
|
|
|
|
|
|
|
func _get_shader_code(uv):
|
|
|
|
var rv = { defs="", code="" }
|
|
|
|
if generated_variants.empty():
|
2018-10-02 07:46:20 +02:00
|
|
|
rv.defs = "float %s_f(vec2 uv) { uv *= vec2(%.9f, %.9f); return %s(%s(uv.x), %s(uv.y)); }\n" % [ name, parameters.x_scale, parameters.y_scale, MIX_FCT[parameters.mix], WAVE_FCT[parameters.x_wave], WAVE_FCT[parameters.y_wave] ]
|
2018-08-01 07:50:58 +02:00
|
|
|
var variant_index = generated_variants.find(uv)
|
|
|
|
if variant_index == -1:
|
|
|
|
variant_index = generated_variants.size()
|
|
|
|
generated_variants.append(uv)
|
|
|
|
rv.code = "float %s_%d_f = %s_f(%s);\n" % [ name, variant_index, name, uv ]
|
|
|
|
rv.f = name+"_"+str(variant_index)+"_f"
|
|
|
|
return rv
|