This commit is contained in:
Justin Garza
2025-01-04 19:06:05 -05:00
parent 7fcda0b22d
commit 95bde46e39
6 changed files with 506 additions and 77 deletions
+49
View File
@@ -185,6 +185,55 @@ vec3 darken(vec3 color, float fac) { return color * (1.0 - fac); }
// color will be white.
vec3 lighten(vec3 color, float fac) { return color + (vec3(1.0) - color) * fac; }
//change the color based on an offset amount
vec3 offsetHue(vec3 color, float hueOffset) {
// Convert RGB to HSV
float maxC = max(max(color.r, color.g), color.b);
float minC = min(min(color.r, color.g), color.b);
float delta = maxC - minC;
float hue = 0.0;
if (delta > 0.0) {
if (maxC == color.r) {
hue = mod((color.g - color.b) / delta, 6.0);
} else if (maxC == color.g) {
hue = (color.b - color.r) / delta + 2.0;
} else {
hue = (color.r - color.g) / delta + 4.0;
}
}
hue /= 6.0;
float saturation = (maxC > 0.0) ? (delta / maxC) : 0.0;
float value = maxC;
// Offset the hue
hue = mod(hue + hueOffset, 1.0);
// Convert HSV back to RGB
float c = value * saturation;
float x = c * (1.0 - abs(mod(hue * 6.0, 2.0) - 1.0));
float m = value - c;
vec3 rgb;
if (hue < 1.0 / 6.0) {
rgb = vec3(c, x, 0.0);
} else if (hue < 2.0 / 6.0) {
rgb = vec3(x, c, 0.0);
} else if (hue < 3.0 / 6.0) {
rgb = vec3(0.0, c, x);
} else if (hue < 4.0 / 6.0) {
rgb = vec3(0.0, x, c);
} else if (hue < 5.0 / 6.0) {
rgb = vec3(x, 0.0, c);
} else {
rgb = vec3(c, 0.0, x);
}
return rgb + m;
}
// ---------------------------------------------------------------------- easing functions
// Here are some basic easing function. More can be added if required!