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.
Mobile masking uses the stencil buffer. Ensure that your project and hardware support this.
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.
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>()
.
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
:
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
:
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.