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


// 0 = time
// 1 = mouse X
// 2 = mouse Y
uniform float		aaa_fu_float[6];

// 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)
{
	vec3 c[9];
	for (int i=0; i < 3; ++i)
	{
		for (int j=0; j < 3; ++j)
		{
			c[3*i+j] = texture2D(aaa_tex2d[0], (gl_TexCoord[0].st * ((vec2(i-1,j-1))))).rgb;
		}
	}

	vec3 Lx = 2.0*(c[7]-c[1]) + c[6] + c[8] - c[2] - c[0];
	vec3 Ly = 2.0*(c[3]-c[5]) + c[6] + c[0] - c[2] - c[8];
	vec3 G  = sqrt(Lx*Lx+Ly*Ly);


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

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