Sign in to follow this  
EnochDagor

Ensuring No Z-Buffer Pop

Recommended Posts

Ok, so I am using a rendertarget to render some stuff to. Here's some pseudo code for you. oOrigSurface = Device.GetRenderTarget(0) Renderstate.ZBufferWriteEnable = False RenderState.ZBufferEnable = False Device.SetRenderTarget(0, oScene) Device.Clear(Target, Color, 1, 0) --- do render stuff here --- Device.SetRenderTarget(0, oOrigSurface) RenderState.ZBufferWriteEnable = True RenderState.ZBufferEnable = True Now, with that series of events, if someone on a GeForce 8600 and 1024x768 resolution (with matching Z-Buffer)... renders to a render target of 2048x2048, their Z-Buffer gets blown out and no longer functions correctly. Oddly enough, on a Radeon (and most other ATI's for that matter) Mobility 9700 at 1440x900 resolution (with matching Z-Buffer)... renders to a render target of 2048x2048, the z-buffer works just fine and doesn't get blown out. Now, DX doesn't appear to provide any caps items that I could check for this discrepancy. So, what is a sure fire way for me to not blow out the Z-Buffer (besides reducing the render target's texture resolution)? -E

Share this post


Link to post
Share on other sites
Quote:
Original post by EnochDagor

Now, DX doesn't appear to provide any caps items that I could check for this discrepancy. So, what is a sure fire way for me to not blow out the Z-Buffer (besides reducing the render target's texture resolution)?



If you want to render to a surface that's of a different size than your back-buffer, and you want to use z-buffering, then you must create a new depth-stencil surface whose size matches that of the surface you're rendering to. AFAIK, this is the only way to ensure proper behavior.

If you're not using z-buffering, then any size will do. DX requires that a depth-stencil surface is bound for rendering, but the size won't matter if you're not actually using it.

Share this post


Link to post
Share on other sites
You can't expect the Z-buffer contents to be reliable if you render with ZBufferWriteEnable set to false. The fact that it works with the 9770 is just one manifestation of undefined behaviour. If you want to disable Z-testing, use ZBufferEnable only. ZBufferWriteEnable is intended to be used for translucent objects and anything else that transcends the opaque object hierarchy.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
The fact that it works with the 9770 is just one manifestation of undefined behaviour.
A very important point - just because it works on ATI hardware doesn't mean they are actually correct [wink]

Run your code with the reference rasterizer to determine which IHV is actually correct...

hth
Jack

Share this post


Link to post
Share on other sites
Any chance you have the Discard Zbuffer flag set in the Presentation Parameters? I once had an issue with the Zbuffer going corrupt whenever I called SetRenderTarget. After a couple days of trying to figure out what was up, it turned out it discards the zbuffer when you call SetRenderTarget, and not, as I thought, when you call Present.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
If you're not using z-buffering, then any size will do. DX requires that a depth-stencil surface is bound for rendering, but the size won't matter if you're not actually using it.


Unfortunately, this is not the case. I'm not rendering to target using z-buffering but the z-buffer still gets blasted.

Quote:
Original post by TheAdmiral
You can't expect the Z-buffer contents to be reliable if you render with ZBufferWriteEnable set to false. The fact that it works with the 9770 is just one manifestation of undefined behaviour. If you want to disable Z-testing, use ZBufferEnable only.


I'll attempt that and see if it makes a difference.

Quote:
Any chance you have the Discard Zbuffer flag set...


I'll look into that and see what I have it set to.

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