/******************************************************************************/
/*                                                                            */
/*       Module Name          : colour_key_ps.c                               */
/*                                                                            */
/*       Author               : S.Chapman                                     */
/*                                                                            */
/*       Comment              : Simple Pixel Shader for implementing texture  */
/*                              colour keys.                                  */
/*                                                                            */
/******************************************************************************/

/******************************************************************************/
/* Declare Constants.                                                         */
/******************************************************************************/

/******************************************************************************/
/* Declare the required Texture Stages.                                       */
/******************************************************************************/
sampler text1 : register( s0);         /* Bilinear Filtered.                  */
sampler text2 : register( s1);         /* Point Sampled.                      */

/******************************************************************************/
/* Declare the Input parameters.                                              */
/******************************************************************************/
struct PS_INPUT
{
   vector diffuse   :COLOR0;
   vector specular  :COLOR1;
   float2  text1    :TEXCOORD0;
};

/******************************************************************************/
/* Declare the Output parameters.                                             */
/******************************************************************************/
struct PS_OUTPUT
{
   vector diffuse : COLOR0;
};

/******************************************************************************/
/* Glow Pixel Shader Entry function.                                          */
/******************************************************************************/
PS_OUTPUT main( PS_INPUT  input)
{
   /* Declare and initialise the output.                                      */
   PS_OUTPUT output = ( PS_OUTPUT)0.0;

   /* Retrieve the colour values from the texture stages.                     */
   vector text_colour1 = tex2D( text1, input.text1);
   vector text_colour2 = tex2D( text2, input.text1);

   /* If the alpha value is set then the pixel is transparent.                */
   if( text_colour2.a > 0.0f)
   {
      discard;

   }                                   /* End of if( text_colour2.r == ...    */
   else
   {
      output.diffuse = ( text_colour1 * input.diffuse) + input.specular;
      output.diffuse.a = input.diffuse.a;

   }                                   /* End of ..else( text_colour2.r == ...*/

   return output;

}                                      /* End of main.                        */
