Masking Objects

There's an example project in ZapWorks Studio that accompanies this article called "Example: Masking Objects".

Masking is a technique that hides parts of a scene as if they were behind an invisible object.

It can be used to create environments that extend behind, and are framed by a target image.

Creating a Mask

The masking process has several steps:

  1. Set the layerMode parameter of the objects that are to be hidden, even partially, to test_3d. This means that these objects will have to be closer to the camera than other objects in order to be visible.
  2. Add an object to the scene that is in front of the undesirable content and set its layerMode parameter to full_3d. This object will hide the objects behind it in the scene.
  3. Move this mask object before the other objects in the Hierarchy. The mask object will still hide the other objects but will be drawn to the screen first.
  4. Set the color opacity of the mask object to 0. The mask object won't be visible but will still hide the objects behind it.

Types of Mask Object

While any object type can be used as a mask, ZapWorks Studio provides a number of useful types that can be added to the Media Library using the + button.

Square Mask This object is very large but has a square hole in the center from x = -1 to +1 and y = -1 to +1.

Circle Mask This object is very large but has a circular hole in the center with a radius of 1.

zapcode branded_zapcode i