direct3ddirectx-9direct3d9zbuffer

Direct3D 9 Z-Buffer Precision Bug occuring only in release build


I'm currently experiencing a weird issue that looks like Z-Fighting with Direct3D 9. I suspect that my problem is actually a Z buffer precision issue.

I noticed that absolutely no depth artifacts appear in Debug builds (I'm using Visual Studio 2012). The bug only occurs in Release builds.

The depth buffer format I'm currently using is 24-bits padded with 8 (D3DFMT_D24X8). When I use only 16-bits, the exact artifacts appear in both Debug AND Release builds. So what does that mean? Is DirectX rejecting 24-bits depth buffers? And if that's the case, why would you even do this?

Aside from all that, I tried setting 32-bits, but it just crashes and returns a null-pointer for the D3D device.

Many thanks in advance.

Here's a screenshot of my problem :

rectangular stair-like edges


Solution

  • Ok, so I eventually found a work-around. I divided my scene into regions of depth, and I'm rendering all of them one by one after clearing the Z-buffer between each passes.

    I currently have two passes (0.1m to 5m, and 5m to 10km). This seems to work pretty well for now.