//
// Projective textures - fragment
// NOTES:
// - uses diffuseMap (tex0) to add alpha, in order to be able
// to light alpha-blended texturemaps. Those must always be the
// first layer/texture in a Racer shader.
//

void main(float2 texCoord : TEXCOORD0,
  float4 texCoordProj    : TEXCOORD1,
  //float4 diffuseLighting : COLOR,
  float  fallOff         : TEXCOORD2,	// Light fall-off

  out float4 color : COLOR,
  
  uniform sampler2D   diffuseMap      : TEXUNIT0,
  uniform sampler2D   projectiveMap   : TEXUNIT1
)
{
  // Fetch color from the projective texture
  float4 textureColor;
  float4 diffuseColor;
  
  // Extract alpha & color of lit texture
  diffuseColor=tex2D(diffuseMap,texCoord);

  // Reverse projection?  
  if(texCoordProj.w>0)textureColor=0;
  else                textureColor=tex2Dproj(projectiveMap,texCoordProj);
  
  // Racer 0.7.1 (8-1-09)
  //diffuseLighting=1.0;
  //color=textureColor*diffuseLighting*diffuseColor.a;
  
  // Some1 (9-1-09)
  const float diffuseLighting=0.6;
  //const float diffuseLighting=1.1;
  color=diffuseColor*diffuseLighting*textureColor*fallOff;
//color=fallOff;
//color.rgb=1;
//color.a=fallOff;
}
