uniform vec3 n00, n01, n11, n10, f00, f01, f11, f10;
uniform float Base;
varying vec2 TexCoord;

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()
{
	gl_Position = gl_ModelViewProjectionMatrix * MixVert(gl_Vertex);
	
	TexCoord = gl_Vertex.xy;
}