Sign in to follow this  
ThorOdinson

Bloom HLSL Pixel shader help

Recommended Posts

hey i've been trying to get bloom to work, i've looked at the NVidia and directX examples trying to find out how to create the effect, i found .fx examples and tried to convert it to .ps but it doesn't seem to load any help or suggestion on how to get this code to work would greatly be appreciated :)



/**********************************************
PP_Bloom.psh

Post-processing pixel shader that spins an
area in a spiral
***********************************************/

//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------

// Access to texture 0 (scene texture)
sampler2D SceneTex;

// UV coordinates of rectangle being processed
float2 UVTopLeft;
float2 UVBottomRight;




//-----------------------------------------------------------------------------
// Input / output structures
//-----------------------------------------------------------------------------

// Input to Pixel Shader
struct PS_Input
{
float2 TexCoord0 : TEXCOORD0; // Texture coords of this pixel within source texture - the entire unprocessed scene
float2 TexCoord1 : TEXCOORD1; // Texture coords of this pixel within processed area only (useful when using support texture - unused in this shader)
};

// Output from Pixel Shader
struct PS_Output
{
float4 Colour : COLOR0;
};


//-----------------------------------------------------------------------------
// Main function
//-----------------------------------------------------------------------------

float Luminance = 0.08f;
static const float fMiddleGray = 0.18f;
static const float fWhiteCutoff = 0.8f;


float2 PixelOffsets[9] =
{
{ -0.004, -0.004 },
{ -0.003, -0.003 },
{ -0.002, -0.002 },
{ -0.001, -0.001 },
{ 0.000, 0.000 },
{ 0.001, 0.001 },
{ 0.002, 0.002 },
{ 0.003, 0.003 },
{ 0.004, 0.004 },
};

static const float BlurWeights[9] =
{
0.026995,
0.064759,
0.120985,
0.176033,
0.199471,
0.176033,
0.120985,
0.064759,
0.026995,
};

// Main pixel shader function
void main( in PS_Input i, out PS_Output o )
{
float3 pixel;
float3 colour = 0;

for(int i = 0; i < 9; i++)
{
pixel = tex2D( SceneTex, i.TexCoord0 + PixelOffsets[i] * 5.0f) + 0.5f;
pixel *= fMiddleGray / (Luminance + 0.001f);
pixel *= (1.0f + (pixel / (fWhiteCutoff * fWhiteCutoff)));
pixel -= 5.0f;

pixel = max(pixel,0.0f);
pixel /= (10.0f + pixel);

colour += pixel * BlurWeights[i];
}

colour *= 1.5f
o.Colour.rgb = (colour , 1.0f) + tex2D( SceneTex, i.TexCoord0);



}

Share this post


Link to post
Share on other sites
[quote name='angelofsloth' timestamp='1313855038' post='4851626']
or can anyone suggest where i can find a good bloom example other than the DirectX SDK?
[/quote]

The example is pretty straight forward, and easily portable. You haven't really given much information as to why it won't load for you, or how you tried porting it. Also, the shader alone doesn't really mean much, as it also has a dependancy on the drawing code around it, quite often including the specific formats used by the renderbuffers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this