Sign in to follow this  
elurahu

XNA: Depthbuffer reuse

Recommended Posts

elurahu    258
I'm trying to implement an effect which involves reusing the depthstencilbuffer from a previous rendertarget. What I want to happen: 1) I render a bunch of geometry to the backbuffer using the default depthstencilbuffer. 2) I set a new active rendertarget where I render some stuff I need depth tested against when SHOULD be in the default depthstencilbuffer. The problem is step 2 doesn't get depthtested against the default depthstencilbuffer. I've tried so many things now I'm at roads end. Anyone have an input on how to do this in XNA? Alternative are welcome! Regards

Share this post


Link to post
Share on other sites
MJP    19754
This is a particularly painful consequence of maintaining compatibility with the Xbox 360. You see on the 360 the depth buffer lives in the eDRAM along with the render target. When you're done with render target, it gets "resolved" which means it's dumped back out to main memory so it can be used as a texture. Unfortunately when this happens, your depth buffer goes with it. On the PC this is actually emulated by the XNA runtime by clearing the depth buffer.

To get around this, you can try restoring the depth buffer. Unfortunately this requires rendering depth yourself to a texture (either via MRT or with a second pass), then using a full-screen pass to sample the texture and write out the depth. Catalin Zima has a sample you could look at.

Share this post


Link to post
Share on other sites
elurahu    258
Thanks a bunch MJP. Yes on the Xbox I would normally have left the depth values in the eDRAM and then just reused them. Right - Good think I havn't been going mental the last 4 hours. Damn XNA :)

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