Skip to content

Instantly share code, notes, and snippets.

@rectalogic
Forked from glslioadmin/TEMPLATE.glsl
Last active March 25, 2022 05:10
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rectalogic/b86b90161503a0023231 to your computer and use it in GitHub Desktop.
Save rectalogic/b86b90161503a0023231 to your computer and use it in GitHub Desktop.
GLSL.io Transition (v1)
// Converted from https://github.com/rectalogic/rendermix-basic-effects/blob/master/assets/com/rendermix/CrossZoom/CrossZoom.frag
// Which is based on https://github.com/evanw/glfx.js/blob/master/src/filters/blur/zoomblur.js
// With additional easing functions from https://github.com/rectalogic/rendermix-basic-effects/blob/master/assets/com/rendermix/Easing/Easing.glsllib
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
uniform float strength;
const float PI = 3.141592653589793;
float Linear_ease(in float begin, in float change, in float duration, in float time) {
return change * time / duration + begin;
}
float Exponential_easeInOut(in float begin, in float change, in float duration, in float time) {
if (time == 0.0)
return begin;
else if (time == duration)
return begin + change;
time = time / (duration / 2.0);
if (time < 1.0)
return change / 2.0 * pow(2.0, 10.0 * (time - 1.0)) + begin;
return change / 2.0 * (-pow(2.0, -10.0 * (time - 1.0)) + 2.0) + begin;
}
float Sinusoidal_easeInOut(in float begin, in float change, in float duration, in float time) {
return -change / 2.0 * (cos(PI * time / duration) - 1.0) + begin;
}
/* random number between 0 and 1 */
float random(in vec3 scale, in float seed) {
/* use the fragment position for randomness */
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
}
vec3 crossFade(in vec2 uv, in float dissolve) {
return mix(texture2D(from, uv).rgb, texture2D(to, uv).rgb, dissolve);
}
void main() {
vec2 texCoord = gl_FragCoord.xy / resolution.xy;
// Linear interpolate center across center half of the image
vec2 center = vec2(Linear_ease(0.25, 0.5, 1.0, progress), 0.5);
float dissolve = Exponential_easeInOut(0.0, 1.0, 1.0, progress);
// Mirrored sinusoidal loop. 0->strength then strength->0
float strength = Sinusoidal_easeInOut(0.0, strength, 0.5, progress);
vec3 color = vec3(0.0);
float total = 0.0;
vec2 toCenter = center - texCoord;
/* randomize the lookup values to hide the fixed number of samples */
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
for (float t = 0.0; t <= 40.0; t++) {
float percent = (t + offset) / 40.0;
float weight = 4.0 * (percent - percent * percent);
color += crossFade(texCoord + toCenter * percent * strength, dissolve) * weight;
total += weight;
}
gl_FragColor = vec4(color / total, 1.0);
}
GLSL.io Transition License (v1):
The MIT License (MIT)
Copyright (C) 2014 rectalogic@rectalogic.com
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