2018-07-22 17:20:27 +02:00
|
|
|
tool
|
2018-09-03 21:35:44 +02:00
|
|
|
extends "res://addons/material_maker/node_base.gd"
|
2018-07-22 17:20:27 +02:00
|
|
|
|
2018-08-19 15:23:11 +02:00
|
|
|
const BRICK_PATTERNS = [
|
|
|
|
{ name="Running bond", suffix="rb", has_offset=true, has_repeat=false },
|
|
|
|
{ name="Running bond (2)", suffix="rb2", has_offset=true, has_repeat=false },
|
|
|
|
{ name="HerringBone", suffix="hb", has_offset=false, has_repeat=true },
|
|
|
|
{ name="Basket weave", suffix="bw", has_offset=false, has_repeat=true },
|
|
|
|
{ name="Spanish bond", suffix="sb", has_offset=false, has_repeat=true }
|
|
|
|
]
|
|
|
|
|
2018-07-22 17:20:27 +02:00
|
|
|
func _ready():
|
2018-08-19 15:23:11 +02:00
|
|
|
$pattern.clear()
|
|
|
|
for p in BRICK_PATTERNS:
|
|
|
|
$pattern.add_item(p.name)
|
|
|
|
initialize_properties([ $pattern, $HBoxContainer1/rows, $HBoxContainer2/columns, $HBoxContainer6/repeat, $HBoxContainer3/row_offset, $HBoxContainer4/mortar, $HBoxContainer5/bevel ])
|
2018-07-22 17:20:27 +02:00
|
|
|
|
2018-08-03 22:38:48 +02:00
|
|
|
func _get_shader_code(uv, slot = 0):
|
2018-07-22 23:25:05 +02:00
|
|
|
var rv = { defs="", code="" }
|
|
|
|
if generated_variants.empty():
|
2018-10-02 07:46:20 +02:00
|
|
|
rv.defs = "vec3 %s_xyz(vec2 uv) { return bricks_%s(uv, vec2(%d, %d), %.9f, %.9f, %.9f, %.9f); }\n" % [ name, BRICK_PATTERNS[parameters.pattern].suffix, parameters.columns, parameters.rows, parameters.repeat, parameters.row_offset, parameters.mortar, max(0.001, parameters.bevel) ]
|
2018-07-22 23:25:05 +02:00
|
|
|
var variant_index = generated_variants.find(uv)
|
|
|
|
if variant_index == -1:
|
|
|
|
variant_index = generated_variants.size()
|
|
|
|
generated_variants.append(uv)
|
2018-08-19 15:23:11 +02:00
|
|
|
rv.code = "vec3 %s_%d_xyz = %s_xyz(%s);\n" % [ name, variant_index, name, uv ]
|
2018-08-03 22:38:48 +02:00
|
|
|
if slot == 0:
|
2018-08-19 15:23:11 +02:00
|
|
|
rv.f = "%s_%d_xyz.x" % [ name, variant_index ]
|
2018-08-03 22:38:48 +02:00
|
|
|
else:
|
2018-08-19 15:23:11 +02:00
|
|
|
rv.rgb = "rand3(%s_%d_xyz.yz+vec2(%.9f))" % [ name, variant_index, get_seed() ]
|
2018-07-22 17:20:27 +02:00
|
|
|
return rv
|
2018-08-19 15:23:11 +02:00
|
|
|
|
|
|
|
func _on_offset_changed():
|
|
|
|
update_shaders()
|