Multiple Camera Compositing

Learn how to make a Unity project work with a multi-LeiaCamera setup.

When developing Unity content for Leia displays, it is common practice that developers will want two separate cameras: one to render the 3d scene, and another to render the UI on top of it. This has several benefits, including ensuring the UI is always rendered on top and enabling having different lighting and camera settings for the UI than for the scene camera. The Multiple Camera Compositing sample scene provides an example demonstrating how a multi-camera setup can be implemented using the Leia Unity SDK. The sample scene can be found in Assets/LeiaLoft/Examples/MultipleCameraCompositing.

The hierarchy of the MultipleCameras sample scene has two cameras: the Game Camera, and the UI Camera. Both cameras are rendering 3d objects to the display simultaneously with the UI Camera rendering on top and using alpha blending to show the Game Camera below.

The UI Camera renders the buttons:

While the Game Camera renders the background, asteroids, player space ship, and everything else contained in the game scene:

Setup

The following outlines a method to setup a multi-LeiaCamera configuration in your project for a 3d scene with a 3d UI rendered on top of it

Step 1 - Create Cameras

Create two cameras in your scene, and attach the LeiaCamera component to both. For this example, we will name the first one Game Camera, and a second UI Camera.

Step 2 - Set the Camera's Depths

Set the Game Camera's depth to a lower value, like -1, and the UI Camera's depth to a higher value, like 1, to ensure the UI Camera is rendered on top of the scene camera.

Step 3 - Set culling masks

Set the culling mask of the UI Camera to "UI". Set the culling mask of the scene camera to include every layer except UI.

Step 4 - Set the layers of UI objects

Set the layer of all the 3D UI objects in your scene to "UI"

Step 5 - Set Clear Flags and Background Color Alpha

Set the clear flags for the UI Camera to "Solid Color" and set the background color's alpha to 0.

Step 6 - Enable Multi Camera Compositing

Check the "Enable Alpha Blending" checkbox in the LeiaDisplay component

Now when we run the game, we should see the 3d UI rendered on top of the rest of the scene.

Last updated

Copyright © 2023 Leia Inc. All Rights Reserved