UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials

Bit Masking

A bit masking is a flexible mechanism used to access only the specific bits in a set of data. After double clicking the mask field you need to specify values for a bit mask consisting of 32 bits. Each of 32 bits can either be turned on (1) or off (0) when clicking on the bit number. The resulting mask (when bit mask window is closed) is displayed in hexadecimal characters. After that, two masks are compared bitwise using binary operator and. As a result, the first bit of the first mask is compared to the first bit of the second mask, the second bit - to the second one etc. If at least one pair of corresponding bits is turned on at the same time, the masks match.

Surface viewport Mask

Bit mask with the first bit turned on

  • A Set option turns on all the bits in the mask
  • A Clear option turns all the bits in the mask

See Also

  • A Collision mask section to know more about selecting objects to collide
  • A Physical mask section to know more about selecting objects to be affected by physical effects
  • An Intersection mask section to know more about selecting objects to be included when calculating intersections

Rendering into the Viewport

Objects (along with decals and lights) can be selectively rendered into the viewport.

For the objects to be rendered into the viewport, the camera viewport mask (set in the Tools -> Camera tab) should match the following masks:

  1. An object surface VIEWPORT mask
  2. An object material viewport mask to render the object's material
  3. A light viewport mask to illuminate the object (otherwise, the whole scene will be black)
Notice
By default, all masks match each other.

Usage Example

Suppose we have two objects with the same material. To make one of them appear in the viewport and the other one not to be rendered, we need to change the viewport mask. Both objects have the same object, material and light masks, but the viewport masks differ, so we get the following result:

MaskValue
Camera Viewport0 1 1 1
1st Object Surface Viewport0 0 0 1
2nd Object Surface Viewport1 0 0 0
Material Viewport0 0 1 0
Light Viewport0 1 0 0
MaskValue
Camera Viewport1 1 1 0
1st Object Surface Viewport0 0 0 1
2nd Object Surface Viewport1 0 0 0
Material Viewport0 0 1 0
Light Viewport0 1 0 0
1st surface matching the viewport mask
2nd surface matching the viewport mask

Reflections from Objects

Reflections from objects can also be selectively rendered into the viewport: an object can be rendered without reflection or only reflection without an object itself. For the object to be rendered with reflections, the camera's reflection mask should match with:

  1. A reflection mask of the reflecting material (set in the Materials -> Parameters tab -> Reflection Mask).
  2. A viewport mask of the reflecting material
  3. A viewport mask of the reflected material
  4. Object's surface viewport mask
  5. A light viewport mask
Notice
By default, all objects are rendered with reflections.

Usage Example

Let's discuss reflection masking for two cases: an object without a reflection and reflection without an object.

  • To render an object without reflection, either its surface viewport mask or its material viewport mask should not match the camera reflection mask.
  • To render a reflection without a surface, its surface viewport mask or its material viewport mask should not match the camera viewport mask.

An object without the reflection A reflection without the object
MaskValue
Viewport for camera0 0 1 1
Reflection for camera1 1 0 0
Viewport for object surface0 0 0 1
Viewport for object reflected material0 0 1 0
Reflection for reflecting material0 0 0 0
Viewport for reflecting material0 0 0 1
Viewport for light1 1 1 1
MaskValue
Viewport for camera0 0 1 1
Reflection for camera1 1 0 0
Viewport for object surface1 0 0 0
Viewport for object reflected material1 0 1 0
Reflection for reflecting material1 0 0 0
Viewport for reflecting material0 0 0 1
Viewport for light1 1 1 1

Masked reflections

Light Mask

For the surface to be illuminated only by the chosen light sources, a bit mask should be used. Matching this mask to the one of light source (one bit, at least), allows you to control the intensity of the object illumination.

Decal Mask

A decal mask specifies objects, onto which the decal can be projected. An object can receive the decal if its mask corresponds to this mask.

Last update: 2017-07-03