Skip to content

Commit a36d8dd

Browse files
authored
Merge pull request #8130 from Unity-Technologies/internal/master
Internal/master
2 parents 638611e + 931fb72 commit a36d8dd

170 files changed

Lines changed: 4384 additions & 1478 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [Free Camera](Free-Camera.md)
1313
* [Camera Switcher](Camera-Switcher.md)
1414
* [Render Requests](User-Render-Requests.md)
15+
* [Render from another camera inside a camera's rendering loop](in-loop-render-requests.md)
1516
* [Render Graph](render-graph-system.md)
1617
* [Benefits of the render graph system](render-graph-benefits.md)
1718
* [Render graph fundamentals](render-graph-fundamentals.md)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Render from another camera inside a camera's rendering loop
2+
3+
Render from cameras nested inside the render loop of other cameras.
4+
5+
Attach the provided script to a GameObject with a Camera component to nest multiple cameras, that are rendering with [RenderPipeline.SubmitRenderRequest](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.RenderPipeline.SubmitRenderRequest.html), inside the render loop of other cameras.
6+
7+
**Note**: If your project uses the [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html) (URP), the recommended best practice is to use [UniversalRenderPipeline.SingleCameraRequest](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.0/api/UnityEngine.Rendering.Universal.UniversalRenderPipeline.SingleCameraRequest.html) instead of [StandardRequest](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.RenderPipeline.StandardRequest.html), to make sure you only render the camera provided to the `RenderRequest` API instead of the full stack of cameras.
8+
9+
## Attach the script to nest
10+
11+
Follow these steps:
12+
13+
1. Create a new C# script.
14+
2. Add the `using` statements shown below and the `RequireComponent` attribute with the `Camera` type.
15+
16+
```c#
17+
using System.Collections.Generic;
18+
using UnityEngine;
19+
using UnityEngine.Rendering;
20+
21+
[RequireComponent(typeof(Camera))]
22+
public class InLoopRenderRequest : MonoBehaviour
23+
{
24+
25+
}
26+
```
27+
28+
3. Add a property with the type `Camera` to the `InLoopRenderRequest` class.
29+
4. Add a property with the type `RenderTexture` for each callback the camera uses, as shown below:
30+
31+
```c#
32+
[RequireComponent(typeof(Camera))]
33+
public class InLoopRenderRequest : MonoBehaviour
34+
{
35+
public Camera renderRequestCamera;
36+
37+
public RenderTexture onBeginCameraRendering;
38+
public RenderTexture onBeginContextRendering;
39+
public RenderTexture onEndCameraRendering;
40+
public RenderTexture onEndContextRendering;
41+
}
42+
```
43+
44+
## Full code example
45+
46+
The following is an example of the finalized code which you attach to the secondary camera:
47+
48+
```c#
49+
using System.Collections.Generic;
50+
using UnityEngine;
51+
using UnityEngine.Rendering;
52+
53+
[RequireComponent(typeof(Camera))]
54+
public class InLoopRenderRequest : MonoBehaviour
55+
{
56+
// Add a reference to the secondary camera that will render the textures
57+
// It's recommended to disable the secondary camera.
58+
public Camera renderRequestCamera;
59+
60+
// Add references to the Render Textures that will contain the rendered image from the secondary camera.
61+
public RenderTexture onBeginCameraRendering;
62+
public RenderTexture onBeginContextRendering;
63+
public RenderTexture onEndCameraRendering;
64+
public RenderTexture onEndContextRendering;
65+
66+
void OnEnable()
67+
{
68+
// Subscribe to the RenderPipelineManager callbacks
69+
RenderPipelineManager.beginCameraRendering += OnBeginCameraRender;
70+
RenderPipelineManager.beginContextRendering += OnBeginContextRendering;
71+
RenderPipelineManager.endCameraRendering += OnEndCameraRender;
72+
RenderPipelineManager.endContextRendering += OnEndContextRendering;
73+
}
74+
75+
public void OnDisable()
76+
{
77+
// Unsubscribe to the callbacks from RenderPipelineManager when we disable the component
78+
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRender;
79+
RenderPipelineManager.beginContextRendering -= OnBeginContextRendering;
80+
RenderPipelineManager.endCameraRendering -= OnEndCameraRender;
81+
RenderPipelineManager.endContextRendering -= OnEndContextRendering;
82+
}
83+
84+
void SubmitStandardRenderRequest(RenderTexture rt, Camera cam)
85+
{
86+
RenderPipeline.StandardRequest request = new();
87+
88+
// Check that the Scriptable Render Pipeline (SRP) we're using supports the given render data.
89+
if (RenderPipeline.SupportsRenderRequest(cam, request))
90+
{
91+
// Set the request RenderTexture
92+
request.destination = rt;
93+
94+
// Render the camera output to the RenderTexture synchronously
95+
// When this is complete, the RenderTexture in renderTextures[i] contains the scene rendered from the point of view of the secondary cameras
96+
RenderPipeline.SubmitRenderRequest(cam, request);
97+
}
98+
}
99+
100+
// StandardRequest and UniversalRenderPipeline.SingleCameraRequest also trigger RenderPipelineManager callbacks.
101+
// Check that the callbacks are from the GameObject's Camera component to avoid a recursive rendering of the same camera.
102+
private void OnBeginContextRendering(ScriptableRenderContext ctx, List<Camera> cams)
103+
{
104+
if (cams.Contains(GetComponent<Camera>()))
105+
{
106+
SubmitStandardRenderRequest(onBeginContextRendering, renderRequestCamera);
107+
}
108+
}
109+
110+
private void OnEndContextRendering(ScriptableRenderContext ctx, List<Camera> cams)
111+
{
112+
if (cams.Contains(GetComponent<Camera>()))
113+
{
114+
SubmitStandardRenderRequest(onEndContextRendering, renderRequestCamera);
115+
}
116+
}
117+
118+
private void OnBeginCameraRender(ScriptableRenderContext ctx, Camera cam)
119+
{
120+
if (cam == GetComponent<Camera>())
121+
{
122+
SubmitStandardRenderRequest(onBeginCameraRendering, renderRequestCamera);
123+
}
124+
}
125+
126+
private void OnEndCameraRender(ScriptableRenderContext ctx, Camera cam)
127+
{
128+
if (cam == GetComponent<Camera>())
129+
{
130+
SubmitStandardRenderRequest(onEndCameraRendering, renderRequestCamera);
131+
}
132+
}
133+
}
134+
```
135+
136+
## Additional resources
137+
- [Render Requests](User-Render-Requests.md)
138+
- [Creating a custom render pipeline](srp-custom.md)
139+

Packages/com.unity.render-pipelines.high-definition/Documentation~/Default-Settings-Window.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The section contains the following settings that let you define project-wide set
66

77
You can also add your own settings. Refer to [Add custom settings](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@17.0/manual/add-custom-graphics-settings.html) in the Scriptable Render Pipeline (SRP) Core manual for more information.
88

9+
## Lightmap Sampling Settings
10+
11+
| **Property** | **Description** |
12+
| --------------------------| ------------------------------------------------------------ |
13+
| **Use Bicubic Lightmap Sampling** | Improves the visual fidelity of lightmaps by smoothening sharp or jagged edges, especially at the edges of shadows. Enabling this property might reduce performance on lower-end platforms. |
14+
915
## Additional Shader Stripping Settings
1016

1117
| **Property** | **Description** |

Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Use HDRP's water system to create and control realistic water surfaces. HDRP's w
432432
- Simulation-based caustics.
433433
- Underwater rendering.
434434
- Deformer.
435-
- Foam Generator.
435+
- Foam.
436436
- Water Excluder.
437437
- A mirrored simulation on the CPU for high-fidelity game interactions.
438438
- A shader graph interaction for advanced visual customization.

Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Sample-Content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ This sample includes examples on how to create a [Fullscreen Shader](create-a-fu
7979
The Water samples contain the following scenes you can use to learn about HDRP's [Water](water.md) features:
8080

8181
- Pool: Demonstrates ripples and buoyancy.
82-
- Glacier: Demonstrates current, water deformers, floating objects, and a water mask.
82+
- Glacier: Demonstrates current, water deformers, floating objects, and a simulation mask.
8383
- Island: Demonstrates waves, foam, and the water excluder.
8484
- Rain: Demonstrates how to add pertubations to the normals using shader graph.
8585
- Waterline: Demonstrates how to override rendering of the waterline using a [Custom Pass](Custom-Pass.md).
388 KB
Loading
1.11 MB
Loading
229 KB
Loading
576 KB
Loading
1.09 MB
Loading

0 commit comments

Comments
 (0)