
#define M_PI 3.141592653589793

// Uniform variables for texturing
uniform sampler2D 	aaa_tex2d[4];

// 0 = time
// 1 = mouse X
// 2 = mouse Y
// 3 = Thickness
// 4 = PI factor
uniform float		aaa_fu_float[8];

// 0 = iterations
uniform int			aaa_fu_int[4];


// balance between texture and effect
uniform float		aaa_fu_src;
uniform float		aaa_fu_out;


// Colors factors
// 0 = src colors
// 1 = out color
uniform vec4		aaa_fu_vec4[8];


void main(void)
{
	vec2 position = gl_TexCoord[0].st - 0.5;
	float a = 0.2*aaa_fu_float[0]*M_PI/3.0;
	float r = length(position);
	float c = cos(a);
	float s = sin(a);
	mat2 rotate = mat2(c,s,-s,c);
	vec2 q = sin(rotate*(position+tan(2.0*position*rotate*rotate))*3.0*(1.5+sin(aaa_fu_float[0]*0.5)/r));
	q = sqrt(abs(q)-0.1);

	vec3 color 	 = vec3(length(position+q));
	color.rg 	+= smoothstep(0.2, 0.0, abs(position.x));
	vec2 p2 	 = (position+q) * rotate;
	color.gb 	+= smoothstep(0.2, 0.0, abs(p2.x));
	vec2 p3 	 = p2 * rotate;
	color.br 	+= smoothstep(0.2, 0.0, abs(p3.x));
	vec2 p4 	 = p3 * rotate;
	color.rg 	+= smoothstep(0.2, 0.0, abs(p4.x));
	vec2 p5  	 = p4 * rotate;
	color.gb 	+= smoothstep(0.2, 0.0, abs(p5.x));
	vec2 p6 	 = p5 * rotate;
	color.br 	+= smoothstep(0.2, 0.0, abs(p6.x));
	color.g 	*= abs(position.x);
	color.b 	*= abs(p2.x);
	color.r 	*= abs(p3.x);
	color.xy 	*= rotate;
	color.yz 	*= rotate;
	color 		 = abs(color);


	vec4 src = (texture2D(aaa_tex2d[0], gl_TexCoord[0].st) * aaa_fu_src) * aaa_fu_vec4[0];
	vec4 fx  = (vec4(color, 1.0) * aaa_fu_out) * aaa_fu_vec4[1];

	gl_FragColor = vec4( (src + fx) );
}









