VR Tunnelling Pro
Plug-and-Play VR Comfort
Masking
Mobile masking settings
Mobile masking settings

Simple masking is supported. This does not allow the WINDOW or PORTAL modes present in the Tunnelling and TunnellingOpaque scripts, but allows objects to be excluded from the effect as in MASK mode. To enable, tick Use Mask.

TIP: Masking works with or without Draw Skybox.

TIP: Using masking disables the Iris Z-Rejection optimisation, and therefore may increase fillrate requirements. It will also increase drawcalls according to the number of objects being masked.

Settings

Mobile masking uses the stencil buffer. Ensure that your project and hardware support this.

  • Stencil Reference: The effect will be excluded from pixels with this value in the stencil buffer. Masked objects will write this value to the stencil buffer.
  • Stencil Mask: The mask used by the effect to read from the stencil buffer. Masked objects will use this as the write mask.
  • Stencil Bias: Offset the z-value of masked objects to avoid z-fighting in the mask.

If you already use the stencil buffer, alter the Stencil Reference and/or Stencil Mask settings to avoid conflicts. If you encounter z-fighting in the mask, alter the Stencil Bias setting.

Masking Objects

The simplest way to mask objects is to add a TunnellingMaskObjectMobile script[API] to any object to be masked. The object must have a Renderer component, such as a MeshRenderer. Ticking Auto Add Children will include child Renderer objects in the mask. Disabling the component or the gameobject will stop it being masked, and re-enabling will again add it to the mask.

Objects can also be masked from code using the AddObjectToMask (Renderer r, bool includeChildren) and RemoveObjectFromMask (Renderer r, bool includeChildren) methods. Alternatively, just use gameObject.AddComponent<TunnellingMaskObjectMobile>().

Custom Shaders

You can also mask objects using custom shaders. To write a shader that masks the object being drawn, include the following Stencil block in your Pass or Subshader:

Stencil {
Ref [_VRTP_Stencil_Ref]
WriteMask [_VRTP_Stencil_Mask]
Pass Replace
}

Objects with custom shaders such as this do not need to be added to the mask using either of the above methods.

The other two methods manually re-draw objects at the end of the frame, leading to increased drawcalls. Making shaders mask-compatible like this removes these extra drawcalls.

Note also that the Stencil Bias setting doesn't affect this, as it's just to avoid z-fighting during re-drawing. If however you require this for whatever reason, add the following line to your Pass or Subshader:

Offset -1, [_VRTP_Stencil_Bias]


TIP: If stencil objects are drawn before objects that occlude them, those pixels will be masked anyway. To avoid this, consider changing draw order or writing 0 to the stencil buffer on occluding objects.

Mobile tunnelling with masking
Mobile tunnelling with masking