How to Use the Occlusion Model in Unity

An occlusion model enables you to mask the surfaces of a physical object so that virtual objects are not rendered over them when they are behind the object in your scene. This effect relies on depth masking and provides a much more realistic rendering for scenes that combine physical and virtual objects.

Depth masking via an occlusion model is accomplished by developing a 3D model or mesh of the regions of the object that you want to mask and then apply a depth mask shader to that model. The depth mask will prevent any objects behind the masked region from being rendered.

Occlusion Management

A volumetric occlusion model

An occlusion model can match the exact geometry of the physical object that it corresponds to, or it can be a simplified representation of the object, such as its bounding box. The latter technique is an easy way to occlude physical objects with simple geometries, like boxes, balls and cylinders and ideal for Multi Targets and Cylinder Targets.

Vuforia Image

A geometrically accurate occlusion model

For Model Targets and Object Targets, it is recommended to use a geometrically accurate occlusion model. And, it is best if you only use the exterior surfaces of the model, at the lowest polygon count needed to provide satisfactory masking of your physical object. You can use a 3D modeling editor to simplify your model by reducing the polygon count and removing any duplicated or hidden (e.g. internal) geometries.

TIP: If you use an occlusion model as well as render virtual augmentations that are closely aligned to the surface of the physical object, be sure to test the rendering results on the device platforms that you intend to deploy to. When 3D models are closely aligned, they can become confused in the renderer's depth buffer. This is an problem known as Z-Fighting ( Z is for Z Axis ) and can result in noisy rendering artifacts. To avoid Z-Fighting, use the MODE_OPTIMIZE_QUALITY setting on the ARCamera and offset your models so that they are not overlapping each other.

Vuforia Image

How to Configure a Model to Occlude for a Physical Object

  1. Import your occlusion model to your Unity project or create a simple bounding model by selecting a primitive mesh geometry from Game Object -> Create Other in the Editor menu.
  2. Drag the model onto your Vuforia Target instance in the Hierarchy so that it is a child of the Vuforia Target instance, in this case an ObjectTarget.
Vuforia Image
  1. Carefully align the position of your occlusion model in relation to its corresponding target.
  2. Add a Depth Mask Shader to your occlusion model’s material or add the Unity built-in SpatialMappingOcclusion material to your model’s mesh in order for it be hidden during runtime.
Vuforia Image
  1. Add your augmentable content to your scene to test that your occlusion model is masking the physical object accurately.
  2. Start Vuforia Play Mode to evaluate the occlusion effect in the scene.
Vuforia Image
  1. Verify the accuracy of your occlusion model registration from multiple positions in the scene.
Vuforia Image

Related Topics

Introduction to Model Targets in Unity

How to Use Object Recognition in Unity

Vuforia Object Scanner