Masking
Note: you are currently viewing documentation for a beta or an older version of Varjo
Varjo Compositor uses the alpha value of a layer to blend the image from the client application with the image 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 plugin.
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 and 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 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.