Skip to content

Instantly share code, notes, and snippets.

@zeh
Forked from glslioadmin/TEMPLATE.glsl
Created May 23, 2014 18:00
Show Gist options
  • Save zeh/a070cbd69e2535e757f1 to your computer and use it in GitHub Desktop.
Save zeh/a070cbd69e2535e757f1 to your computer and use it in GitHub Desktop.
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
// Hardcoded parameters --------
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
// Transition parameters --------
// default barWidth = 10
uniform int barWidth; // Number of bars
// default amplitude = 2
uniform float amplitude; // 0 = no variation when going down, higher = some elements go much faster
// default noise = 0.1
uniform float noise; // 0 = no noise, 1 = super noisy
// default frequency = 1
uniform float frequency; // the bigger the value, the shorter the waves
// The code proper --------
float rand(int num) {
return fract(mod(float(num) * 67123.313, 12.0) * sin(float(num) * 10.3) * cos(float(num)));
}
float wave(int num) {
float fn = float(num) * frequency * 0.1 * float(barWidth);
return cos(fn * 0.5) * cos(fn * 0.13) * sin((fn+10.0) * 0.3) / 2.0 + 0.5;
}
float pos(int num) {
return noise == 0.0 ? wave(num) : mix(wave(num), rand(num), noise);
}
void main() {
int bar = int(gl_FragCoord.x) / barWidth;
float scale = 1.0 + pos(bar) * amplitude;
float phase = progress * scale;
float posY = gl_FragCoord.y / resolution.y;
vec2 p;
vec4 c;
if (phase + posY < 1.0) {
p = vec2(gl_FragCoord.x, gl_FragCoord.y + mix(0.0, resolution.y, phase)) / resolution.xy;
c = texture2D(from, p);
} else {
p = gl_FragCoord.xy / resolution.xy;
c = texture2D(to, p);
}
// Finally, apply the color
gl_FragColor = c;
}
{"barWidth":10,"noise":0.2,"amplitude":2,"frequency":1}
GLSL.io Transition License (v1):
The MIT License (MIT)
Copyright (C) 2014 [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment