mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-18 01:06:47 +01:00
adjust_hsv node.
This commit is contained in:
parent
583415d5fb
commit
77d2e64fe1
@ -147,7 +147,7 @@ static func absv2(v : Vector2) -> Vector2:
|
||||
static func absv3(v : Vector3) -> Vector3:
|
||||
v.x = abs(v.x)
|
||||
v.y = abs(v.y)
|
||||
v.z = abs(v.y)
|
||||
v.z = abs(v.z)
|
||||
|
||||
return v
|
||||
|
||||
|
@ -9,16 +9,6 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
|
||||
#main node methods: adjust_hsv, brightness_contrast
|
||||
|
||||
#vec3 rgb_to_hsv(vec3 c) {
|
||||
# vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
# vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
|
||||
# vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
|
||||
#
|
||||
# float d = q.x - min(q.w, q.y);
|
||||
# float e = 1.0e-10;
|
||||
# return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
#}
|
||||
|
||||
#----------------------
|
||||
#colorize.mmg
|
||||
#Remaps a greyscale image to a custom gradient
|
||||
@ -4188,6 +4178,17 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
# }
|
||||
# ],
|
||||
|
||||
#vec3 rgb_to_hsv(vec3 c) {
|
||||
# vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
# vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
|
||||
# vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
|
||||
#
|
||||
# float d = q.x - min(q.w, q.y);
|
||||
# float e = 1.0e-10;
|
||||
# return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
#}
|
||||
|
||||
|
||||
static func rgb_to_hsv(c : Vector3) -> Vector3:
|
||||
var K : Color = Color(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
|
||||
@ -4240,11 +4241,11 @@ static func hsv_to_rgb(c : Vector3) -> Vector3:
|
||||
static func adjust_hsv(color : Color, hue : float, saturation : float, value : float) -> Color:
|
||||
var hsv : Vector3 = rgb_to_hsv(Vector3(color.r, color.g, color.b));
|
||||
|
||||
var x : float = Commons.fract(hsv.x + hue)
|
||||
var y : float = clamp(hsv.y * saturation, 0.0, 1.0)
|
||||
var z : float = clamp(hsv.z * value, 0.0, 1.0)
|
||||
hsv.x += hue
|
||||
hsv.y = clamp(hsv.y * saturation, 0.0, 1.0)
|
||||
hsv.z = clamp(hsv.z * value, 0.0, 1.0)
|
||||
|
||||
var h : Vector3 = hsv_to_rgb(Vector3(x, y, z))
|
||||
var h : Vector3 = hsv_to_rgb(hsv)
|
||||
|
||||
return Color(h.x, h.y, h.z, color.a);
|
||||
|
||||
|
75
game/addons/mat_maker_gd/nodes/filter/adjust_hsv.gd
Normal file
75
game/addons/mat_maker_gd/nodes/filter/adjust_hsv.gd
Normal file
@ -0,0 +1,75 @@
|
||||
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(float) var hue : float = 0
|
||||
export(float) var saturation : float = 1
|
||||
export(float) var value : float = 1
|
||||
|
||||
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_float("get_hue", "set_hue", "Hue", 0.01)
|
||||
mm_graph_node.add_slot_float("get_saturation", "set_saturation", "Saturation", 0.01)
|
||||
mm_graph_node.add_slot_float("get_value", "set_value", "Value", 0.01)
|
||||
|
||||
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)
|
||||
|
||||
return Filter.adjust_hsv(c, hue, saturation, value)
|
||||
|
||||
#hue
|
||||
func get_hue() -> float:
|
||||
return hue
|
||||
|
||||
func set_hue(val : float) -> void:
|
||||
hue = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#saturation
|
||||
func get_saturation() -> float:
|
||||
return saturation
|
||||
|
||||
func set_saturation(val : float) -> void:
|
||||
saturation = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#value
|
||||
func get_value() -> float:
|
||||
return value
|
||||
|
||||
func set_value(val : float) -> void:
|
||||
value = val
|
||||
|
||||
set_dirty(true)
|
Loading…
Reference in New Issue
Block a user