//
// Diffuse color (demo)
//

void main(
  // In
  float3 normal : TEXCOORD1,
  float3 inPosW : TEXCOORD2,
  // Out
  out float4 outColor : COLOR,
  uniform float3 lightDirection,
  uniform float3 eyePosW
)
{
  const float Ka=0.1;
  const float Kd=0.6;
  const float Ks=1.0;
  const float shininess=10.0;
  const float3 lightColor=float3(1,1,1);
  
  // Note that 'normal' is interpolated across the triangle, so it may not be normalized
  float3 N=normalize(normal);
  
  // Compute diffuse term
  float3 L=normalize(lightDirection);
  float diffuseLight=max(dot(N,L),0);
  float3 diffuse=Kd*diffuseLight;			// Colorize?

  // Ambient light
  float ambient=Ka;
  
  // Compute the specular term
  float3 V=normalize(eyePosW - inPosW);
  float3 H=normalize(L + V);

  float specularLight;
  if (diffuseLight <= 0)
    specularLight=0;
  else
    specularLight=pow(max(dot(N,H),0),shininess);

  float3 specular=Ks*lightColor*specularLight;

  // Output total color
  outColor.rgb=diffuse+ambient+specular;
  //outColor.rgb=specular;
  outColor.a=1;
}
