Skip to content

Commit

Permalink
URP Docs: Backport Camera Docs Overhaul [2021.3]
Browse files Browse the repository at this point in the history
Backports the following PRs to 2021.3 version of URP docs with any version appropriate changes:
- #44239 
- #44926 
- #45311 
- #45429
  • Loading branch information
Richard-Horton authored and Evergreen committed May 15, 2024
1 parent 5948942 commit 63d855b
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 246 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@
* [Light Layers](lighting/light-layers.md)
* [Lens Flare asset](shared/lens-flare/lens-flare-asset.md)
* [Cameras](cameras.md)
* [The Universal Additional Camera Data component](universal-additional-camera-data.md)
* [Render Type](camera-types-and-render-type.md)
* [Working with multiple cameras](cameras-multiple.md)
* [Camera Stacking](camera-stacking.md)
* [Rendering from multiple Cameras to the same render target](rendering-to-the-same-render-target.md)
* [Rendering to a Render Texture](rendering-to-a-render-texture.md)
* [Clearing, rendering order and overdraw](cameras-advanced.md)
* [Anti-aliasing](anti-aliasing.md)
* [Camera component reference](camera-component-reference.md)

* [Cameras in URP](cameras/camera-differences-in-urp.md)
* [Understand camera render order](cameras-advanced.md)
* [Camera render types](camera-types-and-render-type.md)
* [Anti-aliasing in URP](anti-aliasing.md)
* [Use multiple cameras](cameras-multiple.md)
* [Understand camera stacking](cameras/camera-stacking-concepts.md)
* [Set up a camera stack](camera-stacking.md)
* [Add and remove cameras in a camera stack](cameras/add-and-remove-cameras-in-a-stack.md)
* [Set up split-screen rendering](rendering-to-the-same-render-target.md)
* [Apply different post processing effects to separate cameras](cameras/apply-different-post-proc-to-cameras.md)
* [Render a camera's output to a Render Texture](rendering-to-a-render-texture.md)
* [Customize a camera](universal-additional-camera-data.md)
* [Camera component properties](camera-component-reference.md)
* [Physical Camera properties](cameras/physical-camera-reference.md)
* [Post-processing](integration-with-post-processing.md)
* [How to configure](integration-with-post-processing.md#post-proc-how-to)
* [Volumes](Volumes.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ To enable MSAA:

For more information on the available settings, see the [MSAA setings in the URP Asset](universalrp-asset.md#quality).

**Note**: On mobile platforms that don't support the [StoreAndResolve](https://docs.unity3d.com/ScriptReference/Rendering.RenderBufferStoreAction.StoreAndResolve.html) store action, if **Opaque Texture** is selected in the **URP Asset**, Unity ignores the **MSAA** property at runtime (as if **MSAA** is set to **Disabled**).
> [!NOTE]
> On mobile platforms that don't support the [StoreAndResolve](https://docs.unity3d.com/ScriptReference/Rendering.RenderBufferStoreAction.StoreAndResolve.html) store action, if **Opaque Texture** is selected in the **URP Asset**, Unity ignores the **MSAA** property at runtime (as if **MSAA** is set to **Disabled**).

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,77 +1,33 @@
# Camera Stacking
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.
# Set up a camera stack

![Camera Stacking in URP](Images/camera-stacking-example.png)
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).

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.
![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.*

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, see [Advanced information](cameras-advanced.md).
Follow these steps to set up a camera stack:

For examples of how to use Camera Stacking, see the [Camera Stacking samples in URP Package Samples](package-sample-urp-package-samples.md#camera-stacking).
1. [Create a camera stack](#create-a-camera-stack).
2. [Set up layers and culling masks](#set-up-layers-and-culling-masks).

<a name="adding-a-camera-to-a-camera-stack"></a>
## Adding a Camera to a Camera Stack
## Create a camera stack

![Adding a Camera to a Camera Stack](Images/camera-stack-add-camera.png)
Create a camera stack with a Base Camera and one or more Overlay Cameras.

1. Create a Camera in your Scene. Its **Render Type** defaults to **Base**, making it a Base Camera.
2. Create another Camera in your Scene, and select it.
3. In the Camera Inspector, change the Camera’s **Render Type** to **Overlay**.
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.
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).

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.
## Set up layers and culling masks

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:
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.

```
var cameraData = camera.GetUniversalAdditionalCameraData();
cameraData.cameraStack.Add(myOverlayCamera);
```
To do this use the following steps:

## Removing a Camera from a Camera Stack
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).
2. For each GameObject you want an Overlay Camera to render, assign the GameObject to the appropriate layer.
3. Select the Base Camera of your camera stack and navigate to **Rendering** > **Culling Mask** in the Inspector Window.
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.
5. Select the first Overlay Camera in the camera stack and navigate to **Rendering** > **Culling Mask** in the Inspector window.
6. Remove all layers except for the layers that contain GameObjects you want this camera to render.
7. Repeat Step 5 and Step 6 for each Overlay Camera in the camera stack.

![Removing a Camera from a Camera Stack](Images/camera-stack-remove-camera.png)

1. Create a Camera Stack that contains at least one Overlay Camera. For instructions, see [Adding a Camera to a Camera Stack](#adding-a-camera-to-a-camera-stack).
2. Select the Camera Stack's Base Camera.
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.

The Overlay Camera remains in the Scene, but is no longer part of the Camera Stack.

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:

```
var cameraData = camera.GetUniversalAdditionalCameraData();
cameraData.cameraStack.Remove(myOverlayCamera);
```

## Changing the order of Cameras in a Camera Stack

![Removing a Camera from a Camera Stack](Images/camera-stack-reorder.png)

1. Create a Camera Stack that contains more than one Overlay Camera. For instructions, see [Adding a Camera to a Camera Stack](#adding-a-camera-to-a-camera-stack).
2. Select the Base Camera in the Camera Stack.
3. In the Camera Inspector, scroll to the Stack section.
4. Use the handles next to the names of the Overlay Cameras to reorder the list of Overlay Cameras.

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.

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.

## Adding the same Overlay Camera to multiple stacks

To add an Overlay Camera to multiple Camera Stacks:

1. Create a Camera Stack that contains at least one Overlay Camera. For instructions, see [Adding a Camera to a Camera Stack](#adding-a-camera-to-a-camera-stack).
2. Create a Camera in your Scene. Its **Render Type** defaults to **Base**, making it a Base Camera.
3. Select the new Base Camera.
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.

The Overlay Camera is now rendering in both Camera Stacks.

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:

```
var cameraData = camera.GetUniversalAdditionalCameraData();
cameraData.cameraStack.Add(myOverlayCamera);
```
> [!NOTE]
> 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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Render Type
# Camera render types

There are two types of Camera in the Universal Render Pipeline (URP):

Expand All @@ -21,12 +21,14 @@ To change the type of a Camera in the Unity Editor:

You can change a Camera’s type in a script, by setting the `renderType` property of the Camera's [Universal Additional Camera Data](xref:UnityEngine.Rendering.Universal.UniversalAdditionalCameraData) component, like this:

```
```c#
var cameraData = camera.GetUniversalAdditionalCameraData();
cameraData.renderType = CameraRenderType.Base;
```

## <a name="base-camera"></a>Base Camera
<a name="base-camera"></a>

## Base Camera

Base Camera is the default type of Camera in URP. A Base Camera is a general purpose Camera that renders to a given render target.

Expand All @@ -46,7 +48,8 @@ An Overlay Camera is a Camera that renders its view on top of another Camera's o

You must use Overlay Cameras in conjunction with one or more Base Cameras using the [Camera Stacking](camera-stacking.md) system. You cannot use Overlay Cameras on their own. An Overlay Camera that is not part of a Camera Stack does not perform any steps of its render loop, and is known as an orphan Camera.

__Important note:__ In this version of URP, Overlay Cameras and Camera Stacking are supported only when using the Universal Renderer.
> [!NOTE]
> In this version of URP, Overlay Cameras and Camera Stacking are supported only when using the Universal Renderer.
When you have an active Overlay Camera in your Scene, this icon appears next to the Camera Gizmo in the Scene view:

Expand All @@ -67,6 +70,7 @@ The Base Camera in a Camera Stack determines most of the properties of the Camer

Unity hides all of the other unused properties in the Inspector. You can access unused properties using a script, but any changes you make to these unused properties will not affect the visual output of any Camera Stacks that use the Overlay Camera.

You cannot apply post-processing to an individual Overlay Camera. You can apply post-processing to an individual Base Camera, or to a Camera Stack.
> [!NOTE]
> While you can apply post-processing to an individual Overlay Camera within a camera stack, the effects also apply to all the outputs the camera stack renders before the Overlay Camera. This is different to how you can apply post-processing to an individual Base Camera where the effects on only apply to the Base Camera.
For information on the properties that Unity exposes in the Inspector of an Overlay Camera, see the [Camera component reference](camera-component-reference.md).
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Clearing, rendering order and overdraw
<a name="clearing"></a>
## Clearing
# Understand camera render order

This page describes when a Universal Render Pipeline (URP) camera performs the following operations:

* [Clearing the color and depth buffers](#clearing-the-color-and-depth-buffers)
* [Base Camera](#base-camera)
* [Overlay Camera](#overlay-camera)
* [Culling and rendering](#culling-and-rendering)
* [Rendering order optimizations.](#rendering-order-optimizations)

## Clearing the color and depth buffers

In the Universal Render Pipeline (URP), Camera clearing behavior depends on the Camera's [Render Type](camera-types-and-render-type.md).

Expand All @@ -16,7 +24,7 @@ Note that the contents of the uninitialized color buffer vary by platform. On so

A Base Camera always clears its depth buffer at the start of each render loop.

## Overlay Camera
### Overlay Camera

#### Color buffer

Expand All @@ -28,10 +36,9 @@ At the start of its render loop, an Overlay Camera receives a depth buffer conta

When __Clear Depth__ is set to true, the Overlay Camera clears the depth buffer and draws its view to the color buffer on top of any existing color data. When __Clear Depth__ is set to false, the Overlay Camera tests against the depth buffer before drawing its view to the color buffer.

<a name="rendering-order"></a>
## Culling and rendering

## Camera culling and rendering order
If your URP Scene contains multiple Cameras, Unity performs their culling and rendering operations in a predictable order.
If your URP scene contains multiple Cameras, Unity performs their culling and rendering operations in a predictable order.

Once per frame, Unity performs the following operations:

Expand All @@ -54,12 +61,13 @@ Once per frame, Unity performs the following operations:

Unity can render an Overlay Camera’s view multiple times during a frame - either because the Overlay Camera appears in more than one Camera Stack, or because the Overlay Camera appears in the same Camera Stack more than once. When this happens, Unity does not reuse any element of the culling or rendering operation. The operations are repeated in full, in the order detailed above.

__Important note:__ In this version of URP, Overlay Cameras and Camera Stacking are supported only when using the Universal Renderer. Overlay Cameras will not perform any part of their rendering loop if using the 2D Renderer.
<a name="overdraw"></a>
## Overdraw
> [!NOTE]
> In this version of URP, Overlay Cameras and Camera Stacking are supported only when using the Universal Renderer. Overlay Cameras will not perform any part of their rendering loop if using the 2D Renderer.
## Rendering order optimizations

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.

When multiple Cameras in a Camera Stack render to the same render target, Unity draws each pixel in the render target for each Camera in the Camera Stack. Additionally, if more than one Base Camera or Camera Stack renders to the same area of the same render target, Unity draws any pixels in the overlapping area again, as many times as required by each Base Camera or Camera Stack.

You can use Unity's [Frame Debugger](https://docs.unity3d.com/Manual/FrameDebugger.html), or platform-specific frame capture and debugging tools, to understand where excessive overdraw occurs in your Scene. You can then optimize your Camera Stacks accordingly.
You can use Unity's [Frame Debugger](https://docs.unity3d.com/Manual/FrameDebugger.html), or platform-specific frame capture and debugging tools, to understand where excessive overdraw occurs in your scene. You can then optimize your Camera Stacks accordingly.
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Working with multiple cameras
# Use multiple cameras

In the Universal Render Pipeline (URP), you can work with multiple Cameras to:
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.

* [Stack Cameras](camera-stacking.md) 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.
* [Render multiple Base Cameras or Camera Stacks to the same render target](rendering-to-the-same-render-target.md). This allows you to create effects such as split screen rendering.
* [Render a Base Camera or Camera Stack to a Render Texture](rendering-to-a-render-texture.md). Rendering to a Render Texture allows you to create effects such as CCTV monitors.
> [!NOTE]
> If you use multiple cameras, it might make rendering slower. An active camera runs through the entire rendering loop even if it renders nothing.
![Camera Stacking in URP](Images/camera-stacking-example.png)
![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.*

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

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

| Page | Description |
|-|-|
| [Understand camera stacking](cameras/camera-stacking-concepts.md)| Learn the fundamental concepts of camera stacking. |
| [Set up a camera stack](camera-stacking.md)| Stack cameras to layer the outputs of multiple cameras into a single combined output. |
| [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. |
| [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. |
| [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. |
Loading

0 comments on commit 63d855b

Please sign in to comment.