✨ Fix formatting
This commit is contained in:
@@ -185,8 +185,7 @@ vec3 darken(vec3 color, float fac) { return color * (1.0 - fac); }
|
|||||||
// color will be white.
|
// color will be white.
|
||||||
vec3 lighten(vec3 color, float fac) { return color + (vec3(1.0) - color) * fac; }
|
vec3 lighten(vec3 color, float fac) { return color + (vec3(1.0) - color) * fac; }
|
||||||
|
|
||||||
|
// change the color based on an offset amount
|
||||||
//change the color based on an offset amount
|
|
||||||
vec3 offsetHue(vec3 color, float hueOffset) {
|
vec3 offsetHue(vec3 color, float hueOffset) {
|
||||||
// Convert RGB to HSV
|
// Convert RGB to HSV
|
||||||
float maxC = max(max(color.r, color.g), color.b);
|
float maxC = max(max(color.r, color.g), color.b);
|
||||||
@@ -251,21 +250,23 @@ float easeOutBack(float x, float e) {
|
|||||||
return p * p * ((e + 1.0) * p + e) + 1.0;
|
return p * p * ((e + 1.0) * p + e) + 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://easings.net/
|
// https://easings.net/
|
||||||
/*
|
/*
|
||||||
Easing functions define the rate of change of a parameter over time, commonly used in animations, UI transitions, and game development. They provide a way to make movements more natural or visually appealing rather than linear and mechanical. Popular categories of easing functions include:
|
Easing functions define the rate of change of a parameter over time, commonly used in
|
||||||
|
animations, UI transitions, and game development. They provide a way to make movements
|
||||||
|
more natural or visually appealing rather than linear and mechanical. Popular categories
|
||||||
|
of easing functions include:
|
||||||
|
|
||||||
Linear: Constant speed from start to finish.
|
Linear: Constant speed from start to finish.
|
||||||
Quadratic (Ease In, Ease Out, Ease In Out): Changes at varying rates, with smoother starts or stops.
|
Quadratic (Ease In, Ease Out, Ease In Out): Changes at varying rates, with smoother starts
|
||||||
Cubic: Similar to quadratic but allows for even more nuanced transitions.
|
or stops. Cubic: Similar to quadratic but allows for even more nuanced transitions.
|
||||||
Exponential: Drastic changes at the start or end, often used for dramatic effects.
|
Exponential: Drastic changes at the start or end, often used for dramatic effects.
|
||||||
Bounce: Mimics a bouncing object with oscillations.
|
Bounce: Mimics a bouncing object with oscillations.
|
||||||
Elastic: Simulates the behavior of a spring, with overshooting and oscillations.
|
Elastic: Simulates the behavior of a spring, with overshooting and oscillations.
|
||||||
Below are text-based "graphs" of some easing functions, where the horizontal axis represents time and the vertical axis represents progress.
|
Below are text-based "graphs" of some easing functions, where the horizontal axis
|
||||||
|
represents time and the vertical axis represents progress.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Quadratic Easing
|
// Quadratic Easing
|
||||||
// Smooth acceleration and deceleration using quadratic (t^2) curves.
|
// Smooth acceleration and deceleration using quadratic (t^2) curves.
|
||||||
|
|
||||||
@@ -309,7 +310,8 @@ float easeOutQuart(float t) {
|
|||||||
|
|
||||||
float easeInOutQuart(float t) {
|
float easeInOutQuart(float t) {
|
||||||
// Combines easeIn and easeOut quartic behavior for very smooth transitions.
|
// Combines easeIn and easeOut quartic behavior for very smooth transitions.
|
||||||
return t < 0.5 ? 8.0 * t * t * t * t : 1.0 - 8.0 * (t - 1.0) * (t - 1.0) * (t - 1.0) * (t - 1.0);
|
return t < 0.5 ? 8.0 * t * t * t * t
|
||||||
|
: 1.0 - 8.0 * (t - 1.0) * (t - 1.0) * (t - 1.0) * (t - 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sine Easing
|
// Sine Easing
|
||||||
@@ -347,7 +349,8 @@ float easeInOutExpo(float t) {
|
|||||||
// Combines easeIn and easeOut exponential for sharp transitions.
|
// Combines easeIn and easeOut exponential for sharp transitions.
|
||||||
if (t == 0.0) return 0.0;
|
if (t == 0.0) return 0.0;
|
||||||
if (t == 1.0) return 1.0;
|
if (t == 1.0) return 1.0;
|
||||||
return t < 0.5 ? 0.5 * pow(2.0, 20.0 * t - 10.0) : 1.0 - 0.5 * pow(2.0, -20.0 * t + 10.0);
|
return t < 0.5 ? 0.5 * pow(2.0, 20.0 * t - 10.0)
|
||||||
|
: 1.0 - 0.5 * pow(2.0, -20.0 * t + 10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Back Easing
|
// Back Easing
|
||||||
@@ -362,8 +365,6 @@ float easeInOutBack(float t) {
|
|||||||
: (pow(2.0 * t - 2.0, 2.0) * ((c2 + 1.0) * (t * 2.0 - 2.0) + c2) + 2.0) / 2.0;
|
: (pow(2.0 * t - 2.0, 2.0) * ((c2 + 1.0) * (t * 2.0 - 2.0) + c2) + 2.0) / 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------- edge mask helpers
|
// --------------------------------------------------------------------- edge mask helpers
|
||||||
|
|
||||||
// This method returns a mask which smoothly transitions towards zero when approaching
|
// This method returns a mask which smoothly transitions towards zero when approaching
|
||||||
@@ -387,7 +388,7 @@ float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) {
|
|||||||
// the fade zone is given in pixels. This uses the standard uniforms uSize and uPadding.
|
// the fade zone is given in pixels. This uses the standard uniforms uSize and uPadding.
|
||||||
// This means that the fading zone is not actually at the actors boundaries but at the
|
// This means that the fading zone is not actually at the actors boundaries but at the
|
||||||
// position of the window border in the texture.
|
// position of the window border in the texture.
|
||||||
// The offset paramter controls whether the fading is placed inside the window borders
|
// The offset parameter controls whether the fading is placed inside the window borders
|
||||||
// (offset = 0), ontop the window borders (offset = 0.5) or outside the window borders
|
// (offset = 0), ontop the window borders (offset = 0.5) or outside the window borders
|
||||||
// (offset = 1).
|
// (offset = 1).
|
||||||
float getAbsoluteEdgeMask(float fadePixels, float offset) {
|
float getAbsoluteEdgeMask(float fadePixels, float offset) {
|
||||||
@@ -428,19 +429,13 @@ float getWinding(vec2 a, vec2 b) { return cross(vec3(a, 0.0), vec3(b, 0.0)).z; }
|
|||||||
|
|
||||||
// Rotates the given 2D vector a clockwise by the angle alpha (given in radians).
|
// Rotates the given 2D vector a clockwise by the angle alpha (given in radians).
|
||||||
vec2 rotate(vec2 a, float angle) {
|
vec2 rotate(vec2 a, float angle) {
|
||||||
return vec2(
|
return vec2(a.x * cos(angle) - a.y * sin(angle), a.x * sin(angle) + a.y * cos(angle));
|
||||||
a.x * cos(angle) - a.y * sin(angle),
|
|
||||||
a.x * sin(angle) + a.y * cos(angle)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//rotates a given 2d vector, around a given center (angle is in radians)
|
// rotates a given 2d vector, around a given center (angle is in radians)
|
||||||
vec2 rotate(vec2 a, float angle, vec2 center)
|
vec2 rotate(vec2 a, float angle, vec2 center) {
|
||||||
{
|
return vec2(cos(angle) * (a.x - center.x) + sin(angle) * (a.y - center.y) + center.x,
|
||||||
return vec2(
|
cos(angle) * (a.y - center.y) - sin(angle) * (a.x - center.x) + center.y);
|
||||||
cos(angle) * (a.x - center.x) + sin(angle) * (a.y - center.y) + center.x,
|
|
||||||
cos(angle) * (a.y - center.y) - sin(angle) * (a.x - center.x) + center.y
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------- noise
|
// --------------------------------------------------------------------------------- noise
|
||||||
@@ -645,10 +640,8 @@ float simplex3DFractal(vec3 m) {
|
|||||||
0.1333333 * simplex3D(4.0 * m * rot3) + 0.0666667 * simplex3D(8.0 * m);
|
0.1333333 * simplex3D(4.0 * m * rot3) + 0.0666667 * simplex3D(8.0 * m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------- remap
|
// --------------------------------------------------------------------------------- remap
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These functions remap a given value from one range to another.
|
These functions remap a given value from one range to another.
|
||||||
The remap operation is particularly useful in shader programming
|
The remap operation is particularly useful in shader programming
|
||||||
@@ -671,42 +664,30 @@ This ensures a linear transformation from the old range to the new range.
|
|||||||
// Maps a float value from one range [oldMin, oldMax] to another range [newMin, newMax].
|
// Maps a float value from one range [oldMin, oldMax] to another range [newMin, newMax].
|
||||||
// This is useful for normalizing or scaling scalar values to fit within a desired range.
|
// This is useful for normalizing or scaling scalar values to fit within a desired range.
|
||||||
float remap(float value, float oldMin, float oldMax, float newMin, float newMax) {
|
float remap(float value, float oldMin, float oldMax, float newMin, float newMax) {
|
||||||
return clamp(
|
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
|
||||||
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
|
newMax);
|
||||||
newMin,
|
|
||||||
newMax
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remap for vec2
|
// Remap for vec2
|
||||||
// Maps a 2D vector (vec2) from one range [oldMin, oldMax] to another range [newMin, newMax].
|
// Maps a 2D vector (vec2) from one range [oldMin, oldMax] to another range [newMin,
|
||||||
// Each component of the vec2 is individually scaled and transformed.
|
// newMax]. Each component of the vec2 is individually scaled and transformed.
|
||||||
vec2 remap(vec2 value, vec2 oldMin, vec2 oldMax, vec2 newMin, vec2 newMax) {
|
vec2 remap(vec2 value, vec2 oldMin, vec2 oldMax, vec2 newMin, vec2 newMax) {
|
||||||
return clamp(
|
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
|
||||||
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
|
newMax);
|
||||||
newMin,
|
|
||||||
newMax
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remap for vec3
|
// Remap for vec3
|
||||||
// Maps a 3D vector (vec3) from one range [oldMin, oldMax] to another range [newMin, newMax].
|
// Maps a 3D vector (vec3) from one range [oldMin, oldMax] to another range [newMin,
|
||||||
// Each component of the vec3 is individually scaled and transformed.
|
// newMax]. Each component of the vec3 is individually scaled and transformed.
|
||||||
vec3 remap(vec3 value, vec3 oldMin, vec3 oldMax, vec3 newMin, vec3 newMax) {
|
vec3 remap(vec3 value, vec3 oldMin, vec3 oldMax, vec3 newMin, vec3 newMax) {
|
||||||
return clamp(
|
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
|
||||||
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
|
newMax);
|
||||||
newMin,
|
|
||||||
newMax
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remap for vec4
|
// Remap for vec4
|
||||||
// Maps a 4D vector (vec4) from one range [oldMin, oldMax] to another range [newMin, newMax].
|
// Maps a 4D vector (vec4) from one range [oldMin, oldMax] to another range [newMin,
|
||||||
// Each component of the vec4 is individually scaled and transformed.
|
// newMax]. Each component of the vec4 is individually scaled and transformed.
|
||||||
vec4 remap(vec4 value, vec4 oldMin, vec4 oldMax, vec4 newMin, vec4 newMax) {
|
vec4 remap(vec4 value, vec4 oldMin, vec4 oldMax, vec4 newMin, vec4 newMax) {
|
||||||
return clamp(
|
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
|
||||||
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
|
newMax);
|
||||||
newMin,
|
|
||||||
newMax
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user