✨ Fix formatting

This commit is contained in:
Simon Schneegans
2025-02-09 08:00:26 +01:00
parent 3602f07dae
commit 00d6f9089d
+33 -52
View File
@@ -185,8 +185,7 @@ 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
// 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);
@@ -251,21 +250,23 @@ float easeOutBack(float x, float e) {
return p * p * ((e + 1.0) * p + e) + 1.0;
}
// 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.
Quadratic (Ease In, Ease Out, Ease In Out): Changes at varying rates, with smoother starts or stops.
Cubic: Similar to quadratic but allows for even more nuanced transitions.
Quadratic (Ease In, Ease Out, Ease In Out): Changes at varying rates, with smoother starts
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.
Bounce: Mimics a bouncing object with 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
// Smooth acceleration and deceleration using quadratic (t^2) curves.
@@ -309,7 +310,8 @@ float easeOutQuart(float t) {
float easeInOutQuart(float t) {
// 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
@@ -347,7 +349,8 @@ float easeInOutExpo(float t) {
// Combines easeIn and easeOut exponential for sharp transitions.
if (t == 0.0) return 0.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
@@ -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;
}
// --------------------------------------------------------------------- edge mask helpers
// 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.
// This means that the fading zone is not actually at the actors boundaries but at the
// 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 = 1).
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).
vec2 rotate(vec2 a, float angle) {
return vec2(
a.x * cos(angle) - a.y * sin(angle),
a.x * sin(angle) + a.y * cos(angle)
);
return vec2(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)
vec2 rotate(vec2 a, float angle, vec2 center)
{
return vec2(
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
);
// rotates a given 2d vector, around a given center (angle is in radians)
vec2 rotate(vec2 a, float angle, vec2 center) {
return vec2(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
@@ -645,10 +640,8 @@ float simplex3DFractal(vec3 m) {
0.1333333 * simplex3D(4.0 * m * rot3) + 0.0666667 * simplex3D(8.0 * m);
}
// --------------------------------------------------------------------------------- remap
/*
These functions remap a given value from one range to another.
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].
// 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) {
return clamp(
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
newMin,
newMax
);
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
newMax);
}
// Remap for vec2
// Maps a 2D vector (vec2) from one range [oldMin, oldMax] to another range [newMin, newMax].
// Each component of the vec2 is individually scaled and transformed.
// Maps a 2D vector (vec2) from one range [oldMin, oldMax] to another range [newMin,
// newMax]. Each component of the vec2 is individually scaled and transformed.
vec2 remap(vec2 value, vec2 oldMin, vec2 oldMax, vec2 newMin, vec2 newMax) {
return clamp(
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
newMin,
newMax
);
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
newMax);
}
// Remap for vec3
// Maps a 3D vector (vec3) from one range [oldMin, oldMax] to another range [newMin, newMax].
// Each component of the vec3 is individually scaled and transformed.
// Maps a 3D vector (vec3) from one range [oldMin, oldMax] to another range [newMin,
// newMax]. Each component of the vec3 is individually scaled and transformed.
vec3 remap(vec3 value, vec3 oldMin, vec3 oldMax, vec3 newMin, vec3 newMax) {
return clamp(
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
newMin,
newMax
);
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
newMax);
}
// Remap for vec4
// Maps a 4D vector (vec4) from one range [oldMin, oldMax] to another range [newMin, newMax].
// Each component of the vec4 is individually scaled and transformed.
// Maps a 4D vector (vec4) from one range [oldMin, oldMax] to another range [newMin,
// newMax]. Each component of the vec4 is individually scaled and transformed.
vec4 remap(vec4 value, vec4 oldMin, vec4 oldMax, vec4 newMin, vec4 newMax) {
return clamp(
newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin),
newMin,
newMax
);
return clamp(newMin + (value - oldMin) * (newMax - newMin) / (oldMax - oldMin), newMin,
newMax);
}