// Basic HLSL shader
// Author : BlooV
// Date : 15.08.2011
//

float4x4 VPM    : register(c0);

// Vertex shader code
struct appdata {
       float4 Position : POSITION;
       float2 UV       : TEXCOORD0;
       float3 Normal   : NORMAL;
       float3 Tangent  : TANGENT;
       float3 Binormal : BINORMAL;
};

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

vertexOutput std_VS(appdata Input){
  vertexOutput Output = (vertexOutput)0;
  Output.Position = mul(VPM, Input.Position);
  Output.TexCoord = Input.UV;
  return Output;
}

// Pixel shader code
sampler2D DiffuseMap  : register( s0 );
float2    pixelSize  : register( c1 );

static const float2 PixelOffset[ 4 ] =
{
	{  0.530,  0.530 },
	{  0.530, -0.530 },
	{ -0.530, -0.530 },
	{ -0.530,  0.530 }
};

static const float brightCof = 0.6;

float4 std_PS(vertexOutput Input) : COLOR {
	float4 bloomSample = 0.0;
	float4 color;   
		
	for ( int i = 0; i < 4; ++i ) {
		color        = tex2D( DiffuseMap, Input.TexCoord + PixelOffset[ i ] * pixelSize ) - brightCof;
		color       += abs( color );
		bloomSample += color;
	}
	
	return bloomSample * 0.5;
}

// Compiler directives
technique main
{
  pass Pass0
  {
    VertexShader = compile vs_2_0 std_VS();
    PixelShader = compile ps_3_0 std_PS();
  }
};
