Skip to content

Instantly share code, notes, and snippets.

@pthrasher
Forked from glslioadmin/TEMPLATE.glsl
Last active August 29, 2015 14:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pthrasher/8e6226b215548ba12734 to your computer and use it in GitHub Desktop.
Save pthrasher/8e6226b215548ba12734 to your computer and use it in GitHub Desktop.
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
#define M_PI 3.14159265358979323846 /* pi */
// General parameters
uniform sampler2D from;
uniform sampler2D to;
uniform float progress;
uniform vec2 resolution;
uniform float smoothness;
const vec2 center = vec2(0.5, 0.5);
float quadraticInOut(float t) {
float p = 2.0 * t * t;
return t < 0.5 ? p : -p + (4.0 * t) - 1.0;
}
float linearInterp(vec2 range, vec2 domain, float x) {
return mix(range.x, range.y, smoothstep(domain.x, domain.y, clamp(x, domain.x, domain.y)));
}
float getGradient(float r, float dist) {
float grad = smoothstep(-smoothness, 0.0, r - dist * (1.0 + smoothness)); //, 0.0, 1.0);
if (r - dist < 0.005 && r - dist > -0.005) {
return -1.0;
} else if (r - dist < 0.01 && r - dist > -0.005) {
return -2.0;
}
return grad;
}
float round(float a) {
return floor(a + 0.5);
}
float getWave(vec2 p){
// I'd really like to figure out how to make the ends meet on my circle.
// The left side is where the ends don't meet.
vec2 _p = p - center; // offset from center
float rads = atan(_p.y, _p.x);
float degs = degrees(rads) + 180.0;
vec2 range = vec2(0.0, M_PI * 30.0);
vec2 domain = vec2(0.0, 360.0);
float ratio = (M_PI * 30.0) / 360.0;
//degs = linearInterp(range, domain, degs);
degs = degs * ratio;
float x = progress;
float magnitude = mix(0.02, 0.09, smoothstep(0.0, 1.0, x));
float offset = mix(40.0, 30.0, smoothstep(0.0, 1.0, x));
float ease_degs = quadraticInOut(sin(degs));
float deg_wave_pos = (ease_degs * magnitude) * sin(x * offset);
return x + deg_wave_pos;
}
void main() {
vec2 p = gl_FragCoord.xy / resolution.xy;
if (progress == 0.0) {
gl_FragColor = texture2D(from, p);
} else if (progress == 1.0) {
gl_FragColor = texture2D(to, p);
} else {
float dist = distance(center, p);
float m = getGradient(getWave(p), dist);
if (m == -2.0) {
//gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
//gl_FragColor = mix(texture2D(from, p), texture2D(to, p), -1.0);
gl_FragColor = mix(texture2D(from, p), vec4(0.0, 0.0, 0.0, 1.0), 0.75);
} else {
gl_FragColor = mix(texture2D(from, p), texture2D(to, p), m);
}
}
}
{"smoothness":0.02}
GLSL.io Transition License (v1):
The MIT License (MIT)
Copyright (C) 2014 contact@glsl.io
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.
@gre
Copy link

gre commented Jan 5, 2015

impressive work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment