-
-
Save gre/ee15128c2b87d0e74dee to your computer and use it in GitHub Desktop.
GLSL.io Transition (v1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef GL_ES | |
precision highp float; | |
#endif | |
uniform sampler2D from, to; | |
uniform float progress; | |
uniform vec2 resolution; | |
uniform float persp; | |
uniform float unzoom; | |
uniform float reflection; | |
uniform float floating; | |
vec2 project (vec2 p) { | |
return p * vec2(1.0, -1.2) + vec2(0.0, -floating/100.); | |
} | |
bool inBounds (vec2 p) { | |
return all(lessThan(vec2(0.0), p)) && all(lessThan(p, vec2(1.0))); | |
} | |
vec4 bgColor (vec2 p, vec2 pfr, vec2 pto) { | |
vec4 c = vec4(0.0, 0.0, 0.0, 1.0); | |
pfr = project(pfr); | |
if (inBounds(pfr)) { | |
c += mix(vec4(0.0), texture2D(from, pfr), reflection * mix(1.0, 0.0, pfr.y)); | |
} | |
pto = project(pto); | |
if (inBounds(pto)) { | |
c += mix(vec4(0.0), texture2D(to, pto), reflection * mix(1.0, 0.0, pto.y)); | |
} | |
return c; | |
} | |
// p : the position | |
// persp : the perspective in [ 0, 1 ] | |
// center : the xcenter in [0, 1] \ 0.5 excluded | |
vec2 xskew (vec2 p, float persp, float center) { | |
float x = mix(p.x, 1.0-p.x, center); | |
return ( | |
( | |
vec2( x, (p.y - 0.5*(1.0-persp) * x) / (1.0+(persp-1.0)*x) ) | |
- vec2(0.5-distance(center, 0.5), 0.0) | |
) | |
* vec2(0.5 / distance(center, 0.5) * (center<0.5 ? 1.0 : -1.0), 1.0) | |
+ vec2(center<0.5 ? 0.0 : 1.0, 0.0) | |
); | |
} | |
void main() { | |
vec2 op = gl_FragCoord.xy / resolution.xy; | |
float uz = unzoom * 2.0*(0.5-distance(0.5, progress)); | |
vec2 p = -uz*0.5+(1.0+uz) * op; | |
vec2 fromP = xskew( | |
(p - vec2(progress, 0.0)) / vec2(1.0-progress, 1.0), | |
1.0-mix(progress, 0.0, persp), | |
0.0 | |
); | |
vec2 toP = xskew( | |
p / vec2(progress, 1.0), | |
mix(pow(progress, 2.0), 1.0, persp), | |
1.0 | |
); | |
if (inBounds(fromP)) { | |
gl_FragColor = texture2D(from, fromP); | |
} | |
else if (inBounds(toP)) { | |
gl_FragColor = texture2D(to, toP); | |
} | |
else { | |
gl_FragColor = bgColor(op, fromP, toP); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"persp":0.7,"unzoom":0.3,"reflection":0.4,"floating":3} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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