Jump to content
  • Advertisement
Sign in to follow this  

Problem with speed of bloom effect

This topic is 3970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my first post here, hello to all! I am writing a bloom effect in a directx9 engine. I have been following the HDRPipeline example in the SDK which has been a big help. It works fine now and looks pretty good. My only problem is that the final stage which adds the bloomed surface to the scene is very slow at high resolutions. My current method is this (some parts are omitted to keep it concise): //copy contents of back buffer to my own surface //i tried GetContainer() to get the back buffer texture to pass into the pixel shader but this returns E_NOINTERFACE I'm not sure why... pDev->StretchRect(spBackBuff, &winRect, spComposite, &winRect, D3DTEXF_NONE); //I then setup a slightly cut-down version of the finalpass pixel shader from the example which performs additive blending of the pixels pDev->SetTexture( 1, spCompositeTex ); pDev->SetTexture( 2, spBloomTex ); pDev->SetPixelShader( pFinalPassPS ); //then i render to the backbuffer surface usinf 4 verts pDev->SetFVF( FVF_TLVERTEX ); pDev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( TLVertex ) ); The pixel shader I am using is this (It is the one from the HDRPipeline example with the luminance parts taken out) float4 Composite( in float2 t : TEXCOORD0 ) : COLOR0 { // Read the HDR value that was computed as part of the original scene float4 c = tex2D( original_scene, t ); // Compute the blur value using a bilinear filter // It is worth noting that if the hardware supports linear filtering of a // floating point render target that this step can probably be skipped. float xWeight = frac( t.x / g_rcp_bloom_tex_w ) - 0.5; float xDir = xWeight; xWeight = abs( xWeight ); xDir /= xWeight; xDir *= g_rcp_bloom_tex_w; float yWeight = frac( t.y / g_rcp_bloom_tex_h ) - 0.5; float yDir = yWeight; yWeight = abs( yWeight ); yDir /= yWeight; yDir *= g_rcp_bloom_tex_h; // sample the blur texture for the 4 relevant pixels, weighted accordingly float4 b = ((1.0f - xWeight) * (1.0f - yWeight)) * tex2D( bloom, t ); b += (xWeight * (1.0f - yWeight)) * tex2D( bloom, t + float2( xDir, 0.0f ) ); b += (yWeight * (1.0f - xWeight)) * tex2D( bloom, t + float2( 0.0f, yDir ) ); b += (xWeight * yWeight) * tex2D( bloom, t + float2( xDir, yDir ) ); // Compute the actual colour: float4 final = c + 0.25f * b; // Return the fully composed colour c = final; c.a = 1.0f; return c; } I have two questions: 1. Is there an easier/faster way of combining the bloom texture with the image already on the back buffer? (I don't really see a reason to use a pixel shader here if I merely want to additive blend the two textures) 2. If a shader is required, how can I speed this up and is it possible to directly get the texture from the back buffer surface to avoid the copying step at the beginning? thanks in advance!

Share this post

Link to post
Share on other sites
I solved this by simplifying my final shader to this:

// read original scene value
float4 c = tex2D( original_scene, t );

//composite with bloom texture
float4 final = c + 0.4f * tex2D( bloom, t );

// Return the fully composed colour
c = final;
c.a = 1.0f;
return c;

and using this to filter the buffer for me:

pDev->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
pDev->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!