//These variables will get set automatically
texture tex1;
float2 rcpres;
float4 BloomSettings;
sampler s0 = sampler_state { texture = <tex1>; };
float Luminance = 0.08f;
static const float fMiddleGray = 0.18f;
static const float fWhiteCutoff = 0.8f;
#define NUM 25
float2 PixelOffsets[NUM] =
{
{ -0.003, -0.003 },
{ -0.003, 0.0035 },
{ -0.0025, -0.0025 },
{ -0.0025, 0.0025 },
{ -0.002, -0.002 },
{ -0.002, 0.002 },
{ -0.0015, -0.0015 },
{ -0.0015, 0.0015 },
{ -0.001, -0.001 },
{ -0.001, 0.001 },
{ -0.0005, -0.0005 },
{ -0.0005, 0.0005 },
{ 0.000, 0.000 },
{ 0.0005, -0.0005 },
{ 0.0005, 0.0005 },
{ 0.001, -0.001 },
{ 0.001, 0.001 },
{ 0.0015, -0.0015 },
{ 0.0015, 0.0015 },
{ 0.002, -0.002 },
{ 0.002, 0.002 },
{ 0.0025, -0.0025 },
{ 0.0025, 0.0025 },
{ 0.003, -0.003 },
{ 0.003, 0.003 },
};
static const float BlurWeights[NUM] =
{
0.002000,
0.004000,
0.008000,
0.016000,
0.024000,
0.032000,
0.048000,
0.064000,
0.096000,
0.112000,
0.128000,
0.132000,
0.128000,
0.132000,
0.128000,
0.112000,
0.096000,
0.064000,
0.048000,
0.032000,
0.024000,
0.016000,
0.008000,
0.004000,
0.002000,
};
float4 NormalColourPass( in float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 color = tex2D( s0, Tex );
color.a = 1;
return color;
}
float4 BloomPass( in float2 Tex : TEXCOORD0 ) : COLOR0
{
BloomSettings.x = 1.0;
BloomSettings.y = 0.3;
float3 pixel;
float3 Color = 0;
for(int i = 0; i < NUM; i++)
{
pixel = tex2D(s0,Tex + PixelOffsets[i] * 5.0f)+BloomSettings.y;
pixel *= fMiddleGray / (Luminance + 0.001f);
pixel *= (1.0f + (pixel / (fWhiteCutoff * fWhiteCutoff)));
pixel -= 5.0f;
pixel = max(pixel,0.0f);
pixel /= (10.0f + pixel);
Color += pixel * BlurWeights[i];
}
Color *= BloomSettings.x;
return float4(Color,1.0) + tex2D(s0,Tex);
}
float4 BlurPass( in float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color = tex2D( s0, Tex.xy );
Color += tex2D( s0, Tex.xy+0.001);
Color += tex2D( s0, Tex.xy+0.002);
Color += tex2D( s0, Tex.xy+0.003);
Color = Color / 4;
return Color;
}
Technique T0
{
pass p0 { PixelShader = compile ps_2_0 NormalColourPass(); }
pass p1 { PixelShader = compile ps_3_0 BloomPass(); }
pass p1 { PixelShader = compile ps_2_0 BlurPass(); }
}