#ifdef GL_ES precision mediump float; precision mediump int; #endif uniform sampler2D u_texture; uniform vec4 u_color; uniform vec2 u_texsize; uniform vec2 u_uv; uniform vec2 u_uv2; uniform float u_progress; uniform float u_time; varying vec4 v_color; varying vec2 v_texCoord; const float chunk = 4.0; const float start = 0.7; const float end = 0.9; float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } float round(float f){ return float(int(f / chunk)) * chunk; } bool id(vec2 coords, vec4 base, float basediff){ vec4 target = texture2D(u_texture, coords); return target.a < 0.1 || (coords.x < u_uv.x || coords.y < u_uv.y || coords.x > u_uv2.x || coords.y > u_uv2.y); } bool cont(vec2 T, vec2 v, float basediff){ float step = 1.0; vec4 base = texture2D(u_texture, T); return base.a > 0.1 && (id(T + vec2(0, step) * v, base, basediff) || id(T + vec2(0, -step) * v, base, basediff) || id(T + vec2(step, 0) * v, base, basediff) || id(T + vec2(-step, 0) * v, base, basediff)); } bool complete(vec2 coords){ vec2 rc = vec2(round(coords.x), round(coords.y)); float r = clamp(rand(rc) + u_progress, 0.0, 1.0); float fr = (r-start)*(1.0/(end-start)); vec2 next = rc + chunk/2.0; float rdst = max(abs(coords.x - next.x), abs(coords.y - next.y)); return rdst / (chunk/2.0) < fr; } void main() { vec2 t = v_texCoord.xy; vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y); bool any = false; vec2 coords = (v_texCoord-u_uv) / v; float value = coords.x + coords.y; vec4 color = texture2D(u_texture, t); vec2 rc = vec2(round(coords.x), round(coords.y)); vec2 center = ((u_uv + u_uv2)/2.0 - u_uv) /v; float r = clamp(rand(rc) + u_progress, 0.0, 1.0); const float scl = 10.0; float dst = (abs(center.x - coords.x) + abs(center.y - coords.y)) / 2.0; if(dst - 1.0 < u_progress * (center.x) && dst> u_progress * (center.x) && color.a > 0.1){ gl_FragColor = u_color; }else if(r > end){ gl_FragColor = color; }else if((cont(t, v, 100.0) && mod(u_time / 1.5 + value, 20.0) < 5.0 && color.a > 0.1) || (complete(coords) && (!complete(coords + vec2(1.0, 0.0)) || !complete(coords + vec2(-1.0, 0.0)) || !complete(coords + vec2(0.0, 1.0)) || !complete(coords + vec2(0.0, -1.0))))){ gl_FragColor = u_color; }else if(r > start && color.a > 0.1){ float fr = (r-start)*(1.0/(end-start)); vec2 next = rc + chunk/2.0; float rdst = max(abs(coords.x - next.x), abs(coords.y - next.y)); if(rdst / (chunk/2.0) < fr){ gl_FragColor = u_color; }else{ gl_FragColor = vec4(0.0); } }else{ gl_FragColor = vec4(0.0); } }