2018-07-22 17:20:27 +02:00
|
|
|
tool
|
|
|
|
extends "res://addons/procedural_material/node_base.gd"
|
|
|
|
|
2018-07-26 00:08:34 +02:00
|
|
|
var scale_x
|
|
|
|
var scale_y
|
2018-07-22 17:20:27 +02:00
|
|
|
var iterations
|
2018-07-29 14:21:49 +02:00
|
|
|
var persistence
|
2018-07-22 17:20:27 +02:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_slot(0, false, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1))
|
2018-07-29 14:21:49 +02:00
|
|
|
initialize_properties([ $GridContainer/scale_x, $GridContainer/scale_y, $GridContainer/iterations, $GridContainer/persistence ])
|
2018-07-22 17:20:27 +02:00
|
|
|
|
2018-07-26 08:31:28 +02:00
|
|
|
func _get_shader_code(uv):
|
2018-07-22 23:25:05 +02:00
|
|
|
var rv = { defs="", code="" }
|
2018-07-23 22:18:43 +02:00
|
|
|
if generated_variants.empty():
|
2018-07-29 14:21:49 +02:00
|
|
|
rv.defs = "float "+name+"_f(vec2 uv) { return perlin(uv, vec2(%f, %f), %d, %.9f, %d); }\n" % [ scale_x, scale_y, iterations, persistence, get_seed() ]
|
2018-07-23 22:18:43 +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 "+name+"_"+str(variant_index)+"_f = "+name+"_f("+uv+");\n"
|
|
|
|
rv.f = name+"_"+str(variant_index)+"_f"
|
2018-07-22 17:20:27 +02:00
|
|
|
return rv
|
2018-07-28 09:37:51 +02:00
|
|
|
|
|
|
|
func _on_offset_changed():
|
|
|
|
update_shaders()
|