//
// 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,

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

  // Reverse projection?  
  if(texCoordProj.w>0)
    textureColor=0;
  else
    textureColor=tex2Dproj(projectiveMap,texCoordProj);

  diffuseLighting=1.1;
  //diffuseLighting=texCoordProj.r/texCoordProj.q;
  //color=textureColor*diffuseLighting+diffuseColor;
  //color=textureColor*diffuseLighting*diffuseColor.a;
  //color=diffuseColor;
  //color=float4(1,0,1,1);

  //color=textureColor*diffuseColor*diffuseLighting;
  color=diffuseColor*diffuseLighting*textureColor;
}
