2
\$\begingroup\$

In OpenGL and Direct3D11 depth write is disabled if depth test is disabled. To enable depth write with out depth test in gl you must enable depth test with depth func always.

OpenGL

Even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated if the depth test is disabled. In order to unconditionally write to the depth buffer, the depth test should be enabled and set to GL_ALWAYS (see glDepthFunc).

Direct3D11

DepthEnable and StencilEnable enable (and disable) depth and stencil testing. Set DepthEnable to FALSE to disable depth testing and prevent writing to the depth buffer. Set StencilEnable to FALSE to disable stencil testing and prevent writing to the stencil buffer (when DepthEnable is FALSE and StencilEnable is TRUE, the depth test always passes in the stencil operation).

I can't find any documentation on this behavior for d3d9.

In Direct3D9 if D3DRS_ZENABLE is set to D3DZB_FALSE and D3DRS_ZWRITEENABLE is set to TRUE is the depth buffer written to?

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

The closest answer I can find is from the DXSDK article "Depth Buffers (Direct3D 9)"; relevant portion extracted (with some parts about the color buffer and w-buffers removed):

At the beginning of the test, the depth value in the depth buffer is set to the largest possible value for the scene. Each polygon in the scene is tested to see if it intersects with the current coordinate (x,y) on the rendering surface. If it does, the depth value at the current point is tested to see if it is smaller than the depth value stored in the depth buffer. If the depth of the polygon value is smaller, it is stored in the depth buffer...

This implies that depth buffer writing is part of the depth test itself, and that if the depth test is disabled then writing is therefore not done.

I could whip up a quick test program, but that of course would only be valid for my hardware and drivers. So given the apparent lack of a more definitive statement, I'd be inclined to play safe and assume that the behaviour is the same as D3D10/11 and OpenGL - after all, setting the depth comparison to always and writing to true is absolutely guaranteed to produce the desired result, whereas relying on it writing with the test disabled puts you in the clutches of how hardware vendors have decided to interpret this unfortunate vagueness.

\$\endgroup\$
2
\$\begingroup\$

Disclaimer: I've never used D3D9, only D3D10/11 and OpenGL.

See D3DRENDERSTATETYPE enum values and D3DCMPFUNC. Specifically, look at D3DRS_ZFUNC and try setting it to D3DCMP_ALWAYS with D3DRS_ZENABLE set to true, similar to what the GL docs indicate do. See also Depth Buffering State (Direct3D 9)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .