// force vc7 to group all shader related stuff into the Shader namespace
#ifdef WIN32
namespace Shader {
#endif

// define inputs from application
struct appin
{
  float4 position   : POSITION;
};

// define outputs from vertex shader
struct vertout
{
  float4 position   : POSITION;
  float4 texCoords0 : TEXCOORD0;
  float4 texCoords1 : TEXCOORD1;
  float4 color      : COLOR0;
};

 vertout vp_main(appin v_in, 
		 uniform float4x4 TPMatrix, 
		 uniform float4x4 MVPMatrix)
{
  vertout v_out;

  // transform vertex position into homogenous clip-space
  v_out.position   = mul(MVPMatrix, v_in.position);
  v_out.texCoords0 = mul(TPMatrix, v_in.position);
  v_out.color      = 1.0.xxxx;
  v_out.texCoords1 = v_out.texCoords0;

  return v_out;
}


// define inputs from vertex program
struct in_fragment
{
  float4 color     : COLOR0;
  float4 texCoord0 : TEXCOORD0;
  float4 texCoord1 : TEXCOORD1;
};

// define outputs from fragment program
struct out_fragment
 {
   float4 color : COLOR0;
 };
 
// fragment program
 out_fragment fp_main
   (
    // varying parameters
    in_fragment f_in,
    
    // uniform samplers (textures)
    uniform sampler2D shadowMap : TEXUNIT0,
    uniform sampler2D fadeMap   : TEXUNIT1
    )
 {
   out_fragment f_out;
   
   float2 final = f_in.texCoord0.xy / f_in.texCoord0.w;
   f_out.color = tex2D(shadowMap, final) / 4.0;

   float2 temp = final;
   temp.x += 1.0/1024.0;
   f_out.color += tex2D(shadowMap, temp) / 4.0;

   temp = final;
   temp.x -= 1.0/1024.0;
   f_out.color += tex2D(shadowMap, temp) / 4.0;

   temp = final;
   temp.y += 1.0/1024.0;
   f_out.color += tex2D(shadowMap, temp) / 4.0;

   temp = final;
   temp.y -= 1.0/1024.0;
   //f_out.color += tex2D(shadowMap, temp) / 5.0;

   f_out.color += tex2Dproj(fadeMap, f_in.texCoord1);
   //f_out.color = tex2Dproj(fadeMap, f_in.texCoord1);

   return f_out;
 }
 
#ifdef WIN32
}
#endif

