Skip to content

Unity project demonstrating a dual-camera overlay system using alpha-blended composition.

License

Notifications You must be signed in to change notification settings

MSTS-S/Unity-DualCameraOverlay

Repository files navigation

Unity-DualCameraOverlay

This is a Unity project that demonstrates a dual-camera overlay rendering system.
It composites the rendered outputs of two Virtual Cameras with alpha blending, and outputs the final result to the Main Camera.

This project is useful for applications such as:

  • multi-perspective VR/AR visualization
  • mixed overlay UI + world rendering
  • experimental multi-camera composition pipelines

Project thumbnail image



Overview

This Unity project implements a dual-camera overlay system that composites two independent camera outputs into a single final view.

In this project, two environments (Env1 and Env2) are rendered separately by two Virtual Cameras.
Their outputs are then alpha-blended (transparent overlay composition) and displayed through the Main Camera.

This allows two different scenes (or layers) to be visually merged in real time.


Rendering Flow

Env1 camera output

Env2 camera output


↓ Alpha-blended composition (Dual Camera Overlay) ↓


Final composited output


The transparency of each camera layer can be adjusted dynamically, enabling smooth blending and flexible visualization of multiple camera perspectives.



Environment

This project was developed and tested with the following environment:

  • Unity: 2022.3.28f1
  • Render Pipeline: Built-in Render Pipeline
  • XR Interaction Toolkit: 2.5.4
  • XR Plugin Management: 4.5.4
  • OpenXR Plugin: 1.10.0
  • Stereo Rendering Mode: Multi Pass (Single Pass is NOT supported)



Quick Start

Follow the steps below to run the Dual Camera Overlay system.

1. Add the DualCameraCompositor script

Add the DualCameraCompositor component to your Main Camera.

2. Create two Virtual Cameras

Under the following hierarchy:

XR Origin (XR Rig)
├── Camera Offset
│   ├── Main Camera
│   ├── Virtual Camera 1
│   └── Virtual Camera 2

Create two standard Unity Camera objects:

  • Virtual Camera 1
  • Virtual Camera 2

3. Assign Virtual Cameras

In the DualCameraCompositor inspector, assign:

  • Virtual Camera Env 1Virtual Camera 1
  • Virtual Camera Env 2Virtual Camera 2

4. Configure Layer Settings

Assign your scene objects to Unity Layers (e.g., Env 1 and Env 2), then set the Layer Masks:

  • Layer Mask Camera Env 1
  • Layer Mask Camera Env 2

This determines which objects are rendered by each Virtual Camera.

5. Press Play

Press the Unity Play button to run the system.
The outputs of the two Virtual Cameras will be alpha-blended and displayed through the Main Camera.



Configuration (Layer & Alpha Settings)

This project allows you to configure which objects are rendered by each Virtual Camera using Unity Layers.

In the Dual Camera Compositor component, you can specify:

  • Layer Mask Camera Env L: the Layer rendered by Virtual Camera 1 (Env 1)
  • Layer Mask Camera Env R: the Layer rendered by Virtual Camera 2 (Env 2)

This makes it possible to separate two environments (or two object groups) into independent camera outputs.

In addition, you can control the transparency of each camera output individually:

  • Alpha Env L: transparency of Env 1 output
  • Alpha Env R: transparency of Env 2 output

By adjusting these alpha values, the two camera views can be blended smoothly in real time.

Dual Camera Compositor Inspector Settings



Inspector Parameters

Below is a summary of the parameters available in the DualCameraCompositor component.

Category Parameter Description
Virtual Cameras Virtual Camera Env 1 Camera used to render Env 1 (left layer).
Virtual Cameras Virtual Camera Env 2 Camera used to render Env 2 (right layer).
Layer Settings Layer Mask Camera Env 1 LayerMask used by Virtual Camera Env 1. Only objects in this layer will be rendered.
Layer Settings Layer Mask Camera Env 2 LayerMask used by Virtual Camera Env 2. Only objects in this layer will be rendered.
Main Camera Clipping Planes Main Camera Near Clip Near clipping plane value for the Main Camera.
Main Camera Clipping Planes Main Camera Far Clip Far clipping plane value for the Main Camera.
Alpha Settings Alpha Env L Alpha blending weight for Env 1 output. (0 = invisible, 1 = fully visible)
Alpha Settings Alpha Env R Alpha blending weight for Env 2 output. (0 = invisible, 1 = fully visible)
Render Textures Render Texture Width Width of the internal RenderTexture used for each Virtual Camera.
Render Textures Render Texture Height Height of the internal RenderTexture used for each Virtual Camera.
Render Textures Depth Buffer Depth buffer bit depth used for the RenderTextures (e.g., 24).



About

Unity project demonstrating a dual-camera overlay system using alpha-blended composition.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published