sampler texture0 : register(s0);

float4x4 WorldViewProjectionTransform  : WORLDVIEWPROJ;
float2 fTextureSize;
float fAmount;


struct VS_OUTPUT 
{
   float4 Position  : POSITION;
   float2 TexCoord  : TEXCOORD0;    
};

struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};

VS_OUTPUT vertexMain(
				float4 vPosition : POSITION,
				float2 texCoord0 : TEXCOORD0)
{
	VS_OUTPUT Output; 

	Output.Position = mul(vPosition, WorldViewProjectionTransform);
	Output.TexCoord = texCoord0;   

	return Output;
}

float2 coord(float2 input, float x, float y)
{
	float2 result;
	result.x = input.x + x;
	result.y = input.y + y;
	return result;
}

PS_OUTPUT pixelMain(VS_OUTPUT In)
{
	float2 incoord = In.TexCoord + 1.f / fTextureSize / 2.f; 

	float fBlurSize = 2.f / fTextureSize[0];

	float4 result = tex2D(texture0, incoord);
	
	result -= tex2D(texture0, coord(incoord, 0, -3.f * fBlurSize)) * 0.05214f;
	result -= tex2D(texture0, coord(incoord, 0, -2.f * fBlurSize)) * 0.06714f;
	result -= tex2D(texture0, coord(incoord, 0, -1.f * fBlurSize)) * 0.08214f;
	result -= 2 * tex2D(texture0, coord(incoord, 0,               0 )) * 0.08714f;
	result -= tex2D(texture0, coord(incoord, 0,  1.f * fBlurSize)) * 0.08214f;
	result -= tex2D(texture0, coord(incoord, 0,  2.f * fBlurSize)) * 0.06714f;
	result -= tex2D(texture0, coord(incoord, 0,  3.f * fBlurSize)) * 0.05214f;

	result -= tex2D(texture0, coord(incoord, -3.f * fBlurSize, 0)) * 0.05214f;
	result -= tex2D(texture0, coord(incoord, -2.f * fBlurSize, 0)) * 0.06714f;
	result -= tex2D(texture0, coord(incoord, -1.f * fBlurSize, 0)) * 0.08214f;
	//result -= tex2D(texture0, coord(incoord,               0 , 0)) * 0.08714f;
	result -= tex2D(texture0, coord(incoord,  1.f * fBlurSize, 0)) * 0.08214f;
	result -= tex2D(texture0, coord(incoord,  2.f * fBlurSize, 0)) * 0.06714f;
	result -= tex2D(texture0, coord(incoord,  3.f * fBlurSize, 0)) * 0.05214f;
	
	PS_OUTPUT output;

	//float fValue = step(result.r + result.g + result.b, 0.3f);
	float fIntensity = saturate((0.114f * result.b + 0.587f * result.g + 0.299f * result.r) * 12.5f);
	//fIntensity = fIntensity * fIntensity;
	fIntensity = fIntensity * fIntensity * fIntensity;
	fIntensity = 1.f - saturate(fIntensity * fAmount * 400.f);
	output.RGBColor = float4(fIntensity, fIntensity, fIntensity, 1.f);
	return output;
}