/******************************************************************************/
/*                                                                            */
/*       Module Name          : glow_ps.c                                     */
/*                                                                            */
/*       Author               : S.Chapman                                     */
/*                                                                            */
/*       Comment              : Simple Pixel Shader for implementing ripple   */
/*                              effects.                                      */
/*                                                                            */
/******************************************************************************/


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

/******************************************************************************/
/* Declare the Wave contant.                                                  */
/* Wave.x = Length - multiple of 2PI.                                         */
/* Wave.y = Amplitude.                                                        */
/* Wave.z = time1 - value 0 - 1.                                              */
/******************************************************************************/
vector  wave1       : register( c0);
vector  wave2       : register( c1);

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

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

   /* Offset the Texture coordinates using Sine functions to produce the      */
   /* Ripple.                                                                 */
   text_coord.x = input.text1.x+ (sin((input.text1.y+wave1.z)*wave1.x)*wave1.y); 
   text_coord.y = input.text1.y+ (sin((input.text1.x+wave2.z)*wave2.x)*wave2.y); 

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

   /* Determine the Colour of the Output pixel.                               */
   output.diffuse = ( text_colour1 * input.diffuse) + input.specular;
   output.diffuse.a = input.diffuse.a;

   return output;

}                                      /* End of main.                        */
