Skip to content

Commit 1ca3091

Browse files
Richard-HortonEvergreen
authored andcommitted
URP Docs: DOCG-5649 Render Request Doc Review
Render Request doc update for URP Updates links between URP Docs and SRP Core Docs
1 parent 0e9cff0 commit 1ca3091

File tree

4 files changed

+208
-36
lines changed

4 files changed

+208
-36
lines changed

Packages/com.unity.render-pipelines.core/Documentation~/User-Render-Requests.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ The request is processed sequentially in your script, so there's no callback inv
88

99
`RenderPipeline.StandardRequest` renders the following:
1010

11-
- A full stack of cameras in the [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html) (URP).
12-
- A single camera in the [High Definition Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html) (HDRP).
11+
* A full stack of cameras in the [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html) (URP).
12+
* A single camera in the [High Definition Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html) (HDRP).
1313

1414
The following code sample gets the output of the scriptable render pipeline when you select a GUI button. Attach the script to a camera and select **Enter Play Mode**.
1515

16-
```
16+
```c#
1717
using System.Collections;
1818
using System.Collections.Generic;
1919
using UnityEngine;
@@ -91,5 +91,4 @@ public class StandardRenderRequest : MonoBehaviour
9191

9292
## Other useful information
9393

94-
- On [Universal Render Pipeline (URP)](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/User-Render-Requests.html).
95-
94+
* On [Universal Render Pipeline (URP)](https://docs.unity3d.com/Packages/[email protected]/manual/User-Render-Requests.html).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@
100100
* [Set up split-screen rendering](rendering-to-the-same-render-target.md)
101101
* [Apply different post processing effects to separate cameras](cameras/apply-different-post-proc-to-cameras.md)
102102
* [Render a camera's output to a Render Texture](rendering-to-a-render-texture.md)
103+
* [Render a camera outside the rendering loop](render-requests.md)
103104
* [Customize a camera](universal-additional-camera-data.md)
104105
* [Camera component properties](camera-component-reference.md)
105106
* [Physical Camera properties](cameras/physical-camera-reference.md)
106-
* [Render Requests](User-Render-Requests.md)
107107
* [Post-processing](integration-with-post-processing.md)
108108
* [How to configure](integration-with-post-processing.md#post-proc-how-to)
109109
* [HDR Output](post-processing/hdr-output.md)

Packages/com.unity.render-pipelines.universal/Documentation~/User-Render-Requests.md

Lines changed: 201 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,260 @@ uid: urp-docfx-user-render-requests
33
---
44
# Render Requests
55

6-
For a general documentation see the [Core Package](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@latest/User-Render-Requests.html) about Render Requests.
6+
To trigger a camera to render to a render texture outside of the Universal Render Pipeline (URP) rendering loop, use the `SubmitRenderRequest` API in a C# script.
77

8-
## Use UniversalRenderPipeline.SingleCameraRequest
8+
This example shows how to use render requests and callbacks to monitor the progress of these requests. You can see the full code sample in the [Example code](#example-code) section.
99

10-
`UniversalRenderPipeline.SingleCameraRequest` renders a single camera, without taking into account the full stack of cameras.
10+
## Render a single camera from a camera stack
1111

12-
You can still hook into callbacks from [RenderPipelineManager](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager.html).
12+
To render a single camera without taking into account the full stack of cameras, use the `UniversalRenderPipeline.SingleCameraRequest` API. Follow these steps:
1313

14-
The following code sample shows that you can hook into [RenderPipelineManager.endContextRendering](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager-endContextRendering.html) `UniversalRenderPipeline.SingleCameraRequest`
14+
1. Create a C# script with the name `SingleCameraRenderRequestExample` and add the `using` statements shown below.
1515

16-
To try out this example:
16+
```c#
17+
using System.Collections;
18+
using UnityEngine;
19+
using UnityEngine.Rendering;
20+
using UnityEngine.Rendering.Universal;
1721

18-
- Attach the script to a **GameObject** in the **Scene**.
19-
- Configure the **cams** and **rts**.
20-
- Set **useSingleCameraRequestValues** to true or false depending on which type of render request you want to use.
21-
- Select **Enter Play Mode**.
22-
- See the **Console** Log.
22+
public class SingleCameraRenderRequestExample : MonoBehaviour
23+
{
2324

24-
```
25+
}
26+
```
27+
28+
2. Create arrays to store the cameras and Render Textures that you want to render from and to.
29+
30+
```c#
31+
public class SingleCameraRenderRequestExample : MonoBehaviour
32+
{
33+
public Camera[] cameras;
34+
public RenderTexture[] renderTextures;
35+
}
36+
```
37+
38+
3. In the `Start` method, add a check to ensure the `cameras` and `renderTextures` arrays are valid and contain the correct data before continuing with running the script.
39+
40+
```c#
41+
void Start()
42+
{
43+
// Make sure all data is valid before you start the component
44+
if (cameras == null || cameras.Length == 0 || renderTextures == null || cameras.Length != renderTextures.Length)
45+
{
46+
Debug.LogError("Invalid setup");
47+
return;
48+
}
49+
}
50+
```
51+
52+
4. Make a method with the name `SendSingleRenderRequests` and the return type `void` within the `SingleCameraRenderRequest` class.
53+
5. In the `SendSingleRenderRequests` method, add a `for` loop that iterates over the `cameras` array as shown below.
54+
55+
```c#
56+
void SendSingleRenderRequests()
57+
{
58+
for (int i = 0; i < cameras.Length; i++)
59+
{
60+
61+
}
62+
}
63+
```
64+
65+
6. Inside the `for` loop, create a render request of the `UniversalRenderPipeline.SingleCameraRequest` type in a variable with the name `request`. Then check if the active render pipeline supports this render request type with `RenderPipeline.SupportsRenderRequest`.
66+
7. If the active render pipeline supports the render request, set the destination of the camera output to the matching Render Texture from the `renderTextures` array. Then submit the render request with `RenderPipeline.SubmitRenderRequest`.
67+
68+
```c#
69+
void SendSingleRenderRequests()
70+
{
71+
for (int i = 0; i < cameras.Length; i++)
72+
{
73+
UniversalRenderPipeline.SingleCameraRequest request =
74+
new UniversalRenderPipeline.SingleCameraRequest();
75+
76+
// Check if the active render pipeline supports the render request
77+
if (RenderPipeline.SupportsRenderRequest(cameras[i], request))
78+
{
79+
// Set the destination of the camera output to the matching RenderTexture
80+
request.destination = renderTextures[i];
81+
82+
// Render the camera output to the RenderTexture synchronously
83+
// When this is complete, the RenderTexture in renderTextures[i] contains the scene rendered from the point
84+
// of view of the Camera in cameras[i]
85+
RenderPipeline.SubmitRenderRequest(cameras[i], request);
86+
}
87+
}
88+
}
89+
```
90+
91+
8. Above the `SendSingleRenderRequest` method, create an `IEnumerator` interface with the name `RenderSingleRequestNextFrame`.
92+
9. Inside `RenderSingleRequestNextFrame`, wait for the main camera to finish rendering, then call `SendSingleRenderRequest`. Wait for the end of the frame before restarting `RenderSingleRequestNextFrame` in a coroutine with `StartCoroutine`.
93+
94+
```c#
95+
IEnumerator RenderSingleRequestNextFrame()
96+
{
97+
// Wait for the main camera to finish rendering
98+
yield return new WaitForEndOfFrame();
99+
100+
// Enqueue one render request for each camera
101+
SendSingleRenderRequests();
102+
103+
// Wait for the end of the frame
104+
yield return new WaitForEndOfFrame();
105+
106+
// Restart the coroutine
107+
StartCoroutine(RenderSingleRequestNextFrame());
108+
}
109+
```
110+
111+
10. In the `Start` method, call `RenderSingleRequestNextFrame` in a coroutine with `StartCoroutine`.
112+
113+
```c#
114+
void Start()
115+
{
116+
// Make sure all data is valid before you start the component
117+
if (cameras == null || cameras.Length == 0 || renderTextures == null || cameras.Length != renderTextures.Length)
118+
{
119+
Debug.LogError("Invalid setup");
120+
return;
121+
}
122+
123+
// Start the asynchronous coroutine
124+
StartCoroutine(RenderSingleRequestNextFrame());
125+
}
126+
```
127+
128+
11. In the Editor, create an empty GameObject in your scene and add `SingleCameraRenderRequestExample.cs` as a [component](xref:UsingComponents).
129+
12. In the Inspector window, add the camera you want to render from to the **cameras** list, and the Render Texture you want to render into to the **renderTextures** list.
130+
131+
> ![NOTE]
132+
> The number of cameras in the **cameras** list and the number of Render Textures in the **renderTextures** list must be the same.
133+
134+
Now when you enter Play mode, the cameras you added render to the Render Textures you added.
135+
136+
### Check when a camera finishes rendering
137+
138+
To check when a camera finishes rendering, use any callback from the [RenderPipelineManager](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager.html) API.
139+
140+
The following example uses the [RenderPipelineManager.endContextRendering](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager-endContextRendering.html) callback.
141+
142+
1. Add `using System.Collections.Generic` to the top of the `SingleCameraRenderRequestExample.cs` file.
143+
2. At the end of the `Start` method, subscribe to the [`endContextRendering`](https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager-endContextRendering.html) callback.
144+
145+
```c#
146+
void Start()
147+
{
148+
// Make sure all data is valid before you start the component
149+
if (cameras == null || cameras.Length == 0 || renderTextures == null || cameras.Length != renderTextures.Length)
150+
{
151+
Debug.LogError("Invalid setup");
152+
return;
153+
}
154+
155+
// Start the asynchronous coroutine
156+
StartCoroutine(RenderSingleRequestNextFrame());
157+
158+
// Call a method called OnEndContextRendering when a camera finishes rendering
159+
RenderPipelineManager.endContextRendering += OnEndContextRendering;
160+
}
161+
```
162+
163+
3. Create a method with the name `OnEndContextRendering`. Unity runs this method when the `endContextRendering` callback triggers.
164+
165+
```c#
166+
void OnEndContextRendering(ScriptableRenderContext context, List<Camera> cameras)
167+
{
168+
// Create a log to show cameras have finished rendering
169+
Debug.Log("All cameras have finished rendering.");
170+
}
171+
```
172+
173+
4. To unsubscribe the `OnEndContextRendering` method from the `endContextRendering` callback, add an `OnDestroy` method to the `SingleCameraRenderRequestExample` class.
174+
175+
```c#
176+
void OnDestroy()
177+
{
178+
// End the subscription to the callback
179+
RenderPipelineManager.endContextRendering -= OnEndContextRendering;
180+
}
181+
```
182+
183+
This script now works as before, but logs a message to the Console Window about which cameras have finished rendering.
184+
185+
## Example code
186+
187+
```c#
25188
using System.Collections;
26189
using System.Collections.Generic;
27-
using System.Text;
28190
using UnityEngine;
29191
using UnityEngine.Rendering;
30192
using UnityEngine.Rendering.Universal;
31193

32-
public class SingleCameraRenderRequestExample : MonoBehaviour
194+
public class SingleCameraRenderRequest : MonoBehaviour
33195
{
34-
public Camera[] cams;
35-
public RenderTexture[] rts;
196+
public Camera[] cameras;
197+
public RenderTexture[] renderTextures;
36198

37199
void Start()
38200
{
39-
if (cams == null || cams.Length == 0 || rts == null || cams.Length != rts.Length)
201+
// Make sure all data is valid before you start the component
202+
if (cameras == null || cameras.Length == 0 || renderTextures == null || cameras.Length != renderTextures.Length)
40203
{
41204
Debug.LogError("Invalid setup");
42205
return;
43206
}
44207

208+
// Start the asynchronous coroutine
45209
StartCoroutine(RenderSingleRequestNextFrame());
210+
211+
// Call a method called OnEndContextRendering when a camera finishes rendering
46212
RenderPipelineManager.endContextRendering += OnEndContextRendering;
47213
}
48214

49215
void OnEndContextRendering(ScriptableRenderContext context, List<Camera> cameras)
50216
{
51-
var stb = new StringBuilder($"Cameras Count from EndContextRendering: <b> {cameras.Count}</b>.");
52-
foreach (var cam in cameras)
53-
{
54-
stb.AppendLine($"- {cam.name}");
55-
}
56-
Debug.Log(stb.ToString());
217+
// Create a log to show cameras have finished rendering
218+
Debug.Log("All cameras have finished rendering.");
57219
}
58220

59221
void OnDestroy()
60222
{
223+
// End the subscription to the callback
61224
RenderPipelineManager.endContextRendering -= OnEndContextRendering;
62225
}
63226

64227
IEnumerator RenderSingleRequestNextFrame()
65228
{
229+
// Wait for the main camera to finish rendering
66230
yield return new WaitForEndOfFrame();
67231

232+
// Enqueue one render request for each camera
68233
SendSingleRenderRequests();
69234

235+
// Wait for the end of the frame
70236
yield return new WaitForEndOfFrame();
71237

238+
// Restart the coroutine
72239
StartCoroutine(RenderSingleRequestNextFrame());
73240
}
74241

75242
void SendSingleRenderRequests()
76243
{
77-
for (int i = 0; i < cams.Length; i++)
244+
for (int i = 0; i < cameras.Length; i++)
78245
{
79246
UniversalRenderPipeline.SingleCameraRequest request =
80247
new UniversalRenderPipeline.SingleCameraRequest();
81248

82-
// Check if the request is supported by the active render pipeline
83-
if (RenderPipeline.SupportsRenderRequest(cams[i], request))
249+
// Check if the active render pipeline supports the render request
250+
if (RenderPipeline.SupportsRenderRequest(cameras[i], request))
84251
{
85-
request.destination = rts[i];
86-
RenderPipeline.SubmitRenderRequest(cams[i], request);
252+
// Set the destination of the camera output to the matching RenderTexture
253+
request.destination = renderTextures[i];
254+
255+
// Render the camera output to the RenderTexture synchronously
256+
RenderPipeline.SubmitRenderRequest(cameras[i], request);
257+
258+
// At this point, the RenderTexture in renderTextures[i] contains the scene rendered from the point
259+
// of view of the Camera in cameras[i]
87260
}
88261
}
89262
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ You can use Unity's [Frame Debugger](https://docs.unity3d.com/Manual/FrameDebugg
8080

8181
You can use a render request in a C# script to trigger a camera to render to a render texture, outside the URP rendering loop. You can use two types of render request in URP, which do the following:
8282

83-
* [RenderPipeline.StandardRequest](xref:Rendering.RenderPipeline.StandardRequest) renders the output of a full stack of cameras.
83+
* [RenderPipeline.StandardRequest](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.RenderPipeline.StandardRequest.html) renders the output of a full stack of cameras.
8484
* [UniversalRenderPipeline.SingleCameraRequest](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.Universal.UniversalRenderPipeline.SingleCameraRequest.html) renders the output of a single camera.
8585

86-
For more information on how to use render requests, refer to [Render Requests](https://docs.unity3d.com/Packages/[email protected]/manual/User-Render-Requests.html).
86+
For more information on how to use render requests, refer to [Render a camera outside the rendering loop](User-Render-Requests.md).

0 commit comments

Comments
 (0)