#version 100
precision mediump float;

varying vec4 col;
varying vec3 nrm;
varying vec2 uv;

uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
//uniform float lerp;
uniform float layer;
uniform float offset;

void main()
{
//	vec4 texcol = mix(texture2D(tex0,uv),texture2D(tex1,uv),lerp);
//	vec4 envcol = texture2D(tex2,nrm.xy * 0.5 + vec2(0.5,0.5) );
//	gl_FragColor = envcol*texcol;
	float mx = mod(offset, 1.0);
	float off = (mod(offset, 4.0) - mx)/4.0;
	vec4 col = mix(	texture2D(tex0, uv + vec2(0.0, off)),
					texture2D(tex0, uv + vec2(0.0, off + 0.25)), mx);
	float px =	layer < 1.0 ?	mix(col.r, col.g, layer - 0.0):
				layer < 2.0 ?	mix(col.g, col.b, layer - 1.0):
								mix(col.b, col.a, layer - 2.0);
/*	float px =	layer < 1.0 ?	mix(col.r,col.r,layer):
				layer < 2.0 ?	col.r:
								col.b;
*/
	gl_FragColor = vec4(px);// (px < lerp) ? vec4(0.0, 0.0, 0.0, 1.0) : vec4(1.0, 1.0, 1.0, 1.0);
}
