float4x4 WvpXf     : WorldViewProjection	< string UIWidget="None"; >;
float4x4 WorldXf   : World					< string UIWidget="None"; >;
uniform float3 globalAmbient;
uniform float3 lightColor;
uniform float3 lightPosition;
uniform float3 eyePosition;
uniform float3 Ke;
uniform float3 Ka;
uniform float3 Kd;
uniform float3 Ks;
uniform float  shininess;

struct VertexInput
{
	float4 position  : POSITION;
	float3 normal    : NORMAL;
	float2 texCoord : TEXCOORD0;
};


struct VertexOutput {
  float4 position : POSITION;
  float3 color    : COLOR;
  float2 texCoord : TEXCOORD0;
};



VertexOutput BasicLight(in VertexInput IN)
{
  VertexOutput OUT;
  
  float4 modelPos = float4(IN.position.xyz, 1);
  OUT.position = mul(modelPos, WvpXf);
  
  
  float3 P = mul(float4(IN.position.xyz, 1), WorldXf);;
  float3 N = mul(float4(IN.normal, 0), WorldXf);
  
  // Compute emissive term
  float3 emissive = Ke;

  // Compute ambient term
  //float3 ambient = Ka * globalAmbient;
  float3 ambient = Ka;
	
  // Compute the diffuse term
  float3 L = normalize(lightPosition - P);
  float diffuseLight = max(dot(N, L), 0);
  float3 diffuse = Kd * lightColor * diffuseLight;

  // Compute the specular term
  float3 V = normalize(eyePosition - P);
  float3 H = normalize(L + V);
  float specularLight = pow(max(dot(N, H), 0), shininess);
  if (diffuseLight <= 0) specularLight = 0;
  float3 specular = Ks * lightColor * specularLight;

  OUT.color = emissive + ambient + diffuse + specular;
  OUT.texCoord = IN.texCoord;
  
  return OUT;
}
