precision highp float; varying vec2 textureCoordinate; uniform sampler2D from; uniform sampler2D to; uniform float progress; vec4 getFromColor(vec2 uv) { return texture2D(from,uv); } vec4 getToColor(vec2 uv){ return texture2D(to,uv); } #define PI 3.14159265358979323 #define POW2(X) X*X #define POW3(X) X*X*X int endx = 2; int endy = -1; float Rand(vec2 v) { return fract(sin(dot(v.xy ,vec2(12.9898,78.233))) * 43758.5453); } vec2 Rotate(vec2 v, float a) { mat2 rm = mat2(cos(a), -sin(a), sin(a), cos(a)); return rm*v; } float CosInterpolation(float x) { return -cos(x*PI)/2.+.5; } vec4 transition(vec2 uv) { vec2 p = uv.xy / vec2(1.0).xy - .5; vec2 rp = p; float rpr = (progress*2.-1.); float z = -(rpr*rpr*2.) + 3.; float az = abs(z); rp *= az; rp += mix(vec2(.5, .5), vec2(float(endx) + .5, float(endy) + .5), POW2(CosInterpolation(progress))); vec2 mrp = mod(rp, 1.); vec2 crp = rp; bool onEnd = int(floor(crp.x))==endx&&int(floor(crp.y))==endy; if(!onEnd) { float ang = float(int(Rand(floor(crp))*4.))*.5*PI; mrp = vec2(.5) + Rotate(mrp-vec2(.5), ang); } if(onEnd || Rand(floor(crp))>.5) { return getToColor(mrp); } else { return getFromColor(mrp); } } void main(){ gl_FragColor = transition(textureCoordinate); }