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

// 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 main
   (
    // varying parameters
    in_fragment f_in,
    
    // uniform samplers (textures)
    uniform sampler2D diffuseMap  : TEXUNIT0,
    uniform sampler2D diffuseMap2 : TEXUNIT1,

    uniform sampler2D distortMap : TEXUNIT2,

    uniform float distortFactor,
    uniform float defaultFactor,
    uniform float blurFactor
    )
 {
   out_fragment f_out;
   
   //f_out.color = //tex2D(diffuseMap2, f_in.texCoord1.xy);
   //  0.75 * tex2D(diffuseMap, f_in.texCoord0.xy) + 0.25 * tex2D(diffuseMap2, f_in.texCoord1.xy);

   float4 distort = tex2D(distortMap, f_in.texCoord0.xy);
   distort.rg -= 0.5.xx;
   distort.rg *= distortFactor;
   //distort.rg *= 0.05;
   //distort.rg = 0.0.xx;
   float2 distortion = distort.rg + f_in.texCoord0;//float2(distort.,f_out.color.g/10.0) + f_in.texCoord0;

   f_out.color = 
     defaultFactor * tex2D(diffuseMap, distortion) + blurFactor * tex2D(diffuseMap2, distortion);
     //f_in.texCoord0.x * tex2D(diffuseMap, distortion) + second * tex2D(diffuseMap2, distortion);

   // invert the color
   //f_out.color = 1.0.xxxx - f_out.color;

   return f_out;
 }

#ifdef WIN32
}
#endif

