Moved even more things to commons.gd.

This commit is contained in:
Relintai 2021-10-02 15:38:12 +02:00
parent 01fd374344
commit 1d6a95d578
5 changed files with 54 additions and 41 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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