// force vc7 to group all shader related stuff into the Shader namespace
#ifdef WIN32
namespace Shader {
#endif

// define inputs from vertex program
struct in_fragment
{
  float4 texCoord0 : TEXCOORD0;
  float3 normal    : TEXCOORD1;
  float3 vertexPos : TEXCOORD2;
};

// define outputs from fragment program
struct out_fragment
{
  float4 color : COLOR0;
};

// fragment program
out_fragment main
(
 // varying parameters
 in_fragment f_in,
 
 // uniform samplers (textures)
 uniform sampler2D diffuseMap : TEXUNIT0,

 uniform float4 lightPosition0,   // object space
  uniform float4 lightDiffuse0,
  uniform float4 lightSpecular0,

  uniform float4 eyePosition,      // object space
  uniform float4 globalAmbient

 )
 {
   out_fragment f_out;

   // light 0
   // diffuse contribution
   //f_in.normal = normalize(f_in.normal);
   float diffuse = saturate(dot(f_in.normal.xyz,lightPosition0.xyz));
   
   // specular contribution
   float3 V = normalize(eyePosition.xyz - f_in.vertexPos.xyz);
   float3 H = normalize(lightPosition0.xyz + V);
   float shininess = 100;
   float specular = pow(max(dot(f_in.normal.xyz,H),0),shininess);
   
   //if(diffuse <= 0) specular = 0;
   globalAmbient.xyz = 0.3.xxx;
      
   f_out.color.xyz = (lightDiffuse0.xyz * diffuse)+ (specular*lightSpecular0.xyz) + globalAmbient.xyz;
   f_out.color    *= tex2D(diffuseMap, f_in.texCoord0.xy);
   
   return f_out;
 }

#ifdef WIN32
}
#endif

