Occlusion Tests

From Mod Wiki

Jump to: navigation, search

Occlusion testing is another form of optimization that prevents the rendering of entities that are hidden from view (occluded) by other surfaces. By using bounding box data provided by the graphics card in the previous frame, the engine determines whether an entity should be rendered in the next frame. An enlarged entity bounding box is used to do this.

Contents

Basic Usage

There are two main ways to specify that an entity should use occlusion tests:

  • Material Flag - add "occlusionQuery" to the material definition.
  • LOD Groups - assign the entity to a LOD Group that has occlusionTest set to true

It is also possible to flag portals as occlusion tested (see visportal_occluder) - this is useful when a portal is difficult to dog leg but is behind opaque geometry.

Rendering occlusion-tested objects in Salvage

This screenshot demonstrates occlusion-tested objects in Salvage, highlighted using the r_showOcclusions command. Any object subject to occlusion testing is drawn in wireframe, where red indicates that the object failed the last occlusion test. For example, in this screenshot the garage is occluding many objects, such as the truck, and so those objects will not be drawn.

Because occlusion tests use an expanded bounding box, sometimes objects that appear to be occluded are not considered as such by the engine. This can either be ignored, or the object moved further away so its (enlarged and invisible) bounding box does not protrude through.

Bounding box for an occlusion-tested LOD Group on Salvage

This screenshot shows an area in Salvage that has been assigned to the same LOD level and marked as occlusion tested. The engine uses the white bounding box to determine if this area should be drawn in the next frame - if the bounding box is not visible, then it won't draw the LOD Group at all.

Notes

Cost

Of course, there is a hidden expense to enabling occlusion queries, since the bounds of the entity has to be rendered (albeit to the z-buffer)

To prevent stalling the hardware, occlusion data can be up to three frames old. In game this can mean an entity will suddenly appear if that entity was not visible in the previous three frames.

Developer Commands

  • r_showOcclusions - outlines occlusion-tested objects
  • r_occlusionBBDebug - draws the bounding boxes used for occlusion testing
Personal tools