06. AR Foreground Object Masking
About Foreground Object Masking
This section describes how to mask objects in the foreground in Augmented Reality (i.e. rendered in the Foreground pass), also known as Alpha Holdout. This is useful when part of a virtual object should be hidden by a real life object such as objects appearing out of the floor.
Using Alpha Holdout in Project Settings (Recommended)
Alpha Holdout allows real-world objects to hide virtual ones. When you convert an object to Holdout, it becomes hidden from capture, but it obstructs or masks other objects.
- In Project Settings, check that “Alpha Holdout” and “Support Primitive Alpha Holdout (Deferred)” are both enabled. If not, enable them.
- Select the Actor in the Outliner that will act as the masking object, and in the Details panel enable the "Holdout" option.
- Add the Actor to the Objects list in the Cesium Camera Foreground.
The result is an object that is invisible in the Viewport and in the Cesium Camera capture, but which functions as a mask for other objects.
In the example below, the "Plane" actor is set as a Holdout, and the three cubes are masked by it at their intersection. Note that Holdout masks the object whether the Blend Mode is Opaque, Masked, or Translucent.
Using the AR Mask Material (Deprecated)
For versions prior to Unreal Engine 5.5, VSAR offered the M_AR_Mask material, a custom material that, when applied to an Actor's mesh, converts it into a Holdout mask. While this process is deprecated in Unreal Engine 5.5 and later, it is still included and functional.
In this example we want the sphere to hide the cube. The cube and sphere are in the Objects in Foreground list of the Cesium Camera. These are the steps to make the Sphere a mask using the AR Mask Material:
- Select the material “M_AR_Mask” in the “PRIME VSAR Tools” menu and drag and drop it on the masking objects.
- Add the masking objects into the “Objects in Foreground” list of the Cesium Camera. In this case, the Sphere.
In the example below, the masking objects are now invisible on the Fill channel and masking in the Key channel (Holdout)
.
⚠️ In order to find “M_AR_Mask” when using the assets browser, “Show Engine Content” and “Show Plugin Content” must be enabled in “View Options”.