mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Greyscale quantize and tonality nodes.
This commit is contained in:
parent
f17de5a15d
commit
1d27ddd159
@ -49,7 +49,7 @@ margin_bottom = 600.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="AddPopup" parent="Popups" instance=ExtResource( 2 )]
|
||||
type_folders = PoolStringArray( "res://addons/mat_maker_gd/nodes/uniform", "res://addons/mat_maker_gd/nodes/noise", "res://addons/mat_maker_gd/nodes/filter", "res://addons/mat_maker_gd/nodes/gradient", "res://addons/mat_maker_gd/nodes/pattern", "res://addons/mat_maker_gd/nodes/sdf2d", "res://addons/mat_maker_gd/nodes/sdf3d", "res://addons/mat_maker_gd/nodes/simple", "res://addons/mat_maker_gd/nodes/other" )
|
||||
type_folders = PoolStringArray( "res://addons/mat_maker_gd/nodes/uniform", "res://addons/mat_maker_gd/nodes/noise", "res://addons/mat_maker_gd/nodes/filter", "res://addons/mat_maker_gd/nodes/gradient", "res://addons/mat_maker_gd/nodes/pattern", "res://addons/mat_maker_gd/nodes/sdf2d", "res://addons/mat_maker_gd/nodes/sdf3d", "res://addons/mat_maker_gd/nodes/transform", "res://addons/mat_maker_gd/nodes/simple", "res://addons/mat_maker_gd/nodes/other" )
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/PanelContainer/HBoxContainer/AddButton" to="." method="_on_AddButton_pressed"]
|
||||
[connection signal="ok_pressed" from="Popups/AddPopup" to="." method="_on_AddPopup_ok_pressed"]
|
||||
|
@ -113,6 +113,15 @@ static func floorv2(a : Vector2) -> Vector2:
|
||||
|
||||
return v
|
||||
|
||||
static func floorv3(a : Vector3) -> Vector3:
|
||||
var v : Vector3 = Vector3()
|
||||
|
||||
v.x = floor(a.x)
|
||||
v.y = floor(a.y)
|
||||
v.z = floor(a.z)
|
||||
|
||||
return v
|
||||
|
||||
static func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2:
|
||||
var v : Vector2 = Vector2()
|
||||
|
||||
|
@ -82,6 +82,50 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
#tiler.mmg
|
||||
#Tiles several occurences of an input image while adding randomness.
|
||||
|
||||
#vec4 $(name_uv)_rch = tiler_$(name)($uv, vec2($tx, $ty), int($overlap), vec2(float($seed)));
|
||||
|
||||
#instance
|
||||
#vec4 tiler_$(name)(vec2 uv, vec2 tile, int overlap, vec2 _seed) {\n\t
|
||||
# float c = 0.0;\n\t
|
||||
# vec3 rc = vec3(0.0);\n\t
|
||||
# vec3 rc1;\n\t
|
||||
# for (int dx = -overlap; dx <= overlap; ++dx) {\n\t\t
|
||||
# for (int dy = -overlap; dy <= overlap; ++dy) {\n\t\t\t
|
||||
# vec2 pos = fract((floor(uv*tile)+vec2(float(dx), float(dy))+vec2(0.5))/tile-vec2(0.5));\n\t\t\t
|
||||
# vec2 seed = rand2(pos+_seed);\n\t\t\trc1 = rand3(seed);\n\t\t\t
|
||||
# pos = fract(pos+vec2($fixed_offset/tile.x, 0.0)*floor(mod(pos.y*tile.y, 2.0))+$offset*seed/tile);\n\t\t\t
|
||||
# float mask = $mask(fract(pos+vec2(0.5)));\n\t\t\t
|
||||
#
|
||||
# if (mask > 0.01) {\n\t\t\t\t
|
||||
# vec2 pv = fract(uv - pos)-vec2(0.5);\n\t\t\t\t
|
||||
# seed = rand2(seed);\n\t\t\t\t
|
||||
# float angle = (seed.x * 2.0 - 1.0) * $rotate * 0.01745329251;\n\t\t\t\t
|
||||
# float ca = cos(angle);\n\t\t\t\t
|
||||
# float sa = sin(angle);\n\t\t\t\t
|
||||
# pv = vec2(ca*pv.x+sa*pv.y, -sa*pv.x+ca*pv.y);\n\t\t\t\t
|
||||
# pv *= (seed.y-0.5)*2.0*$scale+1.0;\n\t\t\t\t
|
||||
# pv /= vec2($scale_x, $scale_y);\n\t\t\t\t
|
||||
# pv += vec2(0.5);\n\t\t\t\t
|
||||
# seed = rand2(seed);\n\t\t\t\t
|
||||
# vec2 clamped_pv = clamp(pv, vec2(0.0), vec2(1.0));\n\t\t\t\t
|
||||
# if (pv.x != clamped_pv.x || pv.y != clamped_pv.y) {\n\t\t\t\t\t
|
||||
# continue;\n\t\t\t\t
|
||||
# }\n\t\t\t\t
|
||||
#
|
||||
# $select_inputs\n\t\t\t\t
|
||||
#
|
||||
# float c1 = $in.variation(pv, $variations ? seed.x : 0.0)*mask*(1.0-$value*seed.x);\n\t\t\t\t
|
||||
# c = max(c, c1);\n\t\t\t\t
|
||||
# rc = mix(rc, rc1, step(c, c1));\n\t\t\t
|
||||
# }\n\t\t
|
||||
# }\n\t
|
||||
# }\n\t
|
||||
#
|
||||
# return vec4(rc, c);\n
|
||||
#}
|
||||
|
||||
|
||||
|
||||
# "code": "vec4 $(name_uv)_rch = tiler_$(name)($uv, vec2($tx, $ty), int($overlap), vec2(float($seed)));",
|
||||
# "inputs": [
|
||||
# {
|
||||
|
66
game/addons/mat_maker_gd/nodes/filter/greyscale.gd
Normal file
66
game/addons/mat_maker_gd/nodes/filter/greyscale.gd
Normal file
@ -0,0 +1,66 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
var Filter = preload("res://addons/mat_maker_gd/nodes/common/filter.gd")
|
||||
|
||||
export(Resource) var image : Resource
|
||||
export(Resource) var input : Resource
|
||||
export(int, "Lightness,Average,Luminosity,Min,Max") var type : 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 = ">>> Input1 "
|
||||
|
||||
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_type", "set_type", "Type", [ "Lightness", "Average", "Luminosity", "Min", "Max" ])
|
||||
|
||||
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)
|
||||
|
||||
var f : float = 0
|
||||
|
||||
if type == 0:
|
||||
f = Filter.grayscale_lightness(Vector3(c.r, c.g, c.b))
|
||||
elif type == 1:
|
||||
f = Filter.grayscale_average(Vector3(c.r, c.g, c.b))
|
||||
elif type == 2:
|
||||
f = Filter.grayscale_luminosity(Vector3(c.r, c.g, c.b))
|
||||
elif type == 3:
|
||||
f = Filter.grayscale_min(Vector3(c.r, c.g, c.b))
|
||||
elif type == 4:
|
||||
f = Filter.grayscale_max(Vector3(c.r, c.g, c.b))
|
||||
|
||||
return Color(f, f, f, c.a)
|
||||
|
||||
#type
|
||||
func get_type() -> int:
|
||||
return type
|
||||
|
||||
func set_type(val : int) -> void:
|
||||
type = val
|
||||
|
||||
set_dirty(true)
|
56
game/addons/mat_maker_gd/nodes/filter/quantize.gd
Normal file
56
game/addons/mat_maker_gd/nodes/filter/quantize.gd
Normal file
@ -0,0 +1,56 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
var Filter = preload("res://addons/mat_maker_gd/nodes/common/filter.gd")
|
||||
|
||||
export(Resource) var image : Resource
|
||||
export(Resource) var input : Resource
|
||||
export(int) var steps : int = 4
|
||||
|
||||
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_int("get_steps", "set_steps", "Steps")
|
||||
|
||||
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)
|
||||
|
||||
#vec4(floor($in($uv).rgb*$steps)/$steps, $in($uv).a)
|
||||
var v : Vector3 = Commons.floorv3(Vector3(c.r, c.g, c.b) * steps) / float(steps)
|
||||
|
||||
return Color(v.x, v.y, v.z, c.a)
|
||||
|
||||
#steps
|
||||
func get_steps() -> int:
|
||||
return steps
|
||||
|
||||
func set_steps(val : int) -> void:
|
||||
steps = val
|
||||
|
||||
set_dirty(true)
|
50
game/addons/mat_maker_gd/nodes/filter/tonality.gd
Normal file
50
game/addons/mat_maker_gd/nodes/filter/tonality.gd
Normal file
@ -0,0 +1,50 @@
|
||||
tool
|
||||
extends "res://addons/mat_maker_gd/nodes/bases/curve_base.gd"
|
||||
|
||||
var Curves = preload("res://addons/mat_maker_gd/nodes/common/curves.gd")
|
||||
|
||||
export(Resource) var image : Resource
|
||||
export(Resource) var input : Resource
|
||||
|
||||
func _init():
|
||||
init_points_01()
|
||||
|
||||
func _init_properties():
|
||||
if !input:
|
||||
input = MMNodeUniversalProperty.new()
|
||||
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
|
||||
input.set_default_value(0)
|
||||
|
||||
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_curve()
|
||||
|
||||
func _render(material) -> void:
|
||||
var img : Image = render_image(material)
|
||||
|
||||
image.set_value(img)
|
||||
|
||||
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||
var f : float = input.get_value(uv)
|
||||
|
||||
var cf : float = Curves.curve(f, points)
|
||||
|
||||
return Color(cf, cf, cf, 1)
|
||||
|
||||
func _curve_changed() -> void:
|
||||
set_dirty(true)
|
Loading…
Reference in New Issue
Block a user