Home

Awesome

HDRP UI Camera Stacking

The HDRP UI Camera Stacking package allows you to stack multiple camera rendering UI only at a fraction of the cost of a standard camera.

This is achieved by taking advantage of the customRender feature to render only the GUI elements and nothing else, with the only downside to not be able to render Lit objects which are generally not found for UI.

https://user-images.githubusercontent.com/6877923/127684238-1f149a4f-1677-4428-b3f8-7ba51c6c93d6.mp4

This implementation also provides all the benefits of standard camera stacking:

Installation

The UI Camera Stacking package supports the following versions:

Unity VersionHDRP VersionCompatible
2019.4.x7.x
2020.1.x8.x
2020.2.x and 2020.3.x10.x✔️
2021.1.x11.x✔️
2021.2.x12.x✔️
2022.1.x13.x✔️
2022.2.x14.x✔️
2022.3.x14.x✔️
2023.1.x15.x✔️
2023.2.x16.x✔️
6000.0.x17.x✔️
<details><summary>Instructions</summary>

HDRP UI Camera stacking is available on the OpenUPM package registry, to install it in your project, follow the instructions below.

  1. Open the Project Settings and go to the Package Manager tab.
  2. In the Scoped Registry section, click on the small + icon to add a new scoped registry and fill the following information:
Name:     Open UPM
URL:      https://package.openupm.com
Scope(s): com.alelievr
  1. Next, open the Package Manager window, select My Registries in the top left corner and you should be able to see the HDRP UI Camera Stacking package.
  2. Click the Install button and you can start using the package :)

PackageManager

:warning: If you don't see My Registries in the dropdown for some reason, click on the + icon in the top left corner of the package manager window and select Add package from Git URL, then paste com.alelievr.hdrp-ui-camera-stacking and click Add.

Note that sometimes, the package manager can be slow to update the list of available packages. In that case, you can force it by clicking the circular arrow button at the bottom of the package list.

</details>

Tutorial

First, create a UI Camera gameobject with the menu UI > Camera (HDRP)

image

In this new UI Camera there is a component called HD Camera UI, this is the component that will do the rendering of the UI. It's important to correctly configure this component because the camera depth and culling mask are ignored when this component is added.

In the UI Camera gameobject a canvas was also created and correctly configured with the "Screen Space - Camera" mode. You can add your UI in this canvas.

image

PropertyDescription
Ui Layer MaskLayer mask of your UI objects, by default it's set to UI.
PriorityUsed to define a draw order between the UI cameras, a high priority means rendered in front of the other cameras.
Compositing ModeSelect how you want the compositing to happen. By default the Automatic will blend the UI render texture with the camera color after the camera rendering. The Custom mode allows you to replace the compositing material by your own fullscreen shader. The Manual mode disables the compositing and you have to do your own one with the renderTexture field in HDCameraUI.
Target CameraSpecifies which camera will receive the UI. By default the Main value only adds the UI to the main camera. The All value outputs the UI to every camera in the scene. The Layer value allows you to filter cameras by layer. The Specific mode allows you to only output the UI to a specific camera.
Graphics FormatFormat of the color buffer used to render the UI, the default is 16 bit RGBA to avoid banding and keep the alpha channel.
Render In Camera BufferIf true, the UI will also be rendered in the attached camera color buffer.

Performances

In HDRP using more than one camera have a very high performance cost. While you can avoid most of the performance issue on the GPU side with correct culling settings and disabling almost every in the frame settings, you won't be able to escape the CPU cost.

The scenes used for the performance test are available in the Benchmark folder of the project. For HDRP, the Graphics Compositor was used to perform the UI camera stacking. The UI camera had custom frame settings optimized to render GUI (transparent unlit objects).

All performance metrics were captured at a resolution of 1920x1080 on Windows 10 in the Unity Editor.

SetupCPU Time (ms)GPU Time (ms)
HDRP camera stacking~1.350.45
Custom UI camera stacking~0.100.18

Without much surprise, we can see a big difference on CPU side, mostly because we're skipping all the work of a standard HDRP camera. On the GPU side things are pretty even though the camera is still a bit slower because of the overhead of compute shader and fullscreen passes that can't be disabled in the frame settings.

<details><summary>System Information</summary> </details>

Limitations

Rendering Lit objects is not supported. Currently the UI rendering happen before the rendering of the main camera, thus before any lighting structure is built so it's not possible to access the lighting data when rendering the UI for camera stacking.

Future Improvements