Skip to content

Commit 94fe6b0

Browse files
Richard-HortonEvergreen
authored andcommitted
URP Docs: Camera Stacking
Add new docs and update existing docs for Camera Stacking in URP
1 parent b9b4964 commit 94fe6b0

10 files changed

+123
-70
lines changed
253 KB
Loading

Packages/com.unity.render-pipelines.universal/Documentation~/TableOfContents.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
* [Anti-aliasing in URP](anti-aliasing.md)
7070
* [Motion vectors](features/motion-vectors.md)
7171
* [Use multiple cameras](cameras-multiple.md)
72+
* [Understand camera stacking](cameras/camera-stacking-concepts.md)
7273
* [Set up a camera stack](camera-stacking.md)
74+
* [Add and remove cameras in a camera stack](cameras/add-and-remove-cameras-in-a-stack.md)
7375
* [Set up split-screen rendering](rendering-to-the-same-render-target.md)
7476
* [Apply different post processing effects to separate cameras](cameras/apply-different-post-proc-to-cameras.md)
7577
* [Render a camera's output to a Render Texture](rendering-to-a-render-texture.md)

Packages/com.unity.render-pipelines.universal/Documentation~/camera-component-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Overlay cameras expose the following properties:
103103
104104
A camera stack allows to composite results of several cameras together. The camera stack consists of a Base camera and any number of additional Overlay cameras.
105105

106-
You can use the stack property add Overlay cameras to the stack and they will render in the order as defined in the stack. For more information on configuring and using Camera Stacks, refer to [Camera Stacking](camera-stacking.md).
106+
You can use the stack property add Overlay cameras to the stack and they will render in the order as defined in the stack. For more information on configuring and using camera stacks, refer to [Set up a camera stack](camera-stacking.md).
107107

108108
<a name="Environment"></a>
109109

Lines changed: 20 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,33 @@
11
# Set up a camera stack
22

3-
In the Universal Render Pipeline (URP), you use Camera Stacking to layer the output of multiple Cameras and create a single combined output. Camera Stacking allows you to create effects such as a 3D model in a 2D UI, or the cockpit of a vehicle.
3+
This page describes how to use a camera stack to layer outputs from multiple cameras to the same render target. For more information on camera stacking, refer to [Understand camera stacking](cameras/camera-stacking-concepts.md).
44

5-
![Camera Stacking in URP](Images/camera-stacking-example.png)
5+
![A red capsule with a post-processing effect, and a blue capsule with no post-processing](Images/camera-stacking-blur-background.png)<br/>*An example of a scene that uses camera stacking to render a red capsule with a post-processing effect, and a blue capsule with no post-processing.*
66

7-
A Camera Stack consists of a [Base Camera](camera-types-and-render-type.md#base-camera) and one or more [Overlay Cameras](camera-types-and-render-type.md#overlay-camera). A Camera Stack overrides the output of the Base Camera with the combined output of all the Cameras in the Camera Stack. As such, anything that you can do with the output of a Base Camera, you can do with the output of a Camera Stack. For example, you can render a Camera Stack to a given render target, apply post-process effects, and so on.
7+
Follow these steps to set up a camera stack:
88

9-
URP performs several optimizations within a Camera, including rendering order optimizations to reduce overdraw. However, when you use a Camera Stack, you effectively define the order in which those Cameras are rendered. You must therefore be careful not to order the Cameras in a way that causes excessive overdraw. For more information on overdraw in URP, refer to [Advanced information](cameras-advanced.md).
9+
1. [Create a camera stack](#create-a-camera-stack).
10+
2. [Set up layers and culling masks](#set-up-layers-and-culling-masks).
1011

11-
For examples of how to use Camera Stacking, refer to the [Camera Stacking samples in URP Package Samples](package-sample-urp-package-samples.md#camera-stacking).
12+
## Create a camera stack
1213

13-
<a name="adding-a-camera-to-a-camera-stack"></a>
14+
Create a camera stack with a Base Camera and one or more Overlay Cameras.
1415

15-
## Adding a Camera to a Camera Stack
16+
For more information on how to do this, refer to [Add a camera to a camera stack](cameras/add-and-remove-cameras-in-a-stack.md#add-a-camera-to-a-camera-stack).
1617

17-
![Adding a Camera to a Camera Stack](Images/camera-stack-add-camera.png)
18+
## Set up layers and culling masks
1819

19-
1. Create a Camera in your scene. Its **Render Type** defaults to **Base**, making it a Base Camera.
20-
2. Create another Camera in your scene, and select it.
21-
3. In the Camera Inspector, change the Camera’s **Render Type** to **Overlay**.
22-
4. Select the Base Camera again. In the Camera Inspector, scroll to the Stack section, click the **plus (+)** button, and click the name of the Overlay Camera.
20+
Once you create your camera stack, you must assign any GameObjects the Overlay Cameras need to render to a [layer](xref:Layers), then set the **Culling Mask** of each camera to match the layer.
2321

24-
The Overlay Camera is now part of the Base Camera's Camera Stack. Unity renders the Overlay Camera's output on top of the Base Camera's output.
22+
To do this use the following steps:
2523

26-
You can add a Camera to a Camera Stack in a script by directly manipulating the `cameraStack` property of the Base Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component, like this:
24+
1. Add as many layers as your project requires. For information on how to do this, refer to [Add a new layer](xref:create-layers).
25+
2. For each GameObject you want an Overlay Camera to render, assign the GameObject to the appropriate layer.
26+
3. Select the Base Camera of your camera stack and navigate to **Rendering** > **Culling Mask** in the Inspector Window.
27+
4. Remove any layers you don't want the Base Camera to render, such as layers that contain objects only an Overlay Camera should render.
28+
5. Select the first Overlay Camera in the camera stack and navigate to **Rendering** > **Culling Mask** in the Inspector window.
29+
6. Remove all layers except for the layers that contain GameObjects you want this camera to render.
30+
7. Repeat Step 5 and Step 6 for each Overlay Camera in the camera stack.
2731

28-
```c#
29-
var cameraData = camera.GetUniversalAdditionalCameraData();
30-
cameraData.cameraStack.Add(myOverlayCamera);
31-
```
32-
33-
## Removing a Camera from a Camera Stack
34-
35-
![Removing a Camera from a Camera Stack](Images/camera-stack-remove-camera.png)
36-
37-
1. Create a Camera Stack that contains at least one Overlay Camera. For instructions, refer to [Adding a Camera to a Camera Stack](#adding-a-camera-to-a-camera-stack).
38-
2. Select the Camera Stack's Base Camera.
39-
3. In the Camera Inspector, scroll to the Stack section, click the name of the Overlay Camera you want to remove, and then click the **minus (-)** button.
40-
41-
The Overlay Camera remains in the scene, but is no longer part of the Camera Stack.
42-
43-
You can remove a Camera from a Camera Stack in a script by directly manipulating the `cameraStack` property of the Base Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component, like this:
44-
45-
```c#
46-
var cameraData = camera.GetUniversalAdditionalCameraData();
47-
cameraData.cameraStack.Remove(myOverlayCamera);
48-
```
49-
50-
## Changing the order of Cameras in a Camera Stack
51-
52-
![Removing a Camera from a Camera Stack](Images/camera-stack-reorder.png)
53-
54-
1. Create a Camera Stack that contains more than one Overlay Camera. For instructions, refer to [Adding a Camera to a Camera Stack](#adding-a-camera-to-a-camera-stack).
55-
2. Select the Base Camera in the Camera Stack.
56-
3. In the Camera Inspector, scroll to the Stack section.
57-
4. Use the handles next to the names of the Overlay Cameras to reorder the list of Overlay Cameras.
58-
59-
The Base Camera renders the base layer of the Camera Stack, and the Overlay Cameras in the stack render on top of this in the order that they are listed, from top to bottom.
60-
61-
You can reorder a Camera Stack in a script by directly manipulating the `cameraStack` property of the Base Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component.
62-
63-
## Adding the same Overlay Camera to multiple stacks
64-
65-
To add an Overlay Camera to multiple Camera Stacks:
66-
67-
1. Create a Camera Stack that contains at least one Overlay Camera. For instructions, refer to [Adding a Camera to a Camera Stack](#adding-a-camera-to-a-camera-stack).
68-
2. Create a Camera in your scene. Its **Render Type** defaults to **Base**, making it a Base Camera.
69-
3. Select the new Base Camera.
70-
4. In the Camera Inspector, scroll to the Stack section, click the *plus (+)* button, and click the name of the Overlay Camera that you want to use in both Camera Stacks.
71-
72-
The Overlay Camera is now rendering in both Camera Stacks.
73-
74-
You can also add a Camera to a Camera Stack in a script by directly manipulating the `cameraStack` property of the Base Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component, like this:
75-
76-
```c#
77-
var cameraData = camera.GetUniversalAdditionalCameraData();
78-
cameraData.cameraStack.Add(myOverlayCamera);
79-
```
32+
> [!NOTE]
33+
> You don't need to configure the **Culling Mask** property of the cameras. However, cameras in URP render all layers by default, so rendering is faster if you remove layers that contain unneeded GameObjects.

Packages/com.unity.render-pipelines.universal/Documentation~/cameras-multiple.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
In the Universal Render Pipeline (URP), you can use multiple cameras to work with multiple camera outputs and targets, as well as different output resolutions and post-processing effects.
44

55
> [!NOTE]
6-
> If you use multiple cameras, it might make rendering slower. An active camera adds extra calls to the rendering loop even if it renders nothing.
6+
> If you use multiple cameras, it might make rendering slower. An active camera runs through the entire rendering loop even if it renders nothing.
77
88
![An example of the effect camera stacking can produce in URP](Images/camera-stacking-example.png)<br/>*An example of the effect camera stacking can produce in URP.*
99

10-
You can combine these ways of working for more complex effects. For example, you can define two Camera Stacks, and then set each of those to Camera Stacks that render to a different area of the same render target.
10+
You can combine these ways of working for more complex effects. For example, you can define two camera stacks, and then set each of those to camera stacks that render to a different area of the same render target.
1111

1212
For information on Camera rendering order when working with multiple Cameras, refer to [Understand camera render order](cameras-advanced.md).
1313

1414
| Page | Description |
1515
|-|-|
16-
| [Set up a camera stack](camera-stacking.md)| Stack cameras to layer the outputs of multiple cameras into a single combined output. Camera stacking allows you to create effects such as 3D models in a 2D UI, or the cockpit of a vehicle.|
16+
| [Understand camera stacking](cameras/camera-stacking-concepts.md)| Learn the fundamental concepts of camera stacking. |
17+
| [Set up a camera stack](camera-stacking.md)| Stack cameras to layer the outputs of multiple cameras into a single combined output. |
18+
| [Add and remove cameras in a camera stack](cameras/add-and-remove-cameras-in-a-stack.md)| Add, remove, and reorder cameras within a camera stack. |
1719
| [Set up split-screen rendering](rendering-to-the-same-render-target.md) | Render multiple camera outputs to a single render target to create effects such as split screen rendering. |
1820
| [Apply different post processing effects to separate cameras](cameras/apply-different-post-proc-to-cameras.md) | Apply different post-processing setups to individual cameas within a scene. |
1921
| [Render a camera's output to a Render Texture](rendering-to-a-render-texture.md) | Render to a Render Texture to create effects such as in-game CCTV monitors. |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Add and remove cameras in a camera stack
2+
3+
Camera stacks contain a single Base Camera with one or more Overlay Cameras stacked on top. In the Editor, you can add, remove, and reorder these cameras as much as you like to achieve the desired effects.
4+
5+
This page is split into the following sections:
6+
7+
* [Add a camera to a camera stack](#add-a-camera-to-a-camera-stack)
8+
* [Remove a camera from a camera stack](#remove-a-camera-from-a-camera-stack)
9+
* [Reorder cameras in a camera stack](#reorder-cameras-in-a-camera-stack)
10+
11+
## Add a camera to a camera stack
12+
13+
To add a camera to a camera stack, use the following steps:
14+
15+
1. Select a Camera in your scene with the **Render Type** set to **Base**, making it a Base Camera. If you do not have a Base Camera in your scene, create one.
16+
2. Create another camera in your scene, and select it.
17+
3. In the camera Inspector window, set the **Render Type** to **Overlay**.
18+
4. Select the Base Camera again. In the camera Inspector window, go to the **Stack** section, select **Add** (**+**), then select the name of the Overlay Camera.
19+
20+
The Overlay Camera is now part of the Base Camera's camera stack. Unity renders the Overlay Camera's output on top of the Base Camera's output.
21+
22+
> [!NOTE]
23+
> When you create multiple cameras for a camera stack, consider whether the cameras are all necessary. Each camera you add makes rendering slower, because an active camera runs through the entire rendering loop even if it renders nothing.
24+
25+
<a name="add-a-camera-with-a-script"></a>
26+
27+
### Add a camera to a camera stack with a C# script
28+
29+
You can also add a camera to a camera stack with a C# script. Use the `cameraStack` property of the Base Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component, as shown below:
30+
31+
```c#
32+
var cameraData = camera.GetUniversalAdditionalCameraData();
33+
cameraData.cameraStack.Add(myOverlayCamera);
34+
```
35+
36+
## Remove a camera from a camera stack
37+
38+
To remove a camera from a camera stack, use the following steps:
39+
40+
1. Create a camera stack that contains at least one Overlay Camera. For instructions, refer to [Add a camera to a camera stack](#add-a-camera-to-a-camera-stack).
41+
2. Select the camera stack's Base Camera.
42+
3. In the camera Inspector window, go to the **Stack** section, select the name of the Overlay Camera you want to remove, then then select **Remove** (**-**).
43+
44+
The Overlay Camera remains in the scene, but is no longer part of the camera stack.
45+
46+
<a name="remove-a-camera-with-a-script"></a>
47+
48+
### Remove a camera from a camera stack with a C# script
49+
50+
You can also remove a Camera from a camera stack with a C# script. Use the `cameraStack` property of the Base Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component, as shown below:
51+
52+
```c#
53+
var cameraData = camera.GetUniversalAdditionalCameraData();
54+
cameraData.cameraStack.Remove(myOverlayCamera);
55+
```
56+
57+
## Reorder cameras in a camera stack
58+
59+
To reorder the cameras in a camera stack, use the following steps:
60+
61+
1. Create a camera stack that contains more than one Overlay Camera. For instructions, refer to [Add a camera to a camera stack](#add-a-camera-to-a-camera-stack).
62+
2. Select the Base Camera in the camera stack.
63+
3. In the Camera Inspector, go to the **Stack** section.
64+
4. Use the handles next to the names of the Overlay Cameras to reorder the list of Overlay Cameras.
65+
66+
The Base Camera renders the base layer of the camera stack, and the Overlay Cameras in the stack render on top of this in the order that they are listed, from top to bottom.
67+
68+
<a name="reorder-a-camera-stack-with-a-script"></a>
69+
70+
### Reorder a camera from a camera stack with a C# script
71+
72+
You can also reorder a camera stack with a C# script. Use the `cameraStack` property of the Base Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component. The `cameraStack` is a `List` and can be reordered in the same way as any other `List`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Understand camera stacking
2+
3+
In the Universal Render Pipeline (URP), you use camera stacking to layer the output of multiple Cameras and create a single combined output. Camera stacking allows you to create effects such as a 3D model in a 2D UI, or the cockpit of a vehicle.
4+
5+
A camera stack consists of a [Base Camera](../camera-types-and-render-type.md#base-camera) and one or more [Overlay Cameras](../camera-types-and-render-type.md#overlay-camera). A camera stack overrides the output of the Base Camera with the combined output of all the cameras in the camera stack. As a result, anything you can do with the output of a Base Camera, you can do with the output of a camera stack. For example, you can render a camera stack to a render target, or apply post-processing effects.
6+
7+
Refer to [Set up a camera stack](../camera-stacking.md) for more information. To download examples of camera stacking in URP, install the [Camera Stacking samples](../package-sample-urp-package-samples.md#camera-stacking).
8+
9+
## Camera stacking and rendering order
10+
11+
URP performs several optimizations within a camera, including rendering order optimizations to reduce overdraw. However, when you use a camera stack, you define the order in which URP renders the cameras. You must be careful not to order the cameras in a way that causes excessive overdraw. For more information on overdraw in URP, refer to [Rendering order optimizations](../cameras-advanced.md#rendering-order-optimizations).
12+
13+
## Camera stacking and post-processing
14+
15+
You should only apply post-processing to the last camera in the stack, so the following applies:
16+
17+
* URP renders the post-processing effects only once, not repeatedly for each camera.
18+
* The visual effects are consistent, because all the cameras in the stack receive the same post-processing.
19+
20+
## Additional resources
21+
22+
* [Set up a camera stack](../camera-stacking.md)
23+
* [Camera component reference](../camera-component-reference.md)

0 commit comments

Comments
 (0)