Disabling Depth Test

This page describes the depth test property in Qt Quick 3D.

When disabled, the depthTestEnabled property can be used to simultaneously override depth testing and the order of rendering the objects. The operation of this property is not as obvious as many of the other properties in the system so this page offers some insight into when, where, and why this property can be used.

Depth Test

By default, the depthTestEnabled property is true. This is the normal mode of operation, and rendering is done in two passes. First, reading and writing from the depth buffer is enabled and all opaque objects are rendered from front to back (objects closer to camera are rendered first). In the second pass, writing to the depth buffer is disabled and all transparent (non-opaque) objects are rendered from back to front.

The first pass allows for optimal z-culling for normal opaque 3D objects and the second pass allows for correct blending of transparent objects.

When set to false, rendering is done in single pass. In this mode the depth buffer is not used at all, and all objects are rendered in a single back to front pass.

Comparison of Modes

Each setting for this property has pros and cons.

Depth Test Enabled

Pros:

  • It ensures the best visual quality with its two pass rendering technique, that enables the correct rendering of overlapping and intersecting 3D objects. It also ensures correct blending of transparent objects.
  • It offers better performance with opaque objects, which occlude other objects. Skipping the rendering of pixels that are hidden behind fully opaque objects is a common and powerful 3D rendering optimization known as z-culling.

Cons:

  • The two pass rendering technique can be more expensive in some scenarios.

Depth Test Disabled

Pros:

  • It can increase performance, if there are fewer objects benefiting from z-culling. In cases with little overlap it can be faster to render with the one pass technique.

Cons:

  • In some scenarios, rendering errors may be introduced and/or performance can suffer in this mode. When objects intersect or overlap each other, depth testing and the two pass rendering technique are necessary to achieve the correct results.

Conclusion

The depthTestEnabled property is an advanced feature that can be used to improve performance under certain specific scenarios. It can be activated per-scene to enable a separate one pass rendering technique that can achieve better performance than the default rendering technique, by eliminating depth testing in cases where 3D objects do not overlap or intersect.

This property should be disabled with some care. Although it is possible to increase performance by disabling this property on some scenes, it can introduce undesirable rendering errors and even in some cases adversely affect performance. Remember to measure thoroughly when optimizing.