Reading stencil/depth-buffers

Started by
3 comments, last by Matt Aufderheide 16 years, 10 months ago
Hello, I created my device with AutoDepthStencilFormat = D3DFMT_D24S8. Once I write to the stencil/depth buffers, is there a way I can find out exactly what the values of each 32-bits for each pixel in this buffer? Thanks. -amtri
Advertisement
Quote:Original post by amtri
Once I write to the stencil/depth buffers, is there a way I can find out exactly what the values of each 32-bits for each pixel in this buffer?

Unless you use the D3DFMT_D[16/32]_LOCKABLE format, you won't be able to lock the surface directly. You won't be able to use any APIs to copy it to a lockable surface, either (such as StretchRect()). If you need to get the values from a z-buffer, it is more practical to use multiple render targets and just write the depth out to a R32F surface.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
circlesoft: the problem with using multiple render targets is the overhead. Won't this slow things down tremendously?

I usually don't know when exactly I will need to query for the z buffer contents. My feeling is that this is going to be a rare occurrence, so I'd rather use a method that, although less efficient in this one time call, will be more efficient overall since I won't need to render to multiple targets all the time.

-amtri
One option is to set up two different shaders, one that renders to multiple targets and one that doesn't, and switch to the MRT one whenever you need the depth information. You can eliminate dependencies by calling one shader from the other (or putting common code in a function). The only hassle is that you'd need to write special shaders for each one that needs MRT support.
Depending on what you need the depth info for, an easier way is to use a floating point ARGB texture (like A32R32G32B32F) for the main render target and always output the depth value to the alpha channel..(this does create some problems when you need to do alpha blending..alpha testing can be handled by using the clip() function )..

This topic is closed to new replies.

Advertisement