// 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 texCoord0 : TEXCOORD0;
};

// 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
		
		// maybe more uniform parameters fed from the application
		//uniform float3 someParameter
		)
{
	out_fragment f_out;

#ifdef _POISSONFILTER
  f_out.color  = tex2D(diffuseMap,f_in.texCoord0.xy);

  float2 poissonDisc[12] = {
    float2(-0.326212f, -0.40581f),
    float2(-0.840144f, -0.07358f),
    float2(-0.695914f, 0.457137f),
    float2(-0.203345f, 0.620716f),
    float2(0.96234f, -0.194983f),
    float2(0.473434f, -0.480026f),
    float2(0.519456f, 0.767022f),
    float2(0.185461f, -0.893124f),
    float2(0.507431f, 0.064425f),
    float2(0.89642f, 0.412458f), 
    float2(-0.32194f, -0.932615f),
    float2(-0.791559f, -0.59771f)
  }; 


  float pixelSize = 1/512;
  float discRadius = 150.0;

  // 12 weitere Stellen sampeln 
  for(int tap = 0; tap < 12; tap++) 
  { 
    float2 offset = (pixelSize * poissonDisc[tap] * discRadius); 
    float2 coord = f_in.texCoord0.xy + offset;
    f_out.color += tex2D(diffuseMap, coord);
  } 

  // average the results
  f_out.color /= 13.0f;
#else  // GAUSSIAN BLUR (3x3)
  float3 gaussianBlur[3] =
  {
    float3(0.045f,0.122f,0.045f),
    float3(0.122f,0.332f,0.122f),
    float3(0.045f,0.122f,0.045f)
  };
  float pixelSize = 2.0/1024.0;//0.00125;
  //float pixelSize = 0.025 * tex2D(diffuseMap, f_in.texCoord0.xy).a;
  //float pixelSize = tex2D(diffuseMap, f_in.texCoord0.xy).a;

  float2 modTex = f_in.texCoord0.xy;

  f_out.color = float4(0,0,0,0);
  modTex -= float2(pixelSize, pixelSize);

  // upper left
  f_out.color = 0.045 * tex2D(diffuseMap, modTex);

  // upper
  modTex.x += pixelSize;
  f_out.color += 0.122 * tex2D(diffuseMap, modTex);

  // upper right
  modTex.x += pixelSize;
  f_out.color = 0.045 * tex2D(diffuseMap, modTex);

  // center right
  modTex.y += pixelSize;
  f_out.color += 0.122 * tex2D(diffuseMap, modTex);

  // center
  modTex.x -= pixelSize;
  f_out.color += 0.332f * tex2D(diffuseMap, modTex);

  // center left
  modTex.x -= pixelSize;
  f_out.color += 0.122f * tex2D(diffuseMap, modTex);

  // lower left
  modTex.y += pixelSize;
  f_out.color += 0.045 * tex2D(diffuseMap, modTex);

  // lower center
  modTex.x += pixelSize;
  f_out.color += 0.122 * tex2D(diffuseMap, modTex);

  // lower right
  modTex.x += pixelSize;
  f_out.color += 0.045 * tex2D(diffuseMap, modTex);

#endif

	return f_out;
}

#ifdef WIN32
}
#endif

