/******************************************************************************/
/*                                                                            */
/*       Module Name          : glow_ps.c                                     */
/*                                                                            */
/*       Author               : S.Chapman                                     */
/*                                                                            */
/*       Comment              : Simple Pixel Shader for implementing glowing  */
/*                              points within a texture such as windows on    */
/*                              building at night.                            */
/*                                                                            */
/******************************************************************************/

/******************************************************************************/
/* Declare Constants.                                                         */
/******************************************************************************/
vector  daylight_colour : register( c0) = { 0.31f, 0.5f, 0.67f, 1.0f};

/******************************************************************************/
/* Declare the required Texture Stages.                                       */
/******************************************************************************/
sampler text1 : register( s0);

/******************************************************************************/
/* 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;

   /* Retrieve the colour values from the first texture stage.                */
   vector text_colour = tex2D( text1, input.text1);

   /* If the Colours match the Colour Key then adopt the glow colour value,   */
   /* otherwise adopt the texture colour, lighting it as required.            */
   if(( text_colour.r == 0.0f)&&
      ( text_colour.g == 0.0f)&&
      ( text_colour.b == 0.0f))
   {
      output.diffuse = ( daylight_colour * input.diffuse) + input.specular;

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

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

   return output;

}                                      /* End of main.                        */
