varying vec2 TexCoord1;
varying vec2 TexCoord2;

uniform float Base;
uniform float anim;
 
uniform vec3 n00, n01, n11, n10, f00, f01, f11, f10;
uniform float WavesInvSize1;
uniform float WavesInvSize2;

vec4 MixVert(in vec4 v)
{
	vec3 n = mix(mix(n00, n01, v.y), mix(n10, n11, v.y), v.x);
	vec3 f = mix(mix(f00, f01, v.y), mix(f10, f11, v.y), v.x);
	vec3 dir = n.xyz - f.xyz;
	vec4 ret;
	ret.xyz = ((-(n.z - Base)/dir.z) * dir) + n.xyz;
	ret.w = 1.0;
	return ret;
}

void main()
{	
	vec4 v = MixVert(gl_Vertex); //world vertex
	 	
	TexCoord1 = v.xy * WavesInvSize1 + vec2(anim);
	TexCoord2 = v.xy * WavesInvSize2 + vec2(0.0, anim);
	
    v = gl_Vertex;
	v.xy = (v.xy - 0.5) * 2.0;
	v.z = -1.0;
	v.w = 1.0;
	gl_Position = v;
}
