   ZBuffer Position +  Deferred Shading issue
  I'm developing a deferred shading test program, so far I'm rendering the depth values into a R32F texture. Now I like to get rid of that texture and use the depth buffer instead in order to reduce bandwidth.I tried and I'm now able to get the depth buffer value using INTZ,RAWZ or DF24 depending on the hardware, I'm also able to convert the depth values into the true view space positions. But I have a problem.in the first pass, I fill the complete G-Buffer and the ZBuffer, then get the ZBuffer surface for using it in later passes to get the position and place the standard ZBuffer. However, if I do that, the second pass will not be able to use the ZBuffer for early rejection the pixels outside of the light volume because that buffer is clean (I took the buffer with the depth values).Also, in the first pass I set stencil values in order to do some masking I need for lightmaps and dynamic lights, but if I remove the ZBuffer then I lost those stencil values.If there any fast way to copy the values stored in the ZBuffer into another one?. I tried StretchRect but as the Depth/Stencil surfaces have diferent formats (INTZ vs D24S8) then that function fails.The only solution I had came so far is to do a full screen quad pass and in the PS manually change the depth using the ZBuffer of the first pass as a texture. So that the new buffer gets filled. That works great but I don't know how to get   and set the stencil values.Just another question. I tried PerfHUD on Unreal3 and they seem to be using Deferred Shading and get the depth from a ZBuffer, however, they are able to set a D24X8 instead of a INTZ, How they do that? How they create a texture with D24X8 format in a GF8600?   
  I wander how games using Forward Rendering handle this issue. Some games claim that they use a fast ZPrePass in order to avoid running the shaders on pixels that are not visible. And the same games also claim that they use the ZBuffer in order to perform special effects that require getting the depth from the Depth Buffer. However, if they use the ZBuffer as a texture then then forward pass can't use the ZBuffer as the "current" zbuffer, therefore they loose the advantage of the ZPrePass.Copyng the ZBuffer values into the "current ZBuffer" using the Full screen quad pass I mentioned in the previous post is possible and relatively fast, however, I can't preserve the stencil values. Is there away around that? Is there a way to copy from one Depth/Stencil surface to another that have a diferent format?   ;  Crysis for instance does a depth-pass first, but renders that depth to a floating point texture.. so the z-buffer isn't "lost"...as far as I know most current games like Crysis still don't read the depth buffer directly.Btw, is this for DX10 or DX9?... if DX9 how do you actually get the Z-buffer data.. I though this was impossible.[Edited by - Matt Aufderheide on September 5, 2008 8:58:44 PM];Quote:Crysis for instance does a depth-pass first, but renders that depth to a floating point texture.. so the z-buffer isn't "lost"...as far as I know most current games like Crysis still don't read the depth buffer directly.Doing a depth pass first and storing the depth positions into an R32F is a way that works, you get the depth texture and the zbuffer keeps its values so tha the next rendering pass can used it to discard occluded pixels. However, as you are rendering to a texture, you loose the double speed rendering benefit that happens when the color rendering is disabled. Besides, having the R32F texture around means more bandwidth to be consumed. That last thing is one of the most important issues to be avoided when coding a Deferred Renderer as Bandwidth is most of the time the botleneck (at least in my case)Quote:Btw, is this for DX10 or DX9?... if DX9 how do you actually get the Z-buffer data.. I though this was impossible.In DX9 you can get create a depth/stencil texture with one of the FOURCC formats: INTZ, RAWZ, DF24, DF16 (the format depends on the graphic cards). Then that texture's surface can be used as the zbuffer and also later as a regular texture. So you can render to that texture setting it as the zbuffer and disabling color writteenable in order to get 2x-8x speed.The problem is that as you restore the original zbuffer after filling the depth texture, you loose its content and therefore the second pass can't use it to discard occluded pixels (and worst, can't do volume detection in the DF lighting)   