Skip to content

Instantly share code, notes, and snippets.

@TimDonselaar
Forked from glslioadmin/TEMPLATE.glsl
Last active November 21, 2019 04:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimDonselaar/9bcd1c4b5934ba60087bdb55c2ea92e5 to your computer and use it in GitHub Desktop.
Save TimDonselaar/9bcd1c4b5934ba60087bdb55c2ea92e5 to your computer and use it in GitHub Desktop.
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
// General parameters
uniform sampler2D from;
uniform sampler2D to;
uniform float progress;
uniform vec2 resolution;
// Custom parameters
uniform ivec2 size;
uniform float pause;
uniform float dividerSize;
const vec4 dividerColor = vec4(0.0, 0.0, 0.0, 1.0);
const float randomOffset = 0.1;
float rand (vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float getDelta(vec2 p) {
vec2 rectanglePos = floor(vec2(size) * p);
vec2 rectangleSize = vec2(1.0 / vec2(size).x, 1.0 / vec2(size).y);
float top = rectangleSize.y * (rectanglePos.y + 1.0);
float bottom = rectangleSize.y * rectanglePos.y;
float left = rectangleSize.x * rectanglePos.x;
float right = rectangleSize.x * (rectanglePos.x + 1.0);
float minX = min(abs(p.x - left), abs(p.x - right));
float minY = min(abs(p.y - top), abs(p.y - bottom));
return min(minX, minY);
}
float getDividerSize() {
vec2 rectangleSize = vec2(1.0 / vec2(size).x, 1.0 / vec2(size).y);
return min(rectangleSize.x, rectangleSize.y) * dividerSize;
}
void showDivider (vec2 p) {
float currentProg = progress / pause;
float a = 1.0;
if(getDelta(p) < getDividerSize()) {
a = 1.0 - currentProg;
}
gl_FragColor = mix(dividerColor, texture2D(from, p), a);
}
void hideDivider (vec2 p) {
float currentProg = (progress - 1.0 + pause) / pause;
float a = 1.0;
if(getDelta(p) < getDividerSize()) {
a = currentProg;
}
gl_FragColor = mix(dividerColor, texture2D(to, p), a);
}
void main() {
vec2 p = gl_FragCoord.xy / resolution.xy;
if(progress < pause) {
showDivider(p);
} else if(progress < 1.0 - pause){
if(getDelta(p) < getDividerSize()) {
gl_FragColor = dividerColor;
} else {
float currentProg = (progress - pause) / (1.0 - pause * 2.0);
vec2 q = p;
vec2 rectanglePos = floor(vec2(size) * q);
float r = rand(rectanglePos) - randomOffset;
float cp = smoothstep(0.0, 1.0 - r, currentProg);
float rectangleSize = 1.0 / vec2(size).x;
float delta = rectanglePos.x * rectangleSize;
float offset = rectangleSize / 2.0 + delta;
p.x = (p.x - offset)/abs(cp - 0.5)*0.5 + offset;
vec4 a = texture2D(from, p);
vec4 b = texture2D(to, p);
float s = step(abs(vec2(size).x * (q.x - delta) - 0.5), abs(cp - 0.5));
gl_FragColor = vec4(mix(b, a, step(cp, 0.5)).rgb * s, 1.0);
}
} else {
hideDivider(p);
}
}
{"size":[4,4],"pause":0.1,"dividerSize":0.05}
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment