Skip to content

Commit 67368e4

Browse files
authored
Merge pull request #8034 from Unity-Technologies/internal/2021.3/staging
Internal/2021.3/staging
2 parents d2bd3a5 + 364ad73 commit 67368e4

32 files changed

+1162
-72
lines changed

Packages/com.unity.render-pipelines.core/Runtime/Inputs/InputRegistering.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ static void CopyEntry(SerializedProperty spAxis, InputManagerEntry entry)
5959

6060
static void AddEntriesWithoutCheck(SerializedProperty spAxes, List<InputManagerEntry> newEntries)
6161
{
62+
if (newEntries.Count == 0)
63+
return;
64+
6265
int endOfCurrentInputList = spAxes.arraySize;
6366
spAxes.arraySize = endOfCurrentInputList + newEntries.Count;
64-
65-
SerializedProperty spAxis = spAxes.GetArrayElementAtIndex(endOfCurrentInputList - 1);
66-
spAxis.Next(false);
67+
// Assignment to spAxes.arraySize resizes the spAxes array to at least 1 larger than it used to be, and
68+
// therefore it is OK to use endOfCurrentInputList ("one-past-end of previous size") to get the array iterator.
69+
SerializedProperty spAxis = spAxes.GetArrayElementAtIndex(endOfCurrentInputList);
6770
for (int i = 0; i < newEntries.Count; ++i, spAxis.Next(false))
6871
CopyEntry(spAxis, newEntries[i]);
6972
}
@@ -74,6 +77,9 @@ static void AddEntriesWithoutCheck(SerializedProperty spAxes, List<InputManagerE
7477
int size = spAxes.arraySize;
7578
List<(string name, InputManagerEntry.Kind kind)> result = new List<(string name, InputManagerEntry.Kind kind)>(size);
7679

80+
if (size == 0)
81+
return result;
82+
7783
SerializedProperty spAxis = spAxes.GetArrayElementAtIndex(0);
7884
for (int i = 0; i < size; ++i, spAxis.Next(false))
7985
result.Add((spAxis.FindPropertyRelative("m_Name").stringValue, (InputManagerEntry.Kind)spAxis.FindPropertyRelative("type").intValue));

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010
* [Package samples](package-samples.md)
1111
* [URP Package Samples](package-sample-urp-package-samples.md)
1212
* [Scene Templates](scene-templates.md)
13+
* [Change Quality settings with code](quality/quality-settings-through-code.md)
1314
* [Understand performance](understand-performance.md)
1415
* [Configure for better performance](configure-for-better-performance.md)
1516
* [Render Pipeline Concepts](urp-concepts.md)
1617
* [The URP Asset](universalrp-asset.md)
1718
* [URP Global Settings](urp-global-settings.md)
1819
* [Universal Renderer](urp-universal-renderer.md)
1920
* [Deferred Rendering Path](rendering/deferred-rendering-path.md)
20-
* [Renderer Feature](urp-renderer-feature.md)
21+
* [Graphics settings window reference in URP](urp-global-settings.md)
22+
* [Pre-built effects (Renderer Features)](urp-renderer-feature.md)
2123
* [How to add a Renderer Feature](urp-renderer-feature-how-to-add.md)
22-
* [Render Objects Renderer Feature](renderer-features/how-to-custom-effect-render-objects.md)
23-
* [Ambient Occlusion](post-processing-ssao.md)
24-
* [Decal](renderer-feature-decal.md)
25-
* [Decal Shader Graph](decal-shader.md)
24+
* [Render Objects Renderer Feature](renderer-features/renderer-feature-render-objects-landing.md)
25+
* [Example: How to create a custom rendering effect using the Render Objects Renderer Feature](renderer-features/how-to-custom-effect-render-objects.md)
26+
* [Render Objects Renderer Feature reference](renderer-features/renderer-feature-render-objects.md)
27+
* [Decal Renderer Feature](renderer-feature-decal-landing.md)
28+
* [Decal Renderer Feature](renderer-feature-decal.md)
29+
* [Decal Shader Graph](decal-shader.md)
30+
* [Screen Space Ambient Occlusion (SSAO) Renderer Feature](post-processing-ssao.md)
2631
* [Upgrade guides](upgrade-guides.md)
2732
* [Render Pipeline Converter](features/rp-converter.md)
2833
* [Upgrading to URP 12.0.x](upgrade-guide-2021-2.md)
@@ -96,6 +101,7 @@
96101
* [Particles Unlit](particles-unlit-shader.md)
97102
* [Decal](decal-shader.md)
98103
* [Upgrading shaders from Built-in](upgrading-your-shaders.md)
104+
* [Upgrade custom shaders for URP compatibility](urp-shaders/birp-urp-custom-shader-upgrade-guide.md)
99105
* [Shader stripping](shader-stripping.md)
100106
* [Writing custom shaders](writing-custom-shaders-urp.md)
101107
* [Creating a sample scene](writing-shaders-urp-basic-prerequisites.md)
@@ -105,14 +111,19 @@
105111
* [Visualizing normal vectors](writing-shaders-urp-unlit-normals.md)
106112
* [Reconstruct the world space positions](writing-shaders-urp-reconstruct-world-position.md)
107113
* [URP ShaderLab Pass tags](urp-shaders/urp-shaderlab-pass-tags.md)
108-
* [How to](how-to.md)
109-
* [Blit in XR](renderer-features/how-to-fullscreen-blit-in-xr-spi.md)
110-
* [Use Render Objects Renderer Feature](renderer-features/how-to-custom-effect-render-objects.md)
111-
* [Create custom Renderer Feature](containers/create-custom-renderer-feature-1.md)
112-
* [Change Quality settings with code](quality/quality-settings-through-code.md)
113-
* [Customizing URP](customizing-urp.md)
114-
* [beginCameraRendering event](using-begincamerarendering.md)
115-
* [Create custom Renderer Feature](renderer-features/create-custom-renderer-feature.md)
114+
* [Custom rendering and post-processing](customizing-urp.md)
115+
* [Custom render passes](renderer-features/custom-rendering-passes.md)
116+
* [Custom render pass workflow in URP](renderer-features/custom-rendering-pass-workflow-in-urp.md)
117+
* [Scriptable Render Passes](renderer-features/scriptable-render-passes.md)
118+
* [Scriptable Render Passes](renderer-features/intro-to-scriptable-render-passes.md)
119+
* [Write a Scriptable Render Pass](renderer-features/write-a-scriptable-render-pass.md)
120+
* [Inject a pass via scripting](customize/inject-render-pass-via-script.md)
121+
* [Scriptable Renderer Features](renderer-features/scriptable-renderer-features/scriptable-renderer-features-landing.md)
122+
* [Introduction to Scriptable Renderer Features](renderer-features/scriptable-renderer-features/intro-to-scriptable-renderer-features.md)
123+
* [Inject a custom render pass using a Scriptable Renderer Feature](renderer-features/scriptable-renderer-features/inject-a-pass-using-a-scriptable-renderer-feature.md)
124+
* [Apply a Scriptable Renderer Feature to a specific camera type](renderer-features/scriptable-renderer-features/apply-scriptable-feature-to-specific-camera.md)
125+
* [Example of a complete Scriptable Renderer Feature](renderer-features/create-custom-renderer-feature.md)
126+
* [Scriptable Renderer Feature and Scriptable Render Pass API reference](renderer-features/scriptable-renderer-features/scriptable-renderer-feature-reference.md)
116127
* [Optimization](urp-optimization.md)
117128
* [Rendering Debugger](features/rendering-debugger.md)
118129
* [Optimize for better performance](optimize-for-better-performance.md)

Packages/com.unity.render-pipelines.universal/Documentation~/using-begincamerarendering.md renamed to Packages/com.unity.render-pipelines.universal/Documentation~/customize/inject-render-pass-via-script.md

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,57 @@
1-
# Using the beginCameraRendering event
1+
# Inject a render pass via scripting
22

3-
The example on this page shows how to use the [beginCameraRendering](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager-beginCameraRendering.html) event to run a custom method.
4-
5-
## beginCameraRendering event overview
6-
7-
Unity raises a `beginCameraRendering` event before it renders each active Camera in every frame. If a Camera is inactive (for example, if the __Camera__ component checkbox is cleared on a Camera GameObject), Unity does not raise a `beginCameraRendering` event for this Camera.
3+
Unity raises a [beginCameraRendering](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager-beginCameraRendering.html) event before it renders each active Camera in every frame. If a Camera is inactive (for example, if the **Camera** component checkbox is cleared on a Camera GameObject), Unity does not raise a `beginCameraRendering` event for this Camera.
84

95
When you subscribe a method to this event, you can execute custom logic before Unity renders the Camera. Examples of custom logic include rendering extra Cameras to Render Textures, and using those Textures for effects like planar reflections or surveillance camera views.
106

117
Other events in the [RenderPipelineManager](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager.html) class provide more ways to customize URP. You can also use the principles described in this article with those events.
128

13-
## beginCameraRendering event example
9+
## Use the RenderPipelineManager API
10+
11+
1. Subscribe a method to one of the events in the [RenderPipelineManager](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager.html) class.
12+
13+
2. In the subscribed method, use the `EnqueuePass` method of a `ScriptableRenderer` instance to inject a custom render pass into the URP frame rendering.
14+
15+
Example code:
16+
17+
```C#
18+
public class EnqueuePass : MonoBehaviour
19+
{
20+
[SerializeField] private BlurSettings settings;
21+
private BlurRenderPass blurRenderPass;
22+
23+
private void OnEnable()
24+
{
25+
...
26+
blurRenderPass = new BlurRenderPass(settings);
27+
// Subscribe the OnBeginCamera method to the beginCameraRendering event.
28+
RenderPipelineManager.beginCameraRendering += OnBeginCamera;
29+
}
30+
31+
private void OnDisable()
32+
{
33+
RenderPipelineManager.beginCameraRendering -= OnBeginCamera;
34+
blurRenderPass.Dispose();
35+
...
36+
}
37+
38+
private void OnBeginCamera(ScriptableRenderContext context, Camera cam)
39+
{
40+
...
41+
// Use the EnqueuePass method to inject a custom render pass
42+
cam.GetUniversalAdditionalCameraData()
43+
.scriptableRenderer.EnqueuePass(blurRenderPass);
44+
}
45+
}
46+
```
47+
48+
## Example
1449

1550
This example demonstrates how to subscribe a method to the `beginCameraRendering` event.
16-
To follow the steps in this example, create a [new Unity project using the __Universal Project Template__](https://docs.unity3d.com/Packages/[email protected]/manual/creating-a-new-project-with-urp.html).
1751

18-
1. In the Scene, create a Cube. Name it Example Cube.
52+
To follow the steps in this example, create a [new Unity project using the **Universal Project Template**](../creating-a-new-project-with-urp.md)
53+
54+
1. In the scene, create a Cube. Name it Example Cube.
1955
2. In your Project, create a C# script. Call it `URPCallbackExample`.
2056
3. Copy and paste the following code into the script.
2157
```C#
@@ -46,14 +82,14 @@ To follow the steps in this example, create a [new Unity project using the __Uni
4682
}
4783
}
4884
```
49-
> **NOTE**: When you subscribe to an event, your handler method (in this example, `WriteLogMessage`) must accept the parameters defined in the event delegate. In this example, the event delegate is `RenderPipeline.BeginCameraRendering`, which expects the following parameters: `<ScriptableRenderContext, Camera>`.
85+
> **Note**: When you subscribe to an event, your handler method (in this example, `WriteLogMessage`) must accept the parameters defined in the event delegate. In this example, the event delegate is `RenderPipeline.BeginCameraRendering`, which expects the following parameters: `<ScriptableRenderContext, Camera>`.
5086

5187
4. Attach the `URPCallbackExample` script to Example Cube.
5288

53-
5. Select __Play__. Unity prints the message from the script in the Console window each time Unity raises the `beginCameraRendering` event.
89+
5. Select **Play**. Unity prints the message from the script in the Console window each time Unity raises the `beginCameraRendering` event.
5490

55-
![Unity prints log message in console.](Images/customizing-urp/log-message-in-console.png)
91+
![Unity prints log message in console.](../Images/customizing-urp/log-message-in-console.png)
5692

5793
6. To raise a call to the `OnDisable()` method: In the Play mode, select Example Cube and clear the checkbox next to the script component title. Unity unsubscribes `WriteLogMessage` from the `RenderPipelineManager.beginCameraRendering` event and stops printing the message in the Console window.
5894

59-
![Deactivate the script component. Clear the checkbox next to the script component title.](Images/customizing-urp/deactivate-script-component.png)
95+
![Deactivate the script component. Clear the checkbox next to the script component title.](../Images/customizing-urp/deactivate-script-component.png)
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
# Customizing URP
1+
# Custom rendering and post-processing
22

3-
This section contains information on how to customize and extend the rendering process in URP.
3+
Customize and extend the rendering process in the Universal Render Pipeline (URP). URP uses Renderer Features to implement certain effects. URP includes a selection of pre-built Renderer Features and the ability to create customized Renderer Features known as Scriptable Renderer Features.
44

5-
This section contains the following articles:
5+
| Page | Description |
6+
|-|-|
7+
|[Custom render passes](renderer-features/custom-rendering-passes.md)|Create a custom render pass in a C# script and inject it into the URP frame rendering loop.|
8+
|[Scriptable Renderer Feature and Scriptable Render Pass API reference](renderer-features/scriptable-renderer-features/scriptable-renderer-feature-reference.md)|Common methods you can use to write Scriptable Renderer Passes and Scriptable Renderer Features.|
69

7-
* [Using the beginCameraRendering event](using-begincamerarendering.md)
10+
## Additional resources
11+
12+
- [Pre-built effects (Renderer Features)](urp-renderer-feature.md)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,3 @@ You can set the Background Type in the Camera Inspector to control how a Camera'
6868
## What rendering space does URP work in?
6969

7070
By default, URP uses a linear color space while rendering. You can also use a gamma color space, which is non-linear. To do so, toggle it in the Player Settings.
71-
72-
## How do I extend URP with scriptable render pass?
73-
74-
To create a scriptable render pass, you have to create a `ScriptableRendererFeature` script. This is because the scriptable render feature is a container that can have the pass in it. To create the scriptable render feature in the Editor, click on **Asset** > **Create** > **Rendering** > **Universal Render Pipeline** > **Renderer Feature**.

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

Lines changed: 0 additions & 9 deletions
This file was deleted.

Packages/com.unity.render-pipelines.universal/Documentation~/lighting/reflection-probes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ When a GameObject is within multiple reflection probe volumes, maximum two of th
4646

4747
* If the Importance values and the box volumes are the same, Unity determines which two reflection probe volumes contain larger surface areas of a GameObject, and picks the probes of those volumes.
4848

49-
When two reflection probes affect a GameObject, for each pixel, Unity calculates the weight of each probe depending on the distance of this pixel from the faces of the probe box volumes and the values of the **Blend Distance** properties. If the pixel is relatively close to faces of both box volumes and the sum of weights of both probes is less than 1, Unity assigns the remaining weight to the skybox reflection.
49+
When two reflection probes affect a GameObject, for each pixel, Unity calculates the weight of each probe depending on the distance of this pixel from the faces of the probe box volumes and the values of the **Blend Distance** properties.
50+
51+
If the pixel is relatively close to faces of both box volumes and the sum of weights of both probes is less than 1, Unity assigns the remaining weight to the `_GlossyEnvironmentCubeMap`. This cube map contains the reflection from the lighting source set in the Lighting window under **Environment Lighting** > **Source**. In most cases this source is the skybox.
5052

5153
If the pixel is within both box volumes and farther than the Blend Distance values from faces of both volumes:
5254

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Decal Renderer Feature
2+
3+
A Decal Renderer Features projects specific materials (decals) onto other objects in the scene. Decals interact with the scene's lighting and wrap around meshes.
4+
5+
|Page|Description|
6+
|-|-|
7+
|[Decal Renderer Feature](renderer-feature-decal.md)|Use a Decal Renderer Feature in your scene.|
8+
|[Decal Shader Graph](decal-shader.md)|Project a material as a decal if the material uses a Shader Graph with the Decal Material type.|

Packages/com.unity.render-pipelines.universal/Documentation~/renderer-features/create-custom-renderer-feature.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# How to create a custom Renderer Feature
1+
# Example of a complete Scriptable Renderer Feature
22

3-
This section describes how to create a custom Renderer Feature for a URP Renderer.
3+
The example workflow on this page implements a custom Renderer Feature that uses [custom Render Passes](./intro-to-scriptable-render-passes.md) to add a blur effect to the camera output.
44

55
This section assumes the following:
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Custom render pass workflow in URP
2+
3+
A custom render pass is a way to change how the Universal Render Pipeline (URP) renders a scene or the objects within a scene. A custom render pass contains your own rendering code, which you add to the rendering pipeline at an injection point.
4+
5+
To add a custom render pass, complete the following tasks:
6+
7+
- [Create the code](#create-code) for a custom render pass using the Scriptable Render Pass API.
8+
- [Inject the custom render pass](#inject-pass) using the `RenderPipelineManager` API, or by [creating a Scriptable Renderer Feature](#create-srf) that you add to the URP Renderer.
9+
10+
## <a name="create-code"></a>Create the code for a custom render pass
11+
12+
Use the `ScriptableRenderPass` to create the code for a custom render pass.
13+
14+
Refer to [Write a Scriptable Render Pass](write-a-scriptable-render-pass.md) for more information.
15+
16+
## <a name="inject-pass"></a>Inject the custom render pass using the RenderPipelineManager API
17+
18+
Unity raises a [beginCameraRendering](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager-beginCameraRendering.html) event before it renders each active Camera in every frame. You can subscribe a method to this event, to execute your custom render pass before Unity renders the Camera.
19+
20+
Refer to [Inject a render pass via scripting](../customize/inject-render-pass-via-script.md) for more information.
21+
22+
## <a name="create-srf"></a>Create a Scriptable Renderer Feature
23+
24+
Scriptable Renderer Features control when and how the Scriptable Render Passes apply to a particular renderer or camera, and can also manage multiple Scriptable Render Passes at once.
25+
26+
To create a Scriptable Renderer Feature, you do the following:
27+
28+
* Create a Scriptable Renderer Feature using the API.
29+
* Add the Scriptable Renderer Feature to the Universal Renderer asset, so it's included in the rendering pipeline.
30+
* Enqueue your custom render pass in the Scriptable Renderer Feature.
31+
32+
Refer to [Inject a pass using a Scriptable Renderer Feature](scriptable-renderer-features/inject-a-pass-using-a-scriptable-renderer-feature.md) for more information.

0 commit comments

Comments
 (0)