2018-07-28 09:37:51 +02:00
|
|
|
tool
|
2018-09-03 21:35:44 +02:00
|
|
|
extends "res://addons/material_maker/node_base.gd"
|
2018-07-28 09:37:51 +02:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_slot(0, false, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1))
|
|
|
|
initialize_properties([ $HBoxContainer1/scale_x, $HBoxContainer2/scale_y, $HBoxContainer3/intensity ])
|
|
|
|
|
2018-08-03 22:38:48 +02:00
|
|
|
func _get_shader_code(uv, slot = 0):
|
2018-07-28 09:37:51 +02:00
|
|
|
var rv = { defs="", code="" }
|
|
|
|
if generated_variants.empty():
|
2018-10-02 07:46:20 +02:00
|
|
|
rv.defs = "vec4 %s_xyzw(vec2 uv) { return voronoi(uv, vec2(%f, %f), %.9f, %d); }\n" % [ name, parameters.scale_x, parameters.scale_y, parameters.intensity, get_seed() ]
|
2018-07-28 09:37:51 +02:00
|
|
|
var variant_index = generated_variants.find(uv)
|
|
|
|
if variant_index == -1:
|
|
|
|
variant_index = generated_variants.size()
|
|
|
|
generated_variants.append(uv)
|
2018-08-20 15:43:03 +02:00
|
|
|
rv.code = "vec4 %s_%d_xyzw = %s_xyzw(%s);\n" % [ name, variant_index, name, uv ]
|
2018-08-03 22:38:48 +02:00
|
|
|
if slot == 0:
|
2018-08-20 15:43:03 +02:00
|
|
|
rv.f = "%s_%d_xyzw.z" % [ name, variant_index ]
|
2018-08-03 22:38:48 +02:00
|
|
|
elif slot == 1:
|
2018-08-20 15:43:03 +02:00
|
|
|
rv.f = "%s_%d_xyzw.w" % [ name, variant_index ]
|
2018-08-03 22:38:48 +02:00
|
|
|
else:
|
2018-08-20 15:43:03 +02:00
|
|
|
rv.rgb = "rand3(fract(%s_%d_xyzw.xy))" % [ name, variant_index ]
|
2018-07-28 09:37:51 +02:00
|
|
|
return rv
|
|
|
|
|
|
|
|
func _on_offset_changed():
|
|
|
|
update_shaders()
|