treppe-gl/shaders/bounce.glsl
April John cebb41dbc7 Add fire, ocean, heartbeat, bounce, trans and storm shaders
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-16 15:03:47 +02:00

31 lines
1 KiB
GLSL

// A ball bouncing up and down the stairs, new colour every bounce
float hash(float n) { return fract(sin(n * 12.9898) * 43758.5453); }
vec3 hue(float h) {
return clamp(abs(mod(h * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0,
0.0, 1.0);
}
float ballPos(float t) {
return 12.0 * abs(sin(t * 0.5));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
float i = floor(fragCoord.x / iResolution.x * 16.0);
float cyc = iTime * 0.5 / 3.14159265;
float bounce = floor(cyc);
// colour changes while the ball is on the floor, faded over the bounce
vec3 colour = mix(hue(hash(bounce + 2.0)), hue(hash(bounce + 3.0)),
smoothstep(0.0, 0.25, fract(cyc)));
float d = i - ballPos(iTime);
float v = exp(-d * d * 1.0);
for (int j = 1; j <= 8; j++) {
float fj = float(j);
float dj = i - ballPos(iTime - fj * 0.12);
v = max(v, 0.7 * exp(-fj * 0.35) * exp(-dj * dj * 1.0));
}
fragColor = vec4(colour * v + vec3(0.01, 0.0, 0.02), 1.0);
}