This project is read-only.

Depth Buffer and Changing DrawTargets

May 21, 2009 at 9:45 PM

If I draw some items on one drawtarget, then switch to another, does the DepthBuffer get changed along with the new drawtarget?  If this is the case, is there anyway to prevent it?

May 21, 2009 at 11:37 PM
Edited May 21, 2009 at 11:38 PM

This is a limitation of XNA unfortunately.
They have made XNA to be as compatible as possible with the xbox, where whenever you change render target the render target/depth gets wiped (due to the EDRAM temporary buffer).
Unfortunately there is no ability to set a 'keep' flag on a depth buffer.
I do allow you to share the depth buffer between two draw targets, however this only serves to reduce memory usage on the PC. (The 'ShareDepthBuffer' method, depth buffers use no memory on the xbox because they are temporary).

It's a really annoying limitation. :/

May 21, 2009 at 11:49 PM


I'm working with doing some volumetric cloud rendering, and i really need to be able to keep the depth buffer when i go from the object render target to the mega particle render target... Think this is still possible with XNA? Here is the technique I'm following

May 21, 2009 at 11:58 PM

There isn't really an easy way to do it. While redrawing the objects as z-only will be very quite fast (essentially it'll be entirely CPU limited) your only other option is to render depth into a texture during the first pass, and then either use that texture depth for pixel shader tex-kill (clip) or render the depth back into the scene with shader Depth output (which isn't all that ideal, as it kills many z-optimizations the video card might be able to perform)