Skip to content

Instantly share code, notes, and snippets.

@corporateshark
Forked from glslioadmin/TEMPLATE.glsl
Created May 21, 2014 14:45
Show Gist options
  • Save corporateshark/21d2fdd24c706952dc8c to your computer and use it in GitHub Desktop.
Save corporateshark/21d2fdd24c706952dc8c to your computer and use it in GitHub Desktop.
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
/*
(C) Sergey Kosarevsky, 2014
Available under the terms of MIT license
http://www.linderdaum.com
http://blog.linderdaum.com
*/
void main(void)
{
vec2 p = gl_FragCoord.xy / resolution.xy;
float T = progress;
float S0 = 1.0;
float S1 = 50.0;
float S2 = 1.0;
// 2 segments, 1/2 each
float Half = 0.5;
float PixelSize = ( T < Half ) ? mix( S0, S1, T / Half ) : mix( S1, S2, (T-Half) / Half );
vec2 D = PixelSize / resolution.xy;
// remap UV from 0...1 to -0.5...+0.5 to make the mosaic pattern converge torwards the image center
vec2 UV = ( p + vec2( -0.5 ) ) / D;
// don't forget to remap coords back to 0...1 after ceil()
vec2 Coord = clamp( D * ( ceil( UV + vec2( -0.5 ) ) ) + vec2( 0.5 ), vec2( 0.0 ), vec2( 1.0 ) );
vec4 C0 = texture2D( from, Coord );
vec4 C1 = texture2D( to, Coord );
gl_FragColor = mix( C0, C1, T );
}
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