-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8034 from Unity-Technologies/internal/2021.3/staging
Internal/2021.3/staging
- Loading branch information
Showing
32 changed files
with
1,162 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,57 @@ | ||
# Using the beginCameraRendering event | ||
# Inject a render pass via scripting | ||
|
||
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. | ||
|
||
## beginCameraRendering event overview | ||
|
||
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. | ||
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. | ||
|
||
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. | ||
|
||
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. | ||
|
||
## beginCameraRendering event example | ||
## Use the RenderPipelineManager API | ||
|
||
1. Subscribe a method to one of the events in the [RenderPipelineManager](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager.html) class. | ||
|
||
2. In the subscribed method, use the `EnqueuePass` method of a `ScriptableRenderer` instance to inject a custom render pass into the URP frame rendering. | ||
|
||
Example code: | ||
|
||
```C# | ||
public class EnqueuePass : MonoBehaviour | ||
{ | ||
[SerializeField] private BlurSettings settings; | ||
private BlurRenderPass blurRenderPass; | ||
|
||
private void OnEnable() | ||
{ | ||
... | ||
blurRenderPass = new BlurRenderPass(settings); | ||
// Subscribe the OnBeginCamera method to the beginCameraRendering event. | ||
RenderPipelineManager.beginCameraRendering += OnBeginCamera; | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
RenderPipelineManager.beginCameraRendering -= OnBeginCamera; | ||
blurRenderPass.Dispose(); | ||
... | ||
} | ||
|
||
private void OnBeginCamera(ScriptableRenderContext context, Camera cam) | ||
{ | ||
... | ||
// Use the EnqueuePass method to inject a custom render pass | ||
cam.GetUniversalAdditionalCameraData() | ||
.scriptableRenderer.EnqueuePass(blurRenderPass); | ||
} | ||
} | ||
``` | ||
|
||
## Example | ||
|
||
This example demonstrates how to subscribe a method to the `beginCameraRendering` event. | ||
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). | ||
|
||
1. In the Scene, create a Cube. Name it Example Cube. | ||
To follow the steps in this example, create a [new Unity project using the **Universal Project Template**](../creating-a-new-project-with-urp.md) | ||
|
||
1. In the scene, create a Cube. Name it Example Cube. | ||
2. In your Project, create a C# script. Call it `URPCallbackExample`. | ||
3. Copy and paste the following code into the script. | ||
```C# | ||
|
@@ -46,14 +82,14 @@ To follow the steps in this example, create a [new Unity project using the __Uni | |
} | ||
} | ||
``` | ||
> **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>`. | ||
> **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>`. | ||
|
||
4. Attach the `URPCallbackExample` script to Example Cube. | ||
|
||
5. Select __Play__. Unity prints the message from the script in the Console window each time Unity raises the `beginCameraRendering` event. | ||
5. Select **Play**. Unity prints the message from the script in the Console window each time Unity raises the `beginCameraRendering` event. | ||
|
||
![Unity prints log message in console.](Images/customizing-urp/log-message-in-console.png) | ||
![Unity prints log message in console.](../Images/customizing-urp/log-message-in-console.png) | ||
|
||
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. | ||
|
||
![Deactivate the script component. Clear the checkbox next to the script component title.](Images/customizing-urp/deactivate-script-component.png) | ||
![Deactivate the script component. Clear the checkbox next to the script component title.](../Images/customizing-urp/deactivate-script-component.png) |
13 changes: 9 additions & 4 deletions
13
Packages/com.unity.render-pipelines.universal/Documentation~/customizing-urp.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
# Customizing URP | ||
# Custom rendering and post-processing | ||
|
||
This section contains information on how to customize and extend the rendering process in URP. | ||
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. | ||
|
||
This section contains the following articles: | ||
| Page | Description | | ||
|-|-| | ||
|[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.| | ||
|[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.| | ||
|
||
* [Using the beginCameraRendering event](using-begincamerarendering.md) | ||
## Additional resources | ||
|
||
- [Pre-built effects (Renderer Features)](urp-renderer-feature.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
Packages/com.unity.render-pipelines.universal/Documentation~/how-to.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ity.render-pipelines.universal/Documentation~/renderer-feature-decal-landing.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Decal Renderer Feature | ||
|
||
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. | ||
|
||
|Page|Description| | ||
|-|-| | ||
|[Decal Renderer Feature](renderer-feature-decal.md)|Use a Decal Renderer Feature in your scene.| | ||
|[Decal Shader Graph](decal-shader.md)|Project a material as a decal if the material uses a Shader Graph with the Decal Material type.| |
4 changes: 2 additions & 2 deletions
4
...es.universal/Documentation~/renderer-features/create-custom-renderer-feature.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ersal/Documentation~/renderer-features/custom-rendering-pass-workflow-in-urp.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Custom render pass workflow in URP | ||
|
||
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. | ||
|
||
To add a custom render pass, complete the following tasks: | ||
|
||
- [Create the code](#create-code) for a custom render pass using the Scriptable Render Pass API. | ||
- [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. | ||
|
||
## <a name="create-code"></a>Create the code for a custom render pass | ||
|
||
Use the `ScriptableRenderPass` to create the code for a custom render pass. | ||
|
||
Refer to [Write a Scriptable Render Pass](write-a-scriptable-render-pass.md) for more information. | ||
|
||
## <a name="inject-pass"></a>Inject the custom render pass using the RenderPipelineManager API | ||
|
||
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. | ||
|
||
Refer to [Inject a render pass via scripting](../customize/inject-render-pass-via-script.md) for more information. | ||
|
||
## <a name="create-srf"></a>Create a Scriptable Renderer Feature | ||
|
||
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. | ||
|
||
To create a Scriptable Renderer Feature, you do the following: | ||
|
||
* Create a Scriptable Renderer Feature using the API. | ||
* Add the Scriptable Renderer Feature to the Universal Renderer asset, so it's included in the rendering pipeline. | ||
* Enqueue your custom render pass in the Scriptable Renderer Feature. | ||
|
||
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. |
10 changes: 10 additions & 0 deletions
10
...pipelines.universal/Documentation~/renderer-features/custom-rendering-passes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Custom render passes | ||
|
||
Create a custom render pass in a C# script and inject it into the Universal Render Pipeline (URP) frame rendering loop. | ||
|
||
|Page|Description| | ||
|-|-| | ||
|[Custom render pass workflow in URP](custom-rendering-pass-workflow-in-urp.md)|Add and inject a custom render pass to change how URP renders a scene or the objects within a scene.| | ||
|[Scriptable Render Passes](scriptable-render-passes.md)|Use the Scriptable Render Pass API to create a custom render pass.| | ||
|[Scriptable Renderer Features](scriptable-renderer-features/scriptable-renderer-features-landing.md)|Use the Scriptable Renderer Feature API to inject a custom render pass into a URP renderer.| | ||
|
Oops, something went wrong.