Added the bricks node.

This commit is contained in:
Relintai 2021-10-18 15:32:30 +02:00
parent 095fcab86c
commit e6468b8226
4 changed files with 404 additions and 139 deletions

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" load_steps=34 format=2]
[gd_resource type="Resource" load_steps=46 format=2]
[ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/nodes/noise/perlin.gd" type="Script" id=2]
@ -11,6 +11,7 @@
[ext_resource path="res://addons/mat_maker_gd/nodes/uniform/uniform.gd" type="Script" id=9]
[ext_resource path="res://addons/mat_maker_gd/nodes/simple/image.gd" type="Script" id=10]
[ext_resource path="res://addons/mat_maker_gd/nodes/filter/colorize.gd" type="Script" id=11]
[ext_resource path="res://addons/mat_maker_gd/nodes/pattern/bricks.gd" type="Script" id=12]
[sub_resource type="Resource" id=1]
script = ExtResource( 2 )
@ -194,7 +195,116 @@ interpolation_type = 1
points = PoolRealArray( 0, 0.171875, 1, 0, 1, 0.508474, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0.015625, 1, 1 )
image = SubResource( 26 )
[sub_resource type="Resource" id=29]
script = ExtResource( 5 )
default_type = 1
default_int = 0
default_float = 0.1
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=30]
script = ExtResource( 5 )
default_type = 1
default_int = 0
default_float = 0.1
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=31]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=32]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=33]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=34]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=35]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=36]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=37]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=38]
script = ExtResource( 5 )
default_type = 1
default_int = 0
default_float = 0.1
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=39]
script = ExtResource( 12 )
graph_position = Vector2( 400, 180 )
out_bricks_pattern = SubResource( 32 )
out_random_color = SubResource( 37 )
out_position_x = SubResource( 35 )
out_position_y = SubResource( 36 )
out_brick_uv = SubResource( 31 )
out_corner_uv = SubResource( 33 )
out_direction = SubResource( 34 )
type = 0
repeat = 1
row_col = Vector2( 4, 4 )
offset = 0.5
mortar = SubResource( 30 )
bevel = SubResource( 29 )
roundness = SubResource( 38 )
corner = 0.3
[resource]
script = ExtResource( 1 )
image_size = Vector2( 128, 128 )
nodes = [ SubResource( 1 ), SubResource( 2 ), SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ) ]
nodes = [ SubResource( 1 ), SubResource( 2 ), SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ) ]

View File

@ -870,8 +870,10 @@ static func brick(uv : Vector2, bmin : Vector2, bmax : Vector2, mortar : float,
# return rand3(fract(center + vec2(seed)));
#}
static func brick_random_color(uv : Vector2, bmin : Vector2, bmax : Vector2, pseed : float) -> Vector3:
var center : Vector2 = 0.5 * (bmin + bmax)
static func brick_random_color(bmin : Vector2, bmax : Vector2, pseed : float) -> Vector3:
var center : Vector2 = (bmin + bmax)
center.x *= 0.5
center.y *= 0.5
return Commons.rand3(Commons.fractv2(center + Vector2(pseed, pseed)));

View File

@ -1,135 +0,0 @@
tool
extends MMNode
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
var image : Image
var tex : ImageTexture
export(Vector2) var bmin : Vector2 = Vector2(0.1, 0.1)
export(Vector2) var bmax : Vector2 = Vector2(1, 1)
export(bool) var refresh setget reff,reffg
func _ready():
pass
#float o39644_0_2_f : float = o39644_0.x
var seed_o39644 : int = 15005
var p_o39644_repeat : float = 1.000000000
var p_o39644_rows : float = 6.000000000
var p_o39644_columns : float = 3.000000000
var p_o39644_row_offset : float = 0.500000000
var p_o39644_mortar: float = 0.100000000
var p_o39644_bevel : float = 0.100000000
var p_o39644_round : float= 0.000000000
var p_o39644_corner : float = 0.420000000
var p_o3335_albedo_color_r : float = 1.000000000
var p_o3335_albedo_color_g : float = 1.000000000
var p_o3335_albedo_color_b : float = 1.000000000
var p_o3335_albedo_color_a : float = 1.000000000
var p_o3335_metallic : float = 1.000000000
var p_o3335_roughness : float = 1.000000000
var p_o3335_emission_energy : float = 1.000000000
var p_o3335_normal : float = 1.000000000
var p_o3335_ao : float = 1.000000000
var p_o3335_depth_scale : float = 0.500000000
var p_o3335_sss : float = 0.000000000
func gen() -> void:
if !image:
image = Image.new()
image.create(300, 300, false, Image.FORMAT_RGBA8)
if !tex:
tex = ImageTexture.new()
# var bmin : Vector2 = Vector2(0.1, 0.1)
# var bmax : Vector2 = Vector2(1, 1)
image.lock()
var w : float = image.get_width()
var h : float = image.get_width()
var pseed : float = randf() + randi()
for x in range(image.get_width()):
for y in range(image.get_height()):
var v : Vector2 = Vector2(x / w, y / h)
# var vb : Vector3 = brick_uv(v, bmin, bmax, pseed)
## var col : Color = Color(vb.x, vb.y, vb.z, 1)
#
# var col : Color = brick(v, bmin, bmax, 0.2, 0.2, 0.2)
# var cc : Color = Color(vb.x, vb.y, vb.z, 1)
# image.set_pixel(x, y, cc)
#Running Bond
# var brect : Color = bricks_rb(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
#RunningBond2
# var brect : Color = bricks_rb2(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
#HerringBone
# var brect : Color = bricks_hb(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
#BasketWeave
# var brect : Color = bricks_bw(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
#SpanishBond
var brect : Color = Patterns.bricks_sb(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
# 1, 2
var fcolor : Color = Patterns.brick(v, Vector2(brect.r, brect.g), Vector2(brect.b, brect.a), p_o39644_mortar*1.0, p_o39644_round*1.0, max(0.001, p_o39644_bevel*1.0));
# image.set_pixel(x, y, brect)
# image.set_pixel(x, y, fcolor)
# image.set_pixel(x, y, Color(fcolor.r, fcolor.g, fcolor.b, 1))
#1
var rr : float = fcolor.r;
image.set_pixel(x, y, Color(rr,rr, rr, 1))
#
# # 3
# var yy : float = fcolor.g;
# image.set_pixel(x, y, Color(yy,yy, yy, 1))
#
# # 4
# var zz : float = fcolor.b;
# image.set_pixel(x, y, Color(zz,zz, zz, 1))
# 5
# var c : Vector3 = brick_uv(v, Vector2(brect.r, brect.g), Vector2(brect.b, brect.a), float(seed_o39644))
# image.set_pixel(x, y, Color(c.x, c.y, c.z, 1))
# 6
# var c : Vector3 = brick_corner_uv(v, Vector2(brect.r, brect.g), Vector2(brect.b, brect.a), p_o39644_mortar*1.0, p_o39644_corner, float(seed_o39644));
# image.set_pixel(x, y, Color(c.x, c.y, c.z, 1))
# 7
# var f : float = 0.5*(sign(brect.b-brect.r-brect.a+brect.g)+1.0);
# image.set_pixel(x, y, Color(f, f, f, 1))
image.unlock()
tex.create_from_image(image)
# texture = tex
func reffg():
return false
func reff(bb):
if bb:
gen()

View File

@ -0,0 +1,288 @@
tool
extends MMNode
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
export(Resource) var out_bricks_pattern : Resource
export(Resource) var out_random_color : Resource
export(Resource) var out_position_x : Resource
export(Resource) var out_position_y : Resource
export(Resource) var out_brick_uv : Resource
export(Resource) var out_corner_uv : Resource
export(Resource) var out_direction : Resource
export(int, "Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond") var type : int = 0
export(int) var repeat : int = 1
export(Vector2) var row_col : Vector2 = Vector2(4, 4)
export(float) var offset : float = 0.5
export(Resource) var mortar : Resource
export(Resource) var bevel : Resource
export(Resource) var roundness : Resource
export(float) var corner : float = 0.3
func _init_properties():
if !out_bricks_pattern:
out_bricks_pattern = MMNodeUniversalProperty.new()
out_bricks_pattern.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
out_bricks_pattern.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
if !out_random_color:
out_random_color = MMNodeUniversalProperty.new()
out_random_color.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
out_random_color.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
if !out_position_x:
out_position_x = MMNodeUniversalProperty.new()
out_position_x.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
out_position_x.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
if !out_position_y:
out_position_y = MMNodeUniversalProperty.new()
out_position_y.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
out_position_y.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
if !out_brick_uv:
out_brick_uv = MMNodeUniversalProperty.new()
out_brick_uv.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
out_brick_uv.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
if !out_corner_uv:
out_corner_uv = MMNodeUniversalProperty.new()
out_corner_uv.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
out_corner_uv.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
if !out_direction:
out_direction = MMNodeUniversalProperty.new()
out_direction.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
out_direction.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
if !mortar:
mortar = MMNodeUniversalProperty.new()
mortar.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
mortar.set_default_value(0.1)
mortar.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
mortar.slot_name = "Mortar"
mortar.value_step = 0.01
mortar.value_range = Vector2(0, 0.5)
if !bevel:
bevel = MMNodeUniversalProperty.new()
bevel.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
bevel.set_default_value(0.1)
bevel.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
bevel.slot_name = "Bevel"
bevel.value_step = 0.01
bevel.value_range = Vector2(0, 0.5)
if !roundness:
roundness = MMNodeUniversalProperty.new()
roundness.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
roundness.set_default_value(0.1)
roundness.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
roundness.slot_name = "Roundness"
roundness.value_step = 0.01
roundness.value_range = Vector2(0, 0.5)
register_output_property(out_bricks_pattern)
register_output_property(out_random_color)
register_output_property(out_position_x)
register_output_property(out_position_y)
register_output_property(out_brick_uv)
register_output_property(out_corner_uv)
register_output_property(out_direction)
register_input_property(mortar)
register_input_property(bevel)
register_input_property(roundness)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture_universal(out_bricks_pattern)
mm_graph_node.add_slot_texture_universal(out_random_color)
mm_graph_node.add_slot_texture_universal(out_position_x)
mm_graph_node.add_slot_texture_universal(out_position_y)
mm_graph_node.add_slot_texture_universal(out_brick_uv)
mm_graph_node.add_slot_texture_universal(out_corner_uv)
mm_graph_node.add_slot_texture_universal(out_direction)
mm_graph_node.add_slot_enum("get_type", "set_type", "Type", [ "Running Bond", "Running Bond (2)", "HerringBone", "Basket Weave", "Spanish Bond" ])
mm_graph_node.add_slot_int("get_repeat", "set_repeat", "Repeat")
mm_graph_node.add_slot_vector2("get_row_col", "set_row_col", "Row, Col")#, Vector2(1, 32))#, Vector2(0, 32))
mm_graph_node.add_slot_float("get_offset", "set_offset", "Offset")
mm_graph_node.add_slot_float_universal(mortar)
mm_graph_node.add_slot_float_universal(bevel)
mm_graph_node.add_slot_float_universal(roundness)
mm_graph_node.add_slot_float("get_corner", "set_corner", "Corner")
func _render(material) -> void:
var bricks_pattern : Image = Image.new()
var random_color : Image = Image.new()
var position_x : Image = Image.new()
var position_y : Image = Image.new()
var brick_uv : Image = Image.new()
var corner_uv : Image = Image.new()
var direction : Image = Image.new()
bricks_pattern.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
random_color.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
position_x.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
position_y.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
brick_uv.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
corner_uv.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
direction.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
bricks_pattern.lock()
random_color.lock()
position_x.lock()
position_y.lock()
brick_uv.lock()
corner_uv.lock()
direction.lock()
var w : float = material.image_size.x
var h : float = material.image_size.y
var pseed : float = randf() + randi()
for x in range(material.image_size.x):
for y in range(material.image_size.y):
var uv : Vector2 = Vector2(x / w, y / h)
#vec4 $(name_uv)_rect = bricks_$pattern($uv, vec2($columns, $rows), $repeat, $row_offset);
var brick_rect : Color = Color()
#"Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond"
if type == 0:
brick_rect = Patterns.bricks_rb(uv, row_col, repeat, offset)
elif type == 1:
brick_rect = Patterns.bricks_rb2(uv, row_col, repeat, offset)
elif type == 2:
brick_rect = Patterns.bricks_hb(uv, row_col, repeat, offset)
elif type == 3:
brick_rect = Patterns.bricks_bw(uv, row_col, repeat, offset)
elif type == 4:
brick_rect = Patterns.bricks_sb(uv, row_col, repeat, offset)
#vec4 $(name_uv) = brick($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $round*$round_map($uv), max(0.001, $bevel*$bevel_map($uv)));
var brick : Color = Patterns.brick(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar.get_value(uv), roundness.get_value(uv), max(0.001, bevel.get_value(uv)))
#Bricks pattern (float) - A greyscale image that shows the bricks pattern
#$(name_uv).x
var bricks_pattern_col : Color = Color(brick.r, brick.r, brick.r, 1)
#Random color (rgb) - A random color for each brick
#brick_random_color($(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed))
var brc : Vector3 = Patterns.brick_random_color(Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), pseed)
var random_color_col : Color = Color(brc.x, brc.y, brc.z, 1)
#Position.x (float) - The position of each brick along the X axis",
#$(name_uv).y
var position_x_col : Color = Color(brick.g, brick.g, brick.g, 1)
#Position.y (float) - The position of each brick along the Y axis
#$(name_uv).z
var position_y_col : Color = Color(brick.b, brick.b, brick.b, 1)
#Brick UV (rgb) - An UV map output for each brick, to be connected to the Map input of a CustomUV node
#brick_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed))
var buv : Vector3 = Patterns.brick_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), pseed)
var brick_uv_col : Color = Color(buv.x, buv.y, buv.z, 1)
#Corner UV (rgb) - An UV map output for each brick corner, to be connected to the Map input of a CustomUV node
#brick_corner_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $corner, float($seed))
var bcuv : Vector3 = Patterns.brick_corner_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar.get_value(uv), corner, pseed)
var corner_uv_col : Color = Color(bcuv.x, bcuv.y, bcuv.z, 1)
#Direction (float) - The direction of each brick (white: horizontal, black: vertical)
#0.5*(sign($(name_uv)_rect.z-$(name_uv)_rect.x-$(name_uv)_rect.w+$(name_uv)_rect.y)+1.0)
var d : float = 0.5 * (sign(brick_rect.b - brick_rect.r - brick_rect.a + brick_rect.g) + 1.0)
var direction_col : Color = Color(d, d, d, 1)
bricks_pattern.set_pixel(x, y, bricks_pattern_col)
random_color.set_pixel(x, y, random_color_col)
position_x.set_pixel(x, y, position_x_col)
position_y.set_pixel(x, y, position_y_col)
brick_uv.set_pixel(x, y, brick_uv_col)
corner_uv.set_pixel(x, y, corner_uv_col)
direction.set_pixel(x, y, direction_col)
bricks_pattern.unlock()
random_color.unlock()
position_x.unlock()
position_y.unlock()
brick_uv.unlock()
corner_uv.unlock()
direction.unlock()
out_bricks_pattern.set_value(bricks_pattern)
out_random_color.set_value(random_color)
out_position_x.set_value(position_x)
out_position_y.set_value(position_y)
out_brick_uv.set_value(brick_uv)
out_corner_uv.set_value(corner_uv)
out_direction.set_value(direction)
func get_value_for(uv : Vector2, pseed : int) -> Color:
return Color()
#type
func get_type() -> int:
return type
func set_type(val : int) -> void:
type = val
set_dirty(true)
#repeat
func get_repeat() -> int:
return repeat
func set_repeat(val : int) -> void:
repeat = val
set_dirty(true)
#row_col
func get_row_col() -> Vector2:
return row_col
func set_row_col(val : Vector2) -> void:
row_col = val
set_dirty(true)
#offset
func get_offset() -> float:
return offset
func set_offset(val : float) -> void:
offset = val
set_dirty(true)
#corner
func get_corner() -> float:
return corner
func set_corner(val : float) -> void:
corner = val
set_dirty(true)