varying vec2 	texcoord;

// TERRAIN RELATED
uniform sampler2D	heightmap;
uniform float		terrainHeight; // width, depth and height of the terrain
uniform float		terrainNormOrg;
uniform float		waterY;
uniform float		tofs;
////////////////////

void main()
{	
	float flow;
	flow=max(waterY-(texture2D(heightmap,texcoord).x-terrainNormOrg)*terrainHeight,0.0);
	
	// build flow map (SOBEL)
	/*float tleft=max(waterY-(texture2D(heightmap,texcoord+vec2(-tofs,tofs)).x-terrainNormOrg)*terrainHeight,0.0);
	float left=max(waterY-(texture2D(heightmap,texcoord+vec2(-tofs,0.0)).x-terrainNormOrg)*terrainHeight,0.0);
	float bleft=max(waterY-(texture2D(heightmap,texcoord+vec2(-tofs,-tofs)).x-terrainNormOrg)*terrainHeight,0.0);
	
	float top=max(waterY-(texture2D(heightmap,texcoord+vec2(0.0,tofs)).x-terrainNormOrg)*terrainHeight,0.0);
	float bottom=max(waterY-(texture2D(heightmap,texcoord+vec2(0.0,-tofs)).x-terrainNormOrg)*terrainHeight,0.0);
	
	float tright=max(waterY-(texture2D(heightmap,texcoord+vec2(tofs,tofs)).x-terrainNormOrg)*terrainHeight,0.0);
	float right=max(waterY-(texture2D(heightmap,texcoord+vec2(tofs,0.0)).x-terrainNormOrg)*terrainHeight,0.0);
	float bright=max(waterY-(texture2D(heightmap,texcoord+vec2(tofs,-tofs)).x-terrainNormOrg)*terrainHeight,0.0);
	
	flow.x=-(tleft + 2.0*left + bleft - tright - 2.0*right - bright);
	flow.y=-(-tleft - 2.0*top - tright + bleft + 2.0 * bottom + bright);*/
	
	gl_FragColor = vec4(flow);
}