diff --git a/game/addons/mat_maker_gd/nodes/common/commons.gd b/game/addons/mat_maker_gd/nodes/common/commons.gd index 02f7e349..4080f5ef 100644 --- a/game/addons/mat_maker_gd/nodes/common/commons.gd +++ b/game/addons/mat_maker_gd/nodes/common/commons.gd @@ -1199,3 +1199,51 @@ static func shape_rays(uv : Vector2, sides : float, size : float, edge : float) var angle : float = modf(atan(uv.y / uv.x) + 3.14159265359, slice) / slice return clamp(min((size - angle) / edge, angle / edge), 0.0, 1.0); + +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 = 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) + + var h : Vector3 = hsv_to_rgb(Vector3(x, y, z)) + + return Color(h.x, h.y, h.z, color.a); + +static func brightness_contrast(color : Color, brightness : float, contrast : float) -> Color: + var bv : Vector3 = Vector3(brightness, brightness, brightness) + var cvv : Vector3 = Vector3(color.r * contrast, color.g * contrast, color.b * contrast) + + var cv : Vector3 = cvv + bv + Vector3(0.5, 0.5, 0.5) - (Vector3(contrast, contrast, contrast) * 0.5) + + var v : Vector3 = clampv3(cv, Vector3(), Vector3(1, 1, 1)) + + return Color(v.x, v.y, v.z, 1); + + +static func grayscale_min(c : Vector3) -> float: + return min(c.x, min(c.y, c.z)); + +static func grayscale_max(c : Vector3) -> float: + return max(c.x, max(c.y, c.z)); + +static func grayscale_lightness(c : Vector3) -> float: + return 0.5*(max(c.x, max(c.y, c.z)) + min(c.x, min(c.y, c.z))); + +static func grayscale_average(c : Vector3) -> float: + return 0.333333333333*(c.x + c.y + c.z); + +static func grayscale_luminosity(c : Vector3) -> float: + return 0.21 * c.x + 0.72 * c.y + 0.07 * c.z; + +static func sinewave(uv : Vector2, amplitude : float, frequency : float, phase : float) -> Color: + var f : float = 1.0- abs(2.0 * (uv.y-0.5) - amplitude * sin((frequency* uv.x + phase) * 6.28318530718)); + + return Color(f, f, f, 1) + + +static func noise_color(uv : Vector2, pseed : int) -> Color: + var v : Vector3 = color_dots(((uv)), 1.0/512.000000000, pseed); + + return Color(v.x, v.y, v.z, 1) diff --git a/game/addons/mat_maker_gd/nodes/filter/filter.gd b/game/addons/mat_maker_gd/nodes/filter/filter.gd index a9c8c9b6..a922c8c6 100644 --- a/game/addons/mat_maker_gd/nodes/filter/filter.gd +++ b/game/addons/mat_maker_gd/nodes/filter/filter.gd @@ -59,29 +59,14 @@ var p_o91644_brightness = 0.000000000; var p_o91644_contrast = 1.000000000; func brightness_contrast(color : Color) -> Color: - var bv : Vector3 = Vector3(p_o91644_brightness, p_o91644_brightness, p_o91644_brightness) - var cvv : Vector3 = Vector3(color.r * p_o91644_contrast, color.g * p_o91644_contrast, color.b * p_o91644_contrast) - - var cv : Vector3 = cvv + bv + Vector3(0.5, 0.5, 0.5) - (Vector3(p_o91644_contrast, p_o91644_contrast, p_o91644_contrast) * 0.5) - - var v : Vector3 = Commons.clampv3(cv, Vector3(), Vector3(1, 1, 1)) - - return Color(v.x, v.y, v.z, 1); + return Commons.brightness_contrast(color, p_o91644_brightness, p_o91644_contrast); var p_o102649_hue = 0.000000000; var p_o102649_saturation = 1.000000000; var p_o102649_value = 1.000000000; func adjust_hsv(color : Color) -> Color: - var hsv : Vector3 = Commons.rgb_to_hsv(Vector3(color.r, color.g, color.b)); - - var x : float = Commons.fract(hsv.x + p_o102649_hue) - var y : float = clamp(hsv.y * p_o102649_saturation, 0.0, 1.0) - var z : float = clamp(hsv.z * p_o102649_value, 0.0, 1.0) - - var h : Vector3 = Commons.hsv_to_rgb(Vector3(x, y, z)) - - return Color(h.x, h.y, h.z, color.a); + return Commons.adjust_hsv(color, p_o102649_hue, p_o102649_saturation, p_o102649_value) func reffg(): return false diff --git a/game/addons/mat_maker_gd/nodes/filter/grayscale.gd b/game/addons/mat_maker_gd/nodes/filter/grayscale.gd index cc672125..9b7b8a6b 100644 --- a/game/addons/mat_maker_gd/nodes/filter/grayscale.gd +++ b/game/addons/mat_maker_gd/nodes/filter/grayscale.gd @@ -40,7 +40,7 @@ func gen() -> void: var f : float = Commons.shape_circle(v, 3, 1.0 * 1.0, 1.0) - f = gs_luminosity(Vector3(f, f, f)); + f = Commons.grayscale_luminosity(Vector3(f, f, f)); var c : Color = Color(f, f, f, 1) @@ -57,21 +57,6 @@ func gen() -> void: tex.create_from_image(image) texture = tex -func gs_min(c : Vector3) -> float: - return min(c.x, min(c.y, c.z)); - -func gs_max(c : Vector3) -> float: - return max(c.x, max(c.y, c.z)); - -func gs_lightness(c : Vector3) -> float: - return 0.5*(max(c.x, max(c.y, c.z)) + min(c.x, min(c.y, c.z))); - -func gs_average(c : Vector3) -> float: - return 0.333333333333*(c.x + c.y + c.z); - -func gs_luminosity(c : Vector3) -> float: - return 0.21 * c.x + 0.72 * c.y + 0.07 * c.z; - func reffg(): return false diff --git a/game/addons/mat_maker_gd/nodes/noise/noise.gd b/game/addons/mat_maker_gd/nodes/noise/noise.gd index 7d6dc8c5..d243b03a 100644 --- a/game/addons/mat_maker_gd/nodes/noise/noise.gd +++ b/game/addons/mat_maker_gd/nodes/noise/noise.gd @@ -57,9 +57,7 @@ var p_o7136_frequency = 2.000000000; var p_o7136_phase = 0.000000000; func sinewave(uv : Vector2) -> Color: - var f : float = 1.0- abs(2.0 * (uv.y-0.5) - p_o7136_amplitude * sin((p_o7136_frequency* uv.x + p_o7136_phase) * 6.28318530718)); - - return Color(f, f, f, 1) + return Commons.sinewave(uv, p_o7136_amplitude, p_o7136_frequency, p_o7136_phase) func reffg(): return false diff --git a/game/addons/mat_maker_gd/nodes/noise/noise_color.gd b/game/addons/mat_maker_gd/nodes/noise/noise_color.gd index 56c6ad6b..a8547fae 100644 --- a/game/addons/mat_maker_gd/nodes/noise/noise_color.gd +++ b/game/addons/mat_maker_gd/nodes/noise/noise_color.gd @@ -50,13 +50,10 @@ func gen() -> void: tex.create_from_image(image) texture = tex +var seed_o26210 = 7313; func nc(uv : Vector2) -> Color: - var v : Vector3 = Commons.color_dots(((uv)), 1.0/512.000000000, seed_o26210); - - return Color(v.x, v.y, v.z, 1) - -var seed_o26210 = 7313; + return Commons.noise_color(uv, seed_o26210) func reffg(): return false