Masking

When developing for XR-3 and XR-1 Developer Edition, you can mask specific objects to act as a “window” into the real world. This is especially useful if you want to see real-world elements such as instruments or controller devices in the virtual environment.

Varjo Compositor uses the alpha value of a layer to blend between the image from the client application and that from the video pass-through (VST) cameras. If VST rendering is enabled and the layer is not flagged as opaque, every pixel in the color buffer with an alpha value smaller than 1.0 will be blended with the VST image. If the color of the pixel in the color buffer is RGBA(0,0,0,0), only the VST image will be visible.

Follow these simple steps to add a VST mask to your Unity project.

Masking with High Definition Render Pipeline

To enable mixed reality for the Varjo XR Plug-in, see Mixed Reality With Varjo XR Plug-in.

Start by adding a mesh to your scene. The mesh will act as a mask for the VST image and can be any shape. In this example, we use a simple Quad placed in the doorway.

Next, create a new material for the mask. For the material, you will need to assign a shader that is able to export alpha and write to the depth buffer. You can use HDRP’s default Unlit shader or create a custom one. When using HDRP/Unlit, make sure the Surface Type is Opaque and set the Color to RGBA(0,0,0,0). Since Varjo layers use premultiplied alpha, having just the Alpha channel at 0 is not enough. Also make sure that the RGB color is black with the default Unlit shader.

Note: With some newer versions of HDRP you need to enable Alpha Clipping and set its threshold to zero.

Assign the created material to the mask mesh.

Your VST mask is now ready. Click Play, and you should be able to see into the real world through the mesh.

Please note that the VST image is not visible in the Unity Editor. You can see it both inside the headset and in the headset view in Varjo Base.