
#define MAX_ITER 16

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


// 0 = time
// 1 = mouse X
// 2 = mouse Y
// 3 = line weight
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 v_texCoord = gl_TexCoord[0].st;

	vec2 p =  v_texCoord * 2.0 - vec2(20.0);
	vec2 i = p;
	float c = 1.0;
	float inten = .05;

	float r;

	for (int n = 0; n < MAX_ITER; n++)
	{
		float t = aaa_fu_float[0] * (1.0 - (1.0 / float(n+1)));

		i = p + vec2(cos(t - i.x) + sin(t + i.y) * cos(t * 2. + i.x),
					 sin(t - i.y) + cos(t / (i / 3.) + i.y));
					
		c += 1.4/length(vec2(p.x / (sin(i.x+t)/inten),
							 p.y / (cos(i.y+t)/inten)));

		r += pow(i.x * i.y, 0.02);
	}

	r /= float(MAX_ITER);
	c /= float(MAX_ITER);
	c = 1.5 - sqrt(c);

	vec4 texColor = vec4(0.01 - 0.05 * cos(aaa_fu_float[0] / 2.0) , 0.015 + 0.05 * sin(aaa_fu_float[0] / 2.0), 0.015 + 0.05 * c, 1.0);

	texColor.rgb *= (1.0 / (1.0 - (c + 0.05)));

	vec4 col = (texColor * 2.0);

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

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




