//The Bonk Uber-Shader PIXEL

uniform vec4 ambientColor;
uniform sampler2D colorMap;
uniform sampler2D alphaMap;
//uniform sampler2D bgMap;
uniform int useColorAlpha;
uniform float timer;
uniform float uSpeed;
uniform float vSpeed;

void main()
{
	//Calculate UV animation
	vec2 displacement = gl_TexCoord[0].st;
	displacement.x += timer*uSpeed;
	displacement.y += timer*vSpeed;

	//Fetch color map texel
	vec4 texColor = texture2D(colorMap,displacement.xy);
	
	if (useColorAlpha == 1)
	{
		//Use alpha map for alpha
		texColor.a = texture2D(alphaMap,gl_TexCoord[0].st).a;
	}else
	{
		//Multiply color-alpha by alpha-alpha
		texColor.a = texColor.a * texture2D(alphaMap,gl_TexCoord[0].st).a;	
	}


	//vec4 bgColor   = texture2D(bgMap, gl_FragCoord.xy/textureSize(bgMap, 0);
 	//vec4 bgColor   = texture2D(bgMap, gl_TexCoord[0].st);
    	//vec4 thisColor = texColor * ambientColor;
    	//gl_FragColor = mix(thisColor,bgColor , thisColor.a);

	gl_FragColor = texColor * ambientColor;
}
