varying vec4 vert1, vert2, vert3, vert4;
varying vec4 tc12, tc34;

uniform sampler2D Heightmap;
uniform float WaveHeight;
 
void main()
{	
	vec3 p1 = vert1.xyz;
	vec3 p2 = vert2.xyz;
	vec3 p3 = vert3.xyz;
	vec3 p4 = vert4.xyz;
			 	
	vec4 h = texture2D(Heightmap, tc12.xy);
	if (h.a == 0.0)
	    discard;
	p1.z = h.r * WaveHeight;
	p2.z = texture2D(Heightmap, tc12.zw).r * WaveHeight;
	p3.z = texture2D(Heightmap, tc34.xy).r * WaveHeight;
	p4.z = texture2D(Heightmap, tc34.zw).r * WaveHeight;
		 		 
	gl_FragColor.rgb = (h.b * normalize(cross(p3-p4, p1-p2))+1.0) * 0.5;
	gl_FragColor.a = h.g;

//gl_FragColor = vec4(texture2D(Heightmap, tc12.xy).r);

	//gl_FragColor = texture2D(Noise, vert1.xy);
//	t = ((tc1.xy / tc1.w) + 1.0) * 0.5;
//	gl_FragColor = texture2D(Heightmap, t);
	
/*	vec2 t = tc12.zw;
	if ((t.x < 0.0) || (t.x > 1.0) || (t.y < 0.0) || (t.y > 1.0))
		gl_FragColor = vec4(0.0);
	else	 
		gl_FragColor = vec4(1.0);*/
		
/*	if ((pos.x < -1.0) || (pos.x > 1.0) || (pos.y < -1.0) || (pos.y > 1.0))
		gl_FragColor = vec4(0.0);
	else	 
		gl_FragColor = vec4(1.0); */
}
