varying vec4 position;
varying vec3 normal;

varying float depthValue;

varying vec4 myColor;
varying float isTerrain;
uniform float near, far;
varying vec3 glVertex;

uniform sampler2D texture; //"farbe"

void main()
{
	//lighting
	vec3 lightVec = gl_LightSource[0].position.xyz - position.xyz;
	lightVec = normalize(lightVec);
	float cosinusAlpha = dot(normalize(normal), lightVec);
   
   vec3 R = normalize(reflect(-lightVec,normal));
   float cosTheta = max(0.0, dot(R, normalize(-position.xyz)));

	float z = (depthValue - near) / (far - near); //white = far, black = near
	//z = 1.0 - z; //würde farben invertieren, also weiß vorne schwarz hinten

	// pos in camera coordinate system before projection, -1 to differentiate rendered geometry
	gl_FragData[0] = vec4(position.xyz, -1.0); 
	// normal and linear depth 0..1
	gl_FragData[1] = vec4(normalize(normal), z);
	// color including "real" lighting
	gl_FragData[2] = /*myColor;*//*texture2D(texture, gl_TexCoord[0].st) * */vec4(0.9)*cosinusAlpha;//+ pow(cosTheta, 32.0) *vec4(0.2,0.2,0.15,1);

   return;
   if(isTerrain > 0.0)
   {
      float waterLevel = -0.3;
      vec4 color = vec4(0);//gl_Color;
      if (glVertex.y < waterLevel + 0.2)
         color = vec4(0.0,
         clamp(-glVertex.y / 2.0, 0.0, 1.0),
         1.0,
         1.0);
      else color = vec4(clamp(glVertex.y / 2.0, 0.0, 1.0),
         1.0,
         glVertex.y / 8.0,
         1.0);	

      vec4 mountainColor = vec4(0.6);//vec4(0.68, 0.56, 0.37, 0);
      vec4 grassColor = vec4(0.4); //vec4(0.41, 0.6, 0.3, 0);
      vec4 beachColor = vec4(0.2);//vec4(0.68, 0.56, 0.17, 0);

      gl_FragData[2] = (mountainColor * color.r
         + grassColor * color.g
         + beachColor * color.b
         + beachColor * clamp(waterLevel - position.y, 0.3, 0.7) * 0.3
         + grassColor * (0.5 - color.r) * (0.5 - color.g)
         ) * clamp(dot(normal, lightVec), 0.0, 1.0) * 2.0;


      //gl_FragData[2] = mix((vec4(1,1,0.5,1) * gl_Color.r
      //   + vec4(0.4,1,0.2,1) * gl_Color.g
      //   + vec4(0.4,1,0.2,1) * (0.5 - gl_Color.r) * (0.5 - gl_Color.g)
      //   ) * clamp(dot(normal, lightVec), 0.0, 1.0) * 2.0, gl_FragData[2], 0.5);
   }

}