#version 120
uniform sampler2D iChannel0;

uniform sampler2D faceMaskTexture;
uniform sampler2D noiseTexture;

uniform float timer;
uniform float easedTime;
uniform float radius;

uniform float randomValue;

uniform vec2 size;

uniform vec2 faceMaskSize;

#include "shaders/logic.glsl"

const float TAU = 6.28318530718;

void main()
{
	vec2 position = floor((gl_TexCoord[0].xy - 0.5)*size + 0.5);

	float face = texture2D(faceMaskTexture,position/faceMaskSize + 0.5).r;

	float angle = atan(position.y,position.x);
	float noise = texture2D(noiseTexture,vec2(mod(angle/TAU*4.0,1.0),mod(randomValue + 0.25*timer,1.0))).r;

	vec2 diff = position/(radius*easedTime);

	float spike = mod(angle/TAU*10.0 + randomValue,1.0);
	float dist = length(diff)/(1.0 - (0.25*min(spike,1.0 - spike)*easedTime*2.0 - 0.1*noise));

	gl_FragColor = texture2D(iChannel0,vec2(1.0 - pow(dist,3.0),face));
	gl_FragColor *= le(dist,1.0);
	gl_FragColor *= gt(1.0 - (1.0 - dist)*0.4,easedTime);

	gl_FragColor *= gl_Color;
}