diff --git a/resources/shaders/apparition.frag b/resources/shaders/apparition.frag index 6b87d2a..f4193a1 100644 --- a/resources/shaders/apparition.frag +++ b/resources/shaders/apparition.frag @@ -23,8 +23,6 @@ uniform float uRandomness; const float ACTOR_SCALE = 2.0; const float PADDING = ACTOR_SCALE / 2.0 - 0.5; -// The math for the whirling is inspired by this post: -// http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl void main() { // We simply inverse the progress for opening windows. float progress = uForOpening ? 1.0 - uProgress : uProgress; @@ -44,10 +42,7 @@ void main() { coords += progress * coords / dist * 0.5 * uSuction; // Apply some whirling. - float angle = pow(1.0 - dist, 2.0) * uTwirl * progress; - float s = sin(angle); - float c = cos(angle); - coords = vec2(dot(coords, vec2(c, -s)), dot(coords, vec2(s, c))); + coords = whirl(coords, uTwirl * progress, 0.0); // Fade out the window texture. vec4 oColor = getInputColor(coords + center); diff --git a/resources/shaders/common.glsl b/resources/shaders/common.glsl index 0201fe2..62a5d54 100644 --- a/resources/shaders/common.glsl +++ b/resources/shaders/common.glsl @@ -183,6 +183,15 @@ float getRelativeEdgeMask(float fadeAmount) { // ------------------------------------------------------------------------------- 2D math +// The math for the whirling is inspired by this post: +// http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl +vec2 whirl(vec2 coords, float warping, float rotation) { + float angle = pow(1.0 - length(coords), 2.0) * warping + rotation; + float s = sin(angle); + float c = cos(angle); + return vec2(dot(coords, vec2(c, -s)), dot(coords, vec2(s, c))); +} + // Returns the shortest distance between the given point and the line defined by "origin" // and "direction". float distToLine(vec2 origin, vec2 direction, vec2 point) {