🔧 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
+1 -1
View File
@@ -39,7 +39,7 @@ void main() {
progress * 0.05 * uShake * cos((progress + uSeed.y) * (1.0 + uSeed.y) * uShake);
// "Suck" the texture into the center.
float dist = length(coords) / sqrt(2);
float dist = length(coords) / sqrt(2.0);
coords += progress * coords / dist * 0.5 * uSuction;
// Apply some whirling.
+4 -4
View File
@@ -20,12 +20,12 @@ uniform float uShardScale;
uniform float uBlowForce;
uniform float uGravity;
const float SHARD_LAYERS = 5;
const float SHARD_LAYERS = 5.0;
const float ACTOR_SCALE = 2.0;
const float PADDING = ACTOR_SCALE / 2.0 - 0.5;
void main() {
vec4 oColor = vec4(0, 0, 0, 0);
vec4 oColor = vec4(0.0);
float progress = uForOpening ? 1.0 - uProgress : uProgress;
@@ -41,7 +41,7 @@ void main() {
coords -= uEpicenter;
// Scale each layer a bit differently.
coords /= mix(1.0, 1.0 + uBlowForce * (i + 2) / SHARD_LAYERS, progress);
coords /= mix(1.0, 1.0 + uBlowForce * (i + 2.0) / SHARD_LAYERS, progress);
// Rotate each layer a bit differently.
float rotation = (mod(i, 2.0) - 0.5) * 0.2 * progress;
@@ -65,7 +65,7 @@ void main() {
// the bin of the current shard.
float shardGroup = floor(shardMap.g * SHARD_LAYERS * 0.999);
if (shardGroup == i && (shardMap.x - pow(progress + 0.1, 2)) > 0) {
if (shardGroup == i && (shardMap.x - pow(progress + 0.1, 2)) > 0.0) {
oColor = getInputColor(coords);
}
}
+7 -7
View File
@@ -25,10 +25,10 @@ const float EDGE_FADE_WIDTH = 50;
// result.x: A mask for the particles.
// result.y: The opacity of the fading window.
vec2 getMasks(float progress) {
float fadeInProgress = clamp(progress / FADE_IN_TIME, 0, 1);
float fadeOutProgress = clamp((progress - FADE_IN_TIME) / FADE_OUT_TIME, 0, 1);
float fadeInProgress = clamp(progress / FADE_IN_TIME, 0.0, 1.0);
float fadeOutProgress = clamp((progress - FADE_IN_TIME) / FADE_OUT_TIME, 0.0, 1.0);
float heartProgress =
clamp((progress - (1.0 - HEART_FADE_TIME)) / HEART_FADE_TIME, 0, 1);
clamp((progress - (1.0 - HEART_FADE_TIME)) / HEART_FADE_TIME, 0.0, 1.0);
// Compute mask for the "atom" particles.
float dist = length(iTexCoord.st - 0.5) * 4.0;
@@ -41,10 +41,10 @@ vec2 getMasks(float progress) {
atomMask *= edgeFade;
float heartMask = getRelativeEdgeMask(0.5);
heartMask = 3.0 * pow(heartMask, 5);
heartMask = 3.0 * pow(heartMask, 5.0);
heartMask *= fadeOutProgress;
heartMask *= 1.0 - heartProgress;
atomMask = clamp(heartMask + atomMask, 0, 1);
atomMask = clamp(heartMask + atomMask, 0.0, 1.0);
// Compute fading window opacity.
float windowMask = pow(1.0 - fadeOutProgress, 2.0);
@@ -70,7 +70,7 @@ void main() {
scaledUV /= uScale;
// Add molecule particles.
vec2 uv = scaledUV + vec2(0, 0.1 * uProgress * uDuration);
vec2 uv = scaledUV + vec2(0.0, 0.1 * uProgress * uDuration);
uv *= 0.010598 * vec2(0.5 * uSize.x, uSize.y);
float particles = 0.2 * pow((simplex3D(vec3(uv, 0.0 * uProgress * uDuration))), 3.0);
@@ -78,7 +78,7 @@ void main() {
for (int i = 1; i <= 3; ++i) {
vec2 uv = scaledUV * 0.12154 / pow(1.5, i) * uSize;
float atoms = simplex3D(vec3(uv, 2.0 * uProgress * uDuration / i));
particles += 0.5 * pow(0.2 * (1.0 / (1.0 - atoms) - 1.0), 2);
particles += 0.5 * pow(0.2 * (1.0 / (1.0 - atoms) - 1.0), 2.0);
}
oColor.rgb += uColor * particles * masks.x;
+8 -8
View File
@@ -28,22 +28,22 @@ const float EDGE_FADE = 50;
// result.w: The opacity of the fading window.
vec4 getMasks(float progress) {
float showerProgress = progress / SHOWER_TIME;
float streakProgress = clamp((progress - SHOWER_TIME) / STREAK_TIME, 0, 1);
float fadeProgress = clamp((progress - SHOWER_TIME) / (1.0 - SHOWER_TIME), 0, 1);
float streakProgress = clamp((progress - SHOWER_TIME) / STREAK_TIME, 0.0, 1.0);
float fadeProgress = clamp((progress - SHOWER_TIME) / (1.0 - SHOWER_TIME), 0.0, 1.0);
// Gradient from top to bottom.
float t = iTexCoord.t;
// A smooth gradient which moves to the bottom within the showerProgress.
float showerMask =
smoothstep(1, 0, abs(showerProgress - t - SHOWER_WIDTH) / SHOWER_WIDTH);
smoothstep(1.0, 0.0, abs(showerProgress - t - SHOWER_WIDTH) / SHOWER_WIDTH);
// This is 1 above the streak mask.
float streakMask = (showerProgress - t - SHOWER_WIDTH) > 0 ? 1 : 0;
float streakMask = (showerProgress - t - SHOWER_WIDTH) > 0.0 ? 1.0 : 0.0;
// Compute mask for the "atom" particles.
float atomMask = getRelativeEdgeMask(0.2);
atomMask = max(0, atomMask - showerMask);
atomMask = max(0.0, atomMask - showerMask);
atomMask *= streakMask;
atomMask *= sqrt(1 - fadeProgress * fadeProgress);
@@ -84,21 +84,21 @@ void main() {
oColor.a = oColor.a * masks.w;
// Add leading shower particles.
vec2 showerUV = iTexCoord.st + vec2(0, -0.7 * progress / SHOWER_TIME);
vec2 showerUV = iTexCoord.st + vec2(0.0, -0.7 * progress / SHOWER_TIME);
showerUV *= 0.02 * uSize / uScale;
float shower = pow(simplex2D(showerUV), 10.0);
oColor.rgb += uColor * shower * masks.x;
oColor.a += shower * masks.x;
// Add trailing streak lines.
vec2 streakUV = iTexCoord.st + vec2(0, -progress / SHOWER_TIME);
vec2 streakUV = iTexCoord.st + vec2(0.0, -progress / SHOWER_TIME);
streakUV *= vec2(0.05 * uSize.x, 0.001 * uSize.y) / uScale;
float streaks = simplex2DFractal(streakUV) * 0.5;
oColor.rgb += uColor * streaks * masks.y;
oColor.a += streaks * masks.y;
// Add glimmering atoms.
vec2 atomUV = iTexCoord.st + vec2(0, -0.025 * progress / SHOWER_TIME);
vec2 atomUV = iTexCoord.st + vec2(0.0, -0.025 * progress / SHOWER_TIME);
atomUV *= 0.2 * uSize / uScale;
float atoms = pow((simplex3D(vec3(atomUV, uProgress * uDuration))), 5.0);
oColor.rgb += uColor * atoms * masks.z;
+8 -8
View File
@@ -23,7 +23,7 @@ uniform vec4 uGradient4;
uniform vec4 uGradient5;
// These may be configurable in the future.
const float EDGE_FADE = 70;
const float EDGE_FADE = 70.0;
const float FADE_WIDTH = 0.1;
const float HIDE_TIME = 0.4;
@@ -59,22 +59,22 @@ vec4 getFireColor(float v) {
vec2 effectMask(float hideTime, float fadeWidth, float edgeFadeWidth) {
float progress = easeOutQuad(uProgress);
float burnProgress = clamp(progress / hideTime, 0, 1);
float afterBurnProgress = clamp((progress - hideTime) / (1 - hideTime), 0, 1);
float burnProgress = clamp(progress / hideTime, 0.0, 1.0);
float afterBurnProgress = clamp((progress - hideTime) / (1.0 - hideTime), 0.0, 1.0);
// Gradient from top to bottom.
float t = iTexCoord.t * (1 - fadeWidth);
float t = iTexCoord.t * (1.0 - fadeWidth);
// Visible part of the window. Gradually dissolves towards the bottom.
float windowMask = 1 - clamp((burnProgress - t) / fadeWidth, 0, 1);
float windowMask = 1.0 - clamp((burnProgress - t) / fadeWidth, 0.0, 1.0);
// Gradient from top burning window.
float effectMask = clamp(t * (1 - windowMask) / burnProgress, 0, 1);
float effectMask = clamp(t * (1.0 - windowMask) / burnProgress, 0.0, 1.0);
// Fade-out when the window burned down.
if (progress > hideTime) {
float fade = sqrt(1 - afterBurnProgress * afterBurnProgress);
effectMask *= mix(1, 1 - t, afterBurnProgress) * fade;
float fade = sqrt(1.0 - afterBurnProgress * afterBurnProgress);
effectMask *= mix(1.0, 1.0 - t, afterBurnProgress) * fade;
}
// Fade at window borders.
+2 -2
View File
@@ -73,8 +73,8 @@ void main() {
// glowProgress fades in in the first half of the animation, tileProgress fades
// in in the second half.
float glowProgress = smoothstep(0, 1, clamp(progress / 0.5, 0, 1));
float tileProgress = smoothstep(0, 1, clamp((progress - 0.5) / 0.5, 0, 1));
float glowProgress = smoothstep(0.0, 1.0, clamp(progress / 0.5, 0.0, 1.0));
float tileProgress = smoothstep(0.0, 1.0, clamp((progress - 0.5) / 0.5, 0.0, 1.0));
vec2 texScale = 0.1 * uSize / uScale;
vec4 hex = getHexagons(iTexCoord.st * texScale);
+9 -8
View File
@@ -21,8 +21,8 @@ uniform float uRandomness;
uniform float uOverShoot;
// These may be configurable in the future.
const float EDGE_FADE = 30;
const float FADE_WIDTH = 150;
const float EDGE_FADE = 30.0;
const float FADE_WIDTH = 150.0;
const float TRAIL_LENGTH = 0.2;
const float FINAL_FADE_START_TIME = 0.8;
const float LETTER_TILES = 16.0;
@@ -55,8 +55,8 @@ vec2 getRain(vec2 fragCoord) {
float distToDrop = (uProgress * 2 - delay) * speed - iTexCoord.y;
float rainAlpha = distToDrop >= 0 ? exp(-distToDrop / TRAIL_LENGTH) : 0;
float windowAlpha = 1 - clamp(uSize.y * distToDrop, 0, FADE_WIDTH) / FADE_WIDTH;
float rainAlpha = distToDrop >= 0.0 ? exp(-distToDrop / TRAIL_LENGTH) : 0.0;
float windowAlpha = 1.0 - clamp(uSize.y * distToDrop, 0.0, FADE_WIDTH) / FADE_WIDTH;
// Fade at window borders.
rainAlpha *= getAbsoluteEdgeMask(EDGE_FADE, 0.5);
@@ -64,8 +64,8 @@ vec2 getRain(vec2 fragCoord) {
// Add some variation to the drop start and end position.
float shorten =
fract(sin(column + 42.0) * 33.423) * mix(0.0, uOverShoot * 0.25, uRandomness);
rainAlpha *= smoothstep(0, 1, clamp(iTexCoord.y / shorten, 0, 1));
rainAlpha *= smoothstep(0, 1, clamp((1.0 - iTexCoord.y) / shorten, 0, 1));
rainAlpha *= smoothstep(0.0, 1.0, clamp(iTexCoord.y / shorten, 0.0, 1.0));
rainAlpha *= smoothstep(0.0, 1.0, clamp((1.0 - iTexCoord.y) / shorten, 0.0, 1.0));
if (uForOpening) {
windowAlpha = 1.0 - windowAlpha;
@@ -90,11 +90,12 @@ void main() {
// This is used to fade out the remaining trails in the end.
float finalFade =
1 - clamp((uProgress - FINAL_FADE_START_TIME) / (1 - FINAL_FADE_START_TIME), 0, 1);
1 -
clamp((uProgress - FINAL_FADE_START_TIME) / (1.0 - FINAL_FADE_START_TIME), 0.0, 1.0);
float rainAlpha = finalFade * rainMask.x;
// Add the matrix effect to the window.
vec4 text = vec4(mix(uTrailColor, uTipColor, min(1, pow(rainAlpha + 0.1, 4))),
vec4 text = vec4(mix(uTrailColor, uTipColor, min(1.0, pow(rainAlpha + 0.1, 4.0))),
rainAlpha * textMask);
oColor = alphaOver(oColor, text);
+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;
+9 -9
View File
@@ -41,7 +41,7 @@ vec2 getClawUV(vec2 texCoords, float gridScale, vec2 seed) {
coords *= gridScale;
// Get grid cell coordinates in [0..1].
vec2 cellUV = mod(coords, vec2(1));
vec2 cellUV = mod(coords, vec2(1.0));
// This is unique for each cell.
vec2 cellID = coords - cellUV + vec2(362.456);
@@ -61,7 +61,7 @@ vec2 getClawUV(vec2 texCoords, float gridScale, vec2 seed) {
cellUV += 0.5;
// Clamp resulting coordinates.
return clamp(cellUV, vec2(0), vec2(1));
return clamp(cellUV, vec2(0.0), vec2(1.0));
}
void main() {
@@ -84,7 +84,7 @@ void main() {
for (int i = 0; i < uNumClaws; ++i) {
vec2 uv = getClawUV(coords, 1.0 / uClawSize, uSeed * (i + 1));
float delay = i / uNumClaws * MAX_SPAWN_TIME;
scratchMap = min(scratchMap, clamp(texture2D(uClawTexture, uv).r + delay, 0, 1));
scratchMap = min(scratchMap, clamp(texture2D(uClawTexture, uv).r + delay, 0.0, 1.0));
}
// Get the window texture. We shift the texture lookup by the local derivative of
@@ -93,9 +93,9 @@ void main() {
vec4 oColor = getInputColor(coords + offset);
// Add colorful flashes.
float flashIntensity = 1.0 / FLASH_INTENSITY * (scratchMap - progress) + 1;
if (flashIntensity < 0 || flashIntensity >= 1) {
flashIntensity = 0;
float flashIntensity = 1.0 / FLASH_INTENSITY * (scratchMap - progress) + 1.0;
if (flashIntensity < 0.0 || flashIntensity >= 1.0) {
flashIntensity = 0.0;
}
// Hide flashes where there is now window.
@@ -103,14 +103,14 @@ void main() {
flash.a *= flashIntensity * oColor.a * (1.0 - progress);
// Hide scratched out parts.
oColor.a *= (scratchMap > progress ? 1 : 0);
oColor.a *= (scratchMap > progress ? 1.0 : 0.0);
// Add flash color.
oColor = alphaOver(oColor, flash);
// Fade out the remaining shards.
float fadeProgress = smoothstep(0, 1, (progress - 1.0 + FF_TIME) / FF_TIME);
oColor.a *= sqrt(1 - fadeProgress * fadeProgress);
float fadeProgress = smoothstep(0.0, 1.0, (progress - 1.0 + FF_TIME) / FF_TIME);
oColor.a *= sqrt(1.0 - fadeProgress * fadeProgress);
// These are pretty useful for understanding how this works.
// oColor = vec4(vec3(flashIntensity), 1);
+7 -7
View File
@@ -19,7 +19,7 @@ uniform float uScale;
const float WISPS_RADIUS = 20.0;
const float WISPS_SPEED = 10.0;
const float WISPS_SPACING = 40 + WISPS_RADIUS;
const float WISPS_SPACING = 40.0 + WISPS_RADIUS;
const int WISPS_LAYERS = 8;
const float WISPS_IN_TIME = 0.5;
const float WINDOW_OUT_TIME = 1.0;
@@ -36,7 +36,7 @@ float getWisps(vec2 texCoords, float gridSize, vec2 seed) {
coords /= gridSize;
// Get grid cell coordinates in [0..1].
vec2 cellUV = mod(coords, vec2(1));
vec2 cellUV = mod(coords, vec2(1.0));
// This is unique for each cell.
vec2 cellID = coords - cellUV + vec2(362.456);
@@ -77,7 +77,7 @@ void main() {
// Compute several layers of moving wisps.
vec2 uv = (iTexCoord.st - 0.5) / mix(1.0, 0.5, progress) + 0.5;
uv /= uScale;
float wisps = 0;
float wisps = 0.0;
for (int i = 0; i < WISPS_LAYERS; ++i) {
wisps += getWisps(uv * 0.3, WISPS_SPACING, uSeed * (i + 1));
}
@@ -86,10 +86,10 @@ void main() {
float mask = getRelativeEdgeMask(mix(0.01, 0.5, progress));
// Compute three different progress values.
float wispsIn = smoothstep(0, 1, clamp(progress / WISPS_IN_TIME, 0, 1));
float wispsOut =
smoothstep(0, 1, clamp((progress - WISPS_IN_TIME) / (1.0 - WISPS_IN_TIME), 0, 1));
float windowOut = smoothstep(0, 1, clamp(progress / WINDOW_OUT_TIME, 0, 1));
float wispsIn = smoothstep(0.0, 1.0, clamp(progress / WISPS_IN_TIME, 0.0, 1.0));
float wispsOut = smoothstep(
0.0, 1.0, clamp((progress - WISPS_IN_TIME) / (1.0 - WISPS_IN_TIME), 0.0, 1.0));
float windowOut = smoothstep(0.0, 1.0, clamp(progress / WINDOW_OUT_TIME, 0.0, 1.0));
// Use a noise function to dissolve the window.
float noise = smoothstep(1.0, 0.0, abs(2.0 * simplex2DFractal(uv * uSize / 250) - 1.0));