//The Bonk Refract-Shader PIXEL

uniform float timer;
uniform float uSpeed;
uniform float vSpeed;
uniform vec4 bgTextureSize;
uniform vec4 ambientColor;
uniform sampler2D bgMap;
uniform sampler2D colorMap;
uniform sampler2D alphaMap;
uniform sampler2D normalMap;

void main (void)
{
	vec2 animUV = gl_TexCoord[0].st;
	animUV.x += timer*uSpeed;
	animUV.y += timer*vSpeed;

	vec3 noiseVec = normalize(texture2D(normalMap, animUV.xy).xyz);
	noiseVec = (noiseVec * 1.2 - 1.0) * 0.008;
	
	vec4 bgColor = texture2D(bgMap, (gl_FragCoord/bgTextureSize).xy + noiseVec.xy);
	vec4 mapColor =  texture2D(colorMap,gl_TexCoord[0].st+ noiseVec.xy);
	vec4 alphaColor = texture2D(alphaMap,gl_TexCoord[0].st);
	vec4 outColor = mix(mapColor,bgColor,alphaColor.a*ambientColor.a) * ambientColor;
	outColor.a = 1.0;
	gl_FragColor = outColor;
}

