/******************************************************************************/
/*                                                                            */
/*       Module Name          : terrain_ps.c                                  */
/*                                                                            */
/*       Author               : S.Chapman                                     */
/*                                                                            */
/*       Comment              : Simple Pixel Shader for blending the textures */
/*                              on the fractal planets.                       */
/*                                                                            */
/******************************************************************************/

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

/******************************************************************************/
/* Declare the required Texture Stages.                                       */
/******************************************************************************/
sampler text1 : register( s0);         /* Colour Map.                         */
sampler text2 : register( s1);         /* Detail Map.                         */
sampler text3 : register( s2);         /* Detail Map.                         */

/******************************************************************************/
/* Declare the Input parameters.                                              */
/******************************************************************************/
struct PS_INPUT
{
   vector  diffuse   :COLOR0;
   vector  specular  :COLOR1;
   float2  text1     :TEXCOORD1;       /* Detail Map coordinates.             */
   float2  text2     :TEXCOORD2;       /* Colour Map coordinates.             */
};

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

/******************************************************************************/
/* Terrain 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 Colour map and detail map textures. */
   vector text_colour1 = tex2D( text1, input.text2);
   vector text_colour2 = tex2D( text2, input.text1);
   vector text_colour3 = tex2D( text3, input.text1);

   /* Determine the Colour of the output.                                     */
   output.diffuse = text_colour2 * input.diffuse.a;
   output.diffuse += ( text_colour3 * ( 1.0f - input.diffuse.a));
   output.diffuse.rgb *= ( text_colour1.rgb * ( input.diffuse.rgb));

   output.diffuse.rgb += input.specular;

   return output;

}                                      /* End of main.                        */
