//The Bonk Animated Refraction Shader PIXEL

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

void main (void)
{
	vec2 displacement;
	float scaledTimer;
	displacement = gl_TexCoord[0].st;
	scaledTimer = timer*0.05;
	displacement.x += scaledTimer;
	displacement.y -= scaledTimer;

	vec3 noiseVec = normalize(texture2D(normalMap, displacement.xy).xyz);
	noiseVec = (noiseVec * 2.0 - 1.0) * 0.035;
	
	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;
}

