Back to shaders
Shader test bench
Bounce.fs
runnable fragment
Complete GLSL fragment shader. Stronghold runs it directly when the browser can compile it.
Code
uniform sampler2D startImage;
uniform sampler2D endImage;
uniform float progress;
uniform float bounces;
uniform float shadow_height;
uniform vec4 shadow_colour;
precision mediump float;
/*{
"CATEGORIES": [
"Wipe"
],
"CREDIT": "Automatically converted from https://www.github.com/gl-transitions/gl-transitions/tree/master/Bounce.glsl",
"DESCRIPTION": "",
"INPUTS": [
{
"NAME": "startImage",
"TYPE": "image"
},
{
"NAME": "endImage",
"TYPE": "image"
},
{
"DEFAULT": 0,
"MAX": 1,
"MIN": 0,
"NAME": "progress",
"TYPE": "float"
},
{
"DEFAULT": 2,
"MAX": 10,
"MIN": 0,
"NAME": "bounces",
"TYPE": "float"
},
{
"DEFAULT": 0.1,
"MAX": 1,
"MIN": 0,
"NAME": "shadow_height",
"TYPE": "float"
},
{
"DEFAULT": [
0,
0,
0,
1
],
"NAME": "shadow_colour",
"TYPE": "color"
}
],
"ISFVSN": "2",
"VSN": ""
}
*/
vec4 getFromColor(vec2 inUV) {
return texture2D(startImage, inUV);
}
vec4 getToColor(vec2 inUV) {
return texture2D(endImage, inUV);
}
// Author: Adrian Purser
// License: MIT
const float PI = 3.14159265358;
vec4 transition (vec2 uv) {
float time = progress;
float stime = sin(time * PI / 2.);
float phase = time * PI * bounces;
float y = (abs(cos(phase))) * (1.0 - stime);
float d = uv.y - y;
return mix(
mix(
getToColor(uv),
shadow_colour,
step(d, shadow_height) * (1. - mix(
((d / shadow_height) * shadow_colour.a) + (1.0 - shadow_colour.a),
1.0,
smoothstep(0.95, 1., progress) // fade-out the shadow at the end
))
),
getFromColor(vec2(uv.x, uv.y + (1.0 - y))),
step(d, 0.0)
);
}
void main() {
gl_FragColor = transition((gl_FragCoord.xy / u_resolution.xy).xy);
}