mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-18 01:06:47 +01:00
Fill_to_position, fill_to_size, and fill_to_uv nodes for mat_maker_gd.
This commit is contained in:
parent
1d27ddd159
commit
170f50c31f
@ -511,12 +511,25 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
|||||||
# }
|
# }
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
static func flood_fill_preprocess(uv : Vector2, c : float, s : float) -> Color:
|
||||||
|
if (c > 0.5):
|
||||||
|
return Color(0, 0, 0, 0)
|
||||||
|
else:
|
||||||
|
uv = Commons.floorv2(uv * s) / s
|
||||||
|
var f : float = 1.0 / s
|
||||||
|
return Color(uv.x, uv.y, f, f)
|
||||||
|
|
||||||
#vec3 fill_to_uv_stretch(vec2 coord, vec4 bb, float seed) {
|
#vec3 fill_to_uv_stretch(vec2 coord, vec4 bb, float seed) {
|
||||||
# vec2 uv_islands = fract(coord-bb.xy)/bb.zw;
|
# vec2 uv_islands = fract(coord-bb.xy)/bb.zw;
|
||||||
# float random_value = rand(vec2(seed)+bb.xy+bb.zw);
|
# float random_value = rand(vec2(seed)+bb.xy+bb.zw);
|
||||||
# return vec3(uv_islands, random_value);
|
# return vec3(uv_islands, random_value);
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
static func fill_to_uv_stretch(coord : Vector2, bb : Color, pseed : float) -> Vector3:
|
||||||
|
var uv_islands : Vector2 = Commons.fractv2(coord - Vector2(bb.r, bb.g)) / Vector2(bb.b, bb.a)
|
||||||
|
var random_value : float = Commons.rand(Vector2(pseed, pseed) + Vector2(bb.r, bb.g) + Vector2(bb.b, bb.a))
|
||||||
|
return Vector3(uv_islands.x, uv_islands.y, random_value)
|
||||||
|
|
||||||
#vec3 fill_to_uv_square(vec2 coord, vec4 bb, float seed) {
|
#vec3 fill_to_uv_square(vec2 coord, vec4 bb, float seed) {
|
||||||
# vec2 uv_islands;
|
# vec2 uv_islands;
|
||||||
#
|
#
|
||||||
@ -531,3 +544,16 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
|||||||
# float random_value = rand(vec2(seed)+bb.xy+bb.zw);
|
# float random_value = rand(vec2(seed)+bb.xy+bb.zw);
|
||||||
# return vec3(uv_islands, random_value);
|
# return vec3(uv_islands, random_value);
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
static func fill_to_uv_square(coord : Vector2, bb : Color, pseed : float) -> Vector3:
|
||||||
|
var uv_islands : Vector2 = Vector2()
|
||||||
|
|
||||||
|
if (bb.b > bb.a):
|
||||||
|
var adjusted_coord : Vector2 = coord + Vector2(0.0, (bb.b - bb.a) / 2.0);
|
||||||
|
uv_islands = Commons.fractv2(adjusted_coord - Vector2(bb.r, bb.g)) / Vector2(bb.b, bb.b)
|
||||||
|
else:
|
||||||
|
var adjusted_coord : Vector2 = coord + Vector2((bb.a - bb.b) / 2.0, 0.0);
|
||||||
|
uv_islands = Commons.fractv2(adjusted_coord - Vector2(bb.r, bb.g)) / Vector2(bb.a, bb.a)
|
||||||
|
|
||||||
|
var random_value : float = Commons.rand(Vector2(pseed, pseed) + Vector2(bb.r, bb.g) + Vector2(bb.b, bb.a))
|
||||||
|
return Vector3(uv_islands.x, uv_islands.y, random_value)
|
||||||
|
68
game/addons/mat_maker_gd/nodes/filter/fill_to_position.gd
Normal file
68
game/addons/mat_maker_gd/nodes/filter/fill_to_position.gd
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
tool
|
||||||
|
extends MMNode
|
||||||
|
|
||||||
|
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||||
|
var Transforms = preload("res://addons/mat_maker_gd/nodes/common/transforms.gd")
|
||||||
|
|
||||||
|
export(Resource) var image : Resource
|
||||||
|
export(Resource) var input : Resource
|
||||||
|
export(int, "X,Y,Radial") var axis : int = 2
|
||||||
|
|
||||||
|
func _init_properties():
|
||||||
|
if !input:
|
||||||
|
input = MMNodeUniversalProperty.new()
|
||||||
|
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR
|
||||||
|
input.set_default_value(Color(0, 0, 0, 1))
|
||||||
|
|
||||||
|
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||||
|
input.slot_name = ">>> Input "
|
||||||
|
|
||||||
|
if !image:
|
||||||
|
image = MMNodeUniversalProperty.new()
|
||||||
|
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
|
||||||
|
|
||||||
|
#image.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
|
||||||
|
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
|
||||||
|
#image.force_override = true
|
||||||
|
|
||||||
|
register_input_property(input)
|
||||||
|
register_output_property(image)
|
||||||
|
|
||||||
|
func _register_methods(mm_graph_node) -> void:
|
||||||
|
mm_graph_node.add_slot_label_universal(input)
|
||||||
|
mm_graph_node.add_slot_texture_universal(image)
|
||||||
|
mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "X", "Y", "Radial" ])
|
||||||
|
|
||||||
|
func _render(material) -> void:
|
||||||
|
var img : Image = render_image(material)
|
||||||
|
|
||||||
|
image.set_value(img)
|
||||||
|
|
||||||
|
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||||
|
var c : Color = input.get_value(uv)
|
||||||
|
#vec2 $(name_uv)_c = fract($in($uv).xy+0.5*$in($uv).zw);
|
||||||
|
var cnv : Vector2 = Commons.fractv2(Vector2(c.r, c.g) + 0.5 * Vector2(c.b, c.a))
|
||||||
|
|
||||||
|
#X, $(name_uv)_c.x
|
||||||
|
#Y, $(name_uv)_c.y
|
||||||
|
#Radial, length($(name_uv)_c-vec2(0.5))
|
||||||
|
|
||||||
|
if axis == 0:
|
||||||
|
return Color(cnv.x, cnv.x, cnv.x, 1)
|
||||||
|
elif axis == 1:
|
||||||
|
return Color(cnv.y, cnv.y, cnv.y, 1)
|
||||||
|
elif axis == 2:
|
||||||
|
var f : float = (cnv - Vector2(0.5, 0.5)).length()
|
||||||
|
|
||||||
|
return Color(f, f, f, 1)
|
||||||
|
|
||||||
|
return Color(0, 0, 0, 1)
|
||||||
|
|
||||||
|
#axis
|
||||||
|
func get_axis() -> int:
|
||||||
|
return axis
|
||||||
|
|
||||||
|
func set_axis(val : int) -> void:
|
||||||
|
axis = val
|
||||||
|
|
||||||
|
set_dirty(true)
|
70
game/addons/mat_maker_gd/nodes/filter/fill_to_size.gd
Normal file
70
game/addons/mat_maker_gd/nodes/filter/fill_to_size.gd
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
tool
|
||||||
|
extends MMNode
|
||||||
|
|
||||||
|
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||||
|
var Fills = preload("res://addons/mat_maker_gd/nodes/common/fills.gd")
|
||||||
|
|
||||||
|
export(Resource) var image : Resource
|
||||||
|
export(Resource) var input : Resource
|
||||||
|
export(int, "Area,Width,Height,Max(W,H)") var formula : int = 0
|
||||||
|
|
||||||
|
func _init_properties():
|
||||||
|
if !input:
|
||||||
|
input = MMNodeUniversalProperty.new()
|
||||||
|
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR
|
||||||
|
input.set_default_value(Color(0, 0, 0, 1))
|
||||||
|
|
||||||
|
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||||
|
input.slot_name = ">>> Input "
|
||||||
|
|
||||||
|
if !image:
|
||||||
|
image = MMNodeUniversalProperty.new()
|
||||||
|
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
|
||||||
|
|
||||||
|
#image.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
|
||||||
|
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
|
||||||
|
#image.force_override = true
|
||||||
|
|
||||||
|
register_input_property(input)
|
||||||
|
register_output_property(image)
|
||||||
|
|
||||||
|
func _register_methods(mm_graph_node) -> void:
|
||||||
|
mm_graph_node.add_slot_label_universal(input)
|
||||||
|
mm_graph_node.add_slot_texture_universal(image)
|
||||||
|
mm_graph_node.add_slot_enum("get_formula", "set_formula", "Formula", [ "Area", "Width", "Height", "Max(W,H)" ])
|
||||||
|
|
||||||
|
func _render(material) -> void:
|
||||||
|
var img : Image = render_image(material)
|
||||||
|
|
||||||
|
image.set_value(img)
|
||||||
|
|
||||||
|
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||||
|
#vec4 $(name_uv)_bb = $in($uv);
|
||||||
|
var c : Color = input.get_value(uv)
|
||||||
|
|
||||||
|
var f : float = 0
|
||||||
|
|
||||||
|
#"Area" sqrt($(name_uv)_bb.z*$(name_uv)_bb.w)
|
||||||
|
#"Width" $(name_uv)_bb.z
|
||||||
|
#"Height" $(name_uv)_bb.w
|
||||||
|
#"max(W, H)" max($(name_uv)_bb.z, $(name_uv)_bb.w)
|
||||||
|
|
||||||
|
if formula == 0:
|
||||||
|
f = sqrt(c.b * c.a)
|
||||||
|
elif formula == 1:
|
||||||
|
f = c.b
|
||||||
|
elif formula == 2:
|
||||||
|
f = c.a
|
||||||
|
elif formula == 3:
|
||||||
|
f = max(c.b, c.a)
|
||||||
|
|
||||||
|
return Color(f, f, f, 1)
|
||||||
|
|
||||||
|
#formula
|
||||||
|
func get_formula() -> int:
|
||||||
|
return formula
|
||||||
|
|
||||||
|
func set_formula(val : int) -> void:
|
||||||
|
formula = val
|
||||||
|
|
||||||
|
set_dirty(true)
|
62
game/addons/mat_maker_gd/nodes/filter/fill_to_uv.gd
Normal file
62
game/addons/mat_maker_gd/nodes/filter/fill_to_uv.gd
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
tool
|
||||||
|
extends MMNode
|
||||||
|
|
||||||
|
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||||
|
var Fills = preload("res://addons/mat_maker_gd/nodes/common/fills.gd")
|
||||||
|
|
||||||
|
export(Resource) var image : Resource
|
||||||
|
export(Resource) var input : Resource
|
||||||
|
export(int, "Stretch,Square") var mode : int = 0
|
||||||
|
|
||||||
|
func _init_properties():
|
||||||
|
if !input:
|
||||||
|
input = MMNodeUniversalProperty.new()
|
||||||
|
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR
|
||||||
|
input.set_default_value(Color(0, 0, 0, 1))
|
||||||
|
|
||||||
|
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||||
|
input.slot_name = ">>> Input "
|
||||||
|
|
||||||
|
if !image:
|
||||||
|
image = MMNodeUniversalProperty.new()
|
||||||
|
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
|
||||||
|
|
||||||
|
#image.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
|
||||||
|
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
|
||||||
|
#image.force_override = true
|
||||||
|
|
||||||
|
register_input_property(input)
|
||||||
|
register_output_property(image)
|
||||||
|
|
||||||
|
func _register_methods(mm_graph_node) -> void:
|
||||||
|
mm_graph_node.add_slot_label_universal(input)
|
||||||
|
mm_graph_node.add_slot_texture_universal(image)
|
||||||
|
mm_graph_node.add_slot_enum("get_mode", "set_mode", "Mode", [ "Stretch", "Square" ])
|
||||||
|
|
||||||
|
func _render(material) -> void:
|
||||||
|
var img : Image = render_image(material)
|
||||||
|
|
||||||
|
image.set_value(img)
|
||||||
|
|
||||||
|
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||||
|
#vec4 $(name_uv)_bb = $in($uv);
|
||||||
|
var c : Color = input.get_value(uv)
|
||||||
|
|
||||||
|
#fill_to_uv_$mode($uv, $(name_uv)_bb, float($seed))
|
||||||
|
var r : Vector3 = Vector3()
|
||||||
|
|
||||||
|
if mode == 0:
|
||||||
|
r = Fills.fill_to_uv_stretch(uv, c, float(pseed))
|
||||||
|
elif mode == 1:
|
||||||
|
r = Fills.fill_to_uv_square(uv, c, float(pseed))
|
||||||
|
|
||||||
|
return Color(r.x, r.y, r.z, 1)
|
||||||
|
|
||||||
|
#mode
|
||||||
|
func get_mode() -> int:
|
||||||
|
return mode
|
||||||
|
|
||||||
|
func set_mode(val : int) -> void:
|
||||||
|
mode = val
|
||||||
|
|
||||||
|
set_dirty(true)
|
Loading…
Reference in New Issue
Block a user