Any way to save and restore the Z-buffer?

Started by
1 comment, last by phil_t 10 years, 3 months ago

Hi, I was wondering if there's a way to save and restore the Z-buffer. What I want to do is pretty much to create a G-buffer, save the Z-buffer, do stuff, including creating shadow maps etc. Then restore the Z-buffer before rendering the forward pass with particles and other translucent surfaces. Is there any sane way to do this?

I'm using XNA with the intention of moving on to MonoGame in the near-ish future.

Advertisement

I'm not an XNA user, but the D3D9 api surely allows creating multiple z buffers, so that you can "save" one for later usage while using another for write access; and it is normal to the rendering process (SetDepthStencilSurface)

I don't know if XNA allows access to it though.

You might try RenderTargetUsage.PreserveContents, although that means you'll be using the same render target - so it's not an option if you'll be sampling from the same one you used when creating Z-buffer. I'm also not sure if that's supported in MonoGame.

The depth buffer is tightly-coupled with the render target in XNA.

Another option (this is what I do), is to render depth values to a render target during your G-buffer pass, and then use that render target to render to the z-buffer during your forward pass (by outputting DEPTH from your pixel shader, and using a BlendState that disables color writes).

This topic is closed to new replies.

Advertisement