Sign in to follow this  
menohack

Debugging the stencil buffer

Recommended Posts

menohack    216

Is it possible to display the stencil buffer as a texture? The only formats available to a shader resource view are DXGI_FORMAT_R24_UNORM_X8_TYPELESS and DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS. When I try to draw this as a quad I only seem to have access to the x or r component, which is the depth.

 

Thanks!

Share this post


Link to post
Share on other sites
MJP    19755

It depends on which format you used to create the depth buffer. If you used DXGI_FORMAT_R24G8_TYPELESS, then use DXGI_FORMAT_X24_TYPELESS_G8_UINT to create your SRV and then access the G channel in your shader. If you used DXGI_FORMAT_R32G8X24_TYPELESS, then do the same with DXGI_FORMAT_X32_TYPELESS_G8X24_UINT.

In your shader, make sure that you declare your texture as Texture2D<uint2>. You'll then get an integer that's [0, 255], which you can convert to a [0,1] float for displaying.

Edited by MJP

Share this post


Link to post
Share on other sites
NightCreature83    5002

The other way of doing this is to turn color writes back on and stencil writes off for the objects you are rendering to the stencil, they will then appear on screen. This is easier then rendering to a render target and then displaying that if all you need to do is debugging.

 

I used this a lot during the development of DiRT3 where we were using a lot of stencil animations to do certain transitions, because of how our renderer worked. This is a renderstate change as well no need for an additional shader or texture.

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