How do I reuse z-buffer for glow effect?

Started by
3 comments, last by CCF 17 years, 4 months ago
Hi there, I'm playing around with some fixed-function pipeline bloom/glow effect using DirectX 9. So far it's working great, but I would love to optimize the glow rendering speed as it currently cuts the FPS by almost half. I've done a search on the forum and came upon this info:
Quote:just render the normal scene, grab the z-buffer, and render the glowing geometry using the z-buffer from the rendered scene. that's all, no need to re-render non glowing geometry...
Now I'm wondering how would I go about at copying the z-buffer from the normal scene to be reused for the 2nd glow render? Here's a basic break down of how I'm doing the glow at the moment: - Render normal scene - SetRenderTarget to glow surface/texture - Render glow objects normally, while others in black - Down-size to filter the glow texture - Overlay glow texture on top of normal scene Note that I'm not doing fullscreen glow though, which renders a lot quicker using the StretchRect() method. Thanks! [smile]
Advertisement
You wouldn't have to copy the zbuffer to make use of it - you can just leave it bound, and bind your new pixel render target, then render. This does assume, though, that the two render targets are the same size.

Or, you could just use the alpha channel of the original render target to store your glow value, and do your glow rendering at the same time as your normal rendering.
Thanks for the reply, JasonBlochowiak!
It helps a lot. [smile]

Quote:You wouldn't have to copy the zbuffer to make use of it - you can just leave it bound, and bind your new pixel render target, then render. This does assume, though, that the two render targets are the same size.


Ah, do you mean that my glow's render target surface have to be the same size as my normal render target's backbuffer (which is my app window size)?

So if my app window is at 640x480, I would need to create the glow surface at that size? Would it cause a problem if the surface isn't power of two? Upping it to the next closest power of two size (1024x512) seems to be quite a waste.

Quote:Or, you could just use the alpha channel of the original render target to store your glow value, and do your glow rendering at the same time as your normal rendering.


How would I set my render target to point at the alpha channel of the original buffer? I did a search on alpha buffer, but it didn't turn up much info unfortunately.

Sorry for asking so many questions, I'm still quite new at all this.

Thanks for your time! [smile]
You can just write to the alpha value of your regular render target, assuming you're using A8R8G8B8 or some other format that has an alpha value. Depending on your setup, you may need to set part of the card state so that the value just gets written out (as opposed to used for blending or whatever).

I don't think there are any power of two restrictions for render targets, or at least not on any of the hardware I've been using. Also, you can (if I'm remembering correctly) make the render target smaller than the z/stencil - but double check that works correctly for you.
Thanks, I'll look into it!

This topic is closed to new replies.

Advertisement