float4 ambientColor  : register (c0);
float4 diffuseColor  : register (c1);
float4 worldLight    : register (c2);
float4 specularColor : register (c3); //power in c3.a

struct PS_INPUT
{
   float4 Color  : COLOR0;
#ifdef OMNISCALE
   float4 Omni   : COLOR1;
#endif
   float  Fog    : FOG;

   float2 Tex0    : TEXCOORD0; // base0
   float3 Normal  : TEXCOORD1; // world space vertex normal
   float3 EyeVec  : TEXCOORD2; // world space eye vec
};

struct PS_OUTPUT
{
   float4 Color : COLOR0;
};

sampler2D sTex0: register (s0);
sampler2D sTex1: register (s1);
sampler2D sTex2: register (s2);
 
PS_OUTPUT MAINFUNCTION (PS_INPUT Input)
{
  PS_OUTPUT Out;
  
  float4 tex = tex2D (sTex0, Input.Tex0.xy);        // sample base tex
//  tex *= tex2D (sTex1, Input.Tex0.xy);        // sample base tex
//  tex += tex2D (sTex2, Input.Tex0.xy);        // sample base tex

  float3 normal = normalize (Input.Normal);

  float3 normEyeVec = normalize (Input.EyeVec);
  
  // compute specular color
  float3 lightVec = normalize(worldLight); 
//  float3 reflected = reflect(normEyeVec, normal);

  float lightThrough = pow(max(0.0, dot(lightVec, normEyeVec)), 3.0);
  float lightInFront = pow(max(0.0, dot(-lightVec, normEyeVec)), 3.0);

  tex.rgb = lerp(tex.rgb, float3(1.1, 1.2, 0.7) * tex.rgb, lightThrough);
  tex.rgb = lerp(tex.rgb, float3(0.1, 0.1, 0.1) + tex.rgb, lightInFront);

  // compute diffuse color
  half4 diffuse = saturate(dot (worldLight, normal)) * diffuseColor * DIFFUSESCALE + ambientColor * AMBIENTSCALE;
#ifdef OMNISCALE
  diffuse = diffuse + Input.Omni * OMNISCALE;
#endif
  diffuse = saturate (diffuse);
  
  //less reflection during night
  float day = (diffuseColor.r + diffuseColor.g + diffuseColor.b) / 3.0;

  Out.Color = (tex * diffuse) * Input.Color;
  Out.Color.a = tex.a + ALPHABIAS;

  return (Out);
}
