🔧 Reduce number of implicit calls

This commit is contained in:
Simon Schneegans
2022-06-10 08:24:42 +02:00
parent f44d0ae5b6
commit 6fb56612e2
10 changed files with 63 additions and 62 deletions
+8 -8
View File
@@ -18,7 +18,7 @@ uniform vec4 uDustColor;
uniform vec2 uSeed;
uniform float uDustScale;
const float DUST_LAYERS = 4;
const float DUST_LAYERS = 4.0;
const float GROW_INTENSITY = 0.05;
const float SHRINK_INTENSITY = 0.05;
const float WIND_INTENSITY = 0.05;
@@ -32,35 +32,35 @@ void main() {
float gradient = iTexCoord.t * ACTOR_SCALE - PADDING;
progress = 2.0 - gradient - 2.0 * progress;
progress = progress + 0.25 - 0.5 * simplex2D((iTexCoord.st + uSeed) * 2.0);
progress = pow(max(0, progress), 2.0);
progress = pow(max(0.0, progress), 2.0);
vec4 oColor = vec4(0.0);
for (float i = 0; i < DUST_LAYERS; ++i) {
// Create a random direction.
float factor = DUST_LAYERS == 1 ? 0 : i / (DUST_LAYERS - 1);
float factor = DUST_LAYERS == 1.0 ? 0.0 : i / (DUST_LAYERS - 1.0);
float angle = 123.123 * (uSeed.x + factor);
vec2 direction = vec2(1.0, 0.0);
direction = rotate(direction, angle);
// Flip direction for one side of the window.
vec2 coords = iTexCoord.st * ACTOR_SCALE - PADDING - 0.5;
if (getWinding(direction, coords) > 0) {
direction *= -1;
if (getWinding(direction, coords) > 0.0) {
direction *= -1.0;
}
// Flip direction for half the layers.
if (factor > 0.5) {
direction *= -1;
direction *= -1.0;
}
// We grow the layer along the random direction, shrink it orthogonally to it
// and scale it up slightly.
float dist = distToLine(vec2(0.0), direction, coords);
vec2 grow = direction * dist * mix(0, GROW_INTENSITY, progress);
vec2 grow = direction * dist * mix(0.0, GROW_INTENSITY, progress);
vec2 shrink =
vec2(direction.y, -direction.x) * dist * mix(0, SHRINK_INTENSITY, progress);
vec2(direction.y, -direction.x) * dist * mix(0.0, SHRINK_INTENSITY, progress);
float scale = mix(1.0, 1.05, factor * progress);
coords = (coords + grow + shrink) / scale;