When I use this RenderTarget:
renderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width,
GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24);
and draw something to it:
graphicsDevice.SetRenderTarget(renderTarget);
// some drawing code here
graphicsDevice.SetRenderTarget(null);
and then when I want to continue with drawing depth buffer seams to be clean. Why? Is possible to save it for future use?
Answer
From the deferred rendering articles/tutorials I read it's a limitation in XNA (likely because the XBox 360 probably discards the depth buffer when you change render targets, hence they apply the limitation to Windows as well). What you need to do is use MRT (Multiple Render Targets) and write/test the depth against another RenderTarget2D
that is something along the lines of Single
.
When you have finished 'compositing' your depth buffer write it out to the real depth buffer using a screen quad and associated pixel shader.
The first article in J.Coluna's (quite brilliant) series on LPP describes the problem briefly - and his code should provide a nice reference for working around the issue.
No comments:
Post a Comment