• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language ShaderLab
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Optimized implementation of camera stacking for UI only in HDRP.

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.

UI.mp4

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

  • No post process bleeding on UI (motion vectors, ect.)
  • No clipping in the geometry

Installation

The UI Camera Stacking package supports the following versions:

Unity Version HDRP Version Compatible
2019.4.x 7.x ❌
2020.1.x 8.x ❌
2020.2.x and 2020.3.x 10.x βœ”οΈ
2021.1.x 11.x βœ”οΈ
2021.2.x 12.x βœ”οΈ
2022.1.x 13.x βœ”οΈ
2022.2.x 14.x βœ”οΈ
Instructions

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

⚠️ 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.

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

Property Description
Ui Layer Mask Layer mask of your UI objects, by default it's set to UI.
Priority Used to define a draw order between the UI cameras, a high priority means rendered in front of the other cameras.
Compositing Mode Select 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 Camera Specifies 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 Format Format 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 Buffer If 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.

Setup CPU Time (ms) GPU Time (ms)
HDRP camera stacking ~1.35 0.45
Custom UI camera stacking ~0.10 0.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.

System Information
  • System: Windows 10 Pro, DirectX 11
  • CPU: i9-10980k 3.00GHz 18 cores
  • GPU: RTX 3090

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

  • Fullscreen effect applied after rendering the UI
  • Add an injection point before post processes
  • Support post processing volumes for UI Cameras.

More Repositories

1

NodeGraphProcessor

Node graph editor framework focused on data processing using Unity UIElements and C# 4.6
C#
2,137
star
2

HDRP-Custom-Passes

A bunch of custom passes made for HDRP
C#
1,260
star
3

Mixture

Mixture is a powerful node-based tool crafted in unity to generate all kinds of textures in realtime
C#
930
star
4

libft-unit-test

C
447
star
5

Procedural-Worlds-Editor

Procedural World Editor is a node based procedural terrain generator
C#
273
star
6

MasterUnityHandles

Unity custom handles examples
C#
96
star
7

printf-unit-test

C++
30
star
8

SOIL2

C
15
star
9

ProceduralTerrainGPU

HLSL
11
star
10

shaderRender

C
9
star
11

PolygonBurst

C#
7
star
12

VoxelEngine

Vulkan engine in c++ exploiting the compute shaders to generate voxel terrain
C++
6
star
13

ShaderSourceExtractor

Unity shader source extractor
ShaderLab
5
star
14

MixAndGameJam_2019

Mix and Game jam 2019
C#
5
star
15

PostEffects

Small unity post processing effects missing from the post processing stack
C#
5
star
16

THE_FUTURE

program used to render shaders on multiple imacs during the artistik rezo party
GLSL
5
star
17

UnityGraphSerialization

Unity graph serialization tests
C#
4
star
18

42sh

42sh
C
4
star
19

LightweightGraphicCore

Lightweight Graphic Vulkan wrapper to manage windows, allocations, shader compilation, GUI and more
C++
4
star
20

DistanceFieldGraph

C#
3
star
21

GGJ2019

C#
3
star
22

ProceduralTextureExporter

C#
3
star
23

Mixture-dev

ShaderLab
3
star
24

DistributionVisualization

C#
2
star
25

Coders-of-the-caribbean

Unity visualizer for CondiinGame challenge: Coders of the Caribbean
C#
2
star
26

Ludum-Dare-43

C#
2
star
27

Touhou-jam

C#
1
star
28

2D-JamStartupKit

A Unity kit of assets and scripts for game jams
C#
1
star
29

Unity-analytics-test

C#
1
star
30

JamKit

A bunch of useful scripts for jam games
C#
1
star
31

Binary-Security

C
1
star
32

Open-Game-Jam-1

C#
1
star
33

AudioFractal

Little Audio fractal visualizer using KlakLasp
C#
1
star
34

malloc

C
1
star
35

HDRP-Mobile

Unlock HDRP to build on mobile devices
C#
1
star