Skip to content

Instantly share code, notes, and snippets.

@luruke
Last active October 25, 2019 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luruke/cea5edb5afddf2189de6e79d82e1c928 to your computer and use it in GitHub Desktop.
Save luruke/cea5edb5afddf2189de6e79d82e1c928 to your computer and use it in GitHub Desktop.
precision highp float;
uniform float uTime;
uniform sampler2D texture;
uniform sampler2D uWind;
uniform sampler2D uTrail;
void main() {
float pixelHeight = 1.0 / RESOLUTION.y;
float pixelWidth = 1.0 / RESOLUTION.x;
vec2 uv = gl_FragCoord.xy / RESOLUTION.xy;
vec4 current = texture2D(texture, uv);
vec4 wind = texture2D(uWind, uv);
vec4 trail = texture2D(uTrail, uv);
// Initial set
// We use the alpha as simple boolean flag to set initial value.
// x y are the actual value
// z is the vertical speed / direction per column
if (current.a <= 0.9) {
current = vec4(uv, 0.0, 1.0);
}
// Lookup against the static texture
if (current.y < wind.y) {
current.z = wind.y - current.y;
current.y += 0.05 * pow(current.z, 2.0);
}
// Noise and mouse trail will influence the speed/direction
float t = trail.r * 0.1;
float x = (uv.x * 2.0) + uTime * 0.20;
float noise = (sin(x) + sin(2.2 * x + 5.52) + sin(2.9 * x + 0.93) + sin(4.6 * x + 8.94)) / 4.0;
noise *= 0.3;
t = mix(t, t + noise, 0.1);
t = clamp(t, 0.0, 1.0);
current.xy = mix(current.xy, uv, t);
gl_FragColor = current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment