-
-
Save zeh/a830822b23e846e25d2d 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 | |
// Definitions -------- | |
#define DEG2RAD 0.03926990816987241548078304229099 // 1/180*PI | |
// Hardcoded parameters -------- | |
uniform sampler2D from, to; | |
uniform float progress; | |
uniform vec2 resolution; | |
// Transition parameters -------- | |
// default rotation = 6 | |
uniform float rotation; // In degrees | |
// default scale = 1.2 | |
uniform float scale; // Multiplier | |
// The code proper -------- | |
void main() { | |
// Massage parameters | |
float phase = progress < 0.5 ? progress * 2.0 : (progress - 0.5) * 2.0; | |
float angleOffset = progress < 0.5 ? mix(0.0, rotation * DEG2RAD, phase) : mix(-rotation * DEG2RAD, 0.0, phase); | |
float newScale = progress < 0.5 ? mix(1.0, scale, phase) : mix(scale, 1.0, phase); | |
vec2 center = vec2(0, 0); | |
// Calculate | |
float maxRes = max(resolution.x, resolution.y); | |
float resX = resolution.x / maxRes * 0.5; | |
float resY = resolution.y / maxRes * 0.5; | |
vec2 p = (gl_FragCoord.xy / maxRes - vec2(resX, resY)) / newScale; | |
// This can probably be optimized (with distance()) | |
float angle = atan(p.y, p.x) + angleOffset; | |
float dist = distance(center, p); | |
p.x = cos(angle) * dist + resX; | |
p.y = sin(angle) * dist + resY; | |
vec4 c = progress < 0.5 ? texture2D(from, p) : texture2D(to, p); | |
// Finally, apply the color | |
gl_FragColor = c + (progress < 0.5 ? mix(0.0, 1.0, phase) : mix(1.0, 0.0, phase)); | |
} |
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
{"rotation":6,"scale":1.2} |
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
Great job!
your transition works for the square rendering but there is some issue with the ratio (that you currently only see on the gallery).