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

File tree

170 files changed

+4384
-1478
lines changed

Some content is hidden

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

170 files changed

+4384
-1478
lines changed

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/[email protected]/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/[email protected]/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).
Loading

Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Getting-Started.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ To make HDRP calculate ray tracing effects for [Cameras](hdrp-camera-component-r
123123

124124
To enable ray tracing by default:
125125

126-
1. Open the Project Settings window (menu: **Edit > Project Settings**), then select the HDRP Default Settings tab.
127-
2. Select Camera from the Default Frame Settings For drop-down.
128-
3. In the **Rendering** section, enable **Ray Tracing**.
126+
1. From the main menu, select **Edit** &gt; **Project Settings**.
127+
2. In the **Project Settings** window, go to the **Pipeline Specific Settings** section, then select the **HDRP** tab.
128+
3. Under **Frame Settings (Default Values)** &gt; **Camera** &gt; **Rendering**, enable **Ray Tracing**.
129129

130-
To enable ray tracing for a specific Camera:
130+
To enable ray tracing for a specific camera:
131131

132-
1. Click on the Camera in the Scene or Hierarchy to view it in the Inspector.
133-
2. In the **General** section, enable **Custom Frame Settings**. This exposes Frame Settings just for this Camera.
134-
3. in the **Rendering** section, enable **Ray Tracing**.
132+
1. Select the camera in the scene or **Hierarchy** window to view it in the **Inspector** window.
133+
2. In the **Rendering** section, enable **Custom Frame Settings**. This exposes frame settings for this camera only.
134+
3. Use the foldout (triangle) to expand **Rendering**, then enable **Ray Tracing**.
135135

136136
#### Build settings
137137

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,13 @@
210210
* [Enable mask and water decals](enable-mask-and-water-decals.md)
211211
* [Configure swell, agitation, or ripples](add-swell-agitation-or-ripples.md)
212212
* [Simulating currents with water decals](simulating-currents-with-water-decals.md)
213-
* [Simulating foam or ripples with masks](simulating-foam-or-ripples-with-masks.md)
213+
* [Simulating ripples with masks](simulating-foam-or-ripples-with-masks.md)
214214
* [Decals and masking in the water system](water-decals-and-masking-in-the-water-system.md)
215215
* [Foam in the Water System](water-foam-in-the-water-system.md)
216+
* [Introduction to foam](introduction-to-foam.md)
217+
* [Create wind-driven foam on the whole water surface](create-wind-driven-foam-on-the-whole-water-surface.md)
218+
* [Create local foam in the wake of a GameObject](create-local-foam-in-the-wake-of-a-gameobject.md)
219+
* [Add foam with a script](add-foam-with-script.md)
216220
* [Caustics in the Water System](water-caustics-in-the-water-system.md)
217221
* [Create a current in the Water System](water-create-a-current-in-the-water-system.md)
218222
* [Deform a water surface](water-deform-a-water-surface.md)

Packages/com.unity.render-pipelines.high-definition/Documentation~/add-caustics-and-foam-and-check-waves-and-ripples.md

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# Add caustics or foam and check waves and ripples
1+
# Add caustics and check waves and ripples
22

3-
To add caustics or foam, or get information about water surface displacement due to waves and ripples, get buffers from the [`WaterSurface`](xref:UnityEngine.Rendering.HighDefinition.WaterSurface) class:
3+
To add caustics or get information about water surface displacement due to waves and ripples, get buffers from the [`WaterSurface`](xref:UnityEngine.Rendering.HighDefinition.WaterSurface) class:
44

55
| Action | API |
66
|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
77
| Add caustics | [GetCausticsBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetCausticsBuffer_System_Single__) |
8-
| Add foam | [GetFoamBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetFoamBuffer_UnityEngine_Vector2__) |
98
| Check waves and ripples | [GetDeformationBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetDeformationBuffer) |
109

1110
## Example: Add caustics
@@ -44,45 +43,6 @@ public class WaterCausticsExample : MonoBehaviour
4443
}
4544
```
4645

47-
## Example: Add foam
48-
49-
```
50-
using UnityEngine;
51-
using UnityEngine.Rendering.HighDefinition;
52-
53-
public class WaterFoamExample : MonoBehaviour
54-
{
55-
// Reference to the water surface component
56-
public WaterSurface waterSurface;
57-
58-
// The area of the water surface where the foam buffer should be queried
59-
public Vector2 foamArea;
60-
61-
// Material to apply the foam effect
62-
public Material waterMaterial;
63-
64-
// Shader property name for foam texture in the water material
65-
private readonly string _foamTextureProperty = "_FoamTex";
66-
67-
void Start()
68-
{
69-
// Get the foam buffer for the specified 2D area on the water surface
70-
Texture foamBuffer = waterSurface.GetFoamBuffer(out foamArea);
71-
72-
if (foamBuffer != null)
73-
{
74-
// Apply the foam buffer as a texture to the water material
75-
waterMaterial.SetTexture(_foamTextureProperty, foamBuffer);
76-
Debug.Log("Foam buffer applied successfully.");
77-
}
78-
else
79-
{
80-
Debug.LogWarning("Foam buffer could not be retrieved.");
81-
}
82-
}
83-
}
84-
```
85-
8646
## Example: Check waves and ripples
8747

8848
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Add foam with a script
2+
3+
To add caustics or foam, or get information about water surface displacement due to waves and ripples, get buffers from the [GetFoamBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetFoamBuffer_UnityEngine_Vector2__) API.
4+
5+
## Example: Add foam
6+
7+
```
8+
using UnityEngine;
9+
using UnityEngine.Rendering.HighDefinition;
10+
11+
public class WaterFoamExample : MonoBehaviour
12+
{
13+
// Reference to the water surface component
14+
public WaterSurface waterSurface;
15+
16+
// The area of the water surface where the foam buffer should be queried
17+
public Vector2 foamArea;
18+
19+
// Material to apply the foam effect
20+
public Material waterMaterial;
21+
22+
// Shader property name for foam texture in the water material
23+
private readonly string _foamTextureProperty = "_FoamTex";
24+
25+
void Start()
26+
{
27+
// Get the foam buffer for the specified 2D area on the water surface
28+
Texture foamBuffer = waterSurface.GetFoamBuffer(out foamArea);
29+
30+
if (foamBuffer != null)
31+
{
32+
// Apply the foam buffer as a texture to the water material
33+
waterMaterial.SetTexture(_foamTextureProperty, foamBuffer);
34+
Debug.Log("Foam buffer applied successfully.");
35+
}
36+
else
37+
{
38+
Debug.LogWarning("Foam buffer could not be retrieved.");
39+
}
40+
}
41+
}
42+
```

Packages/com.unity.render-pipelines.high-definition/Documentation~/add-swell-agitation-or-ripples.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Configure swell, agitation, or ripples with a water mask
1+
# Configure swell, agitation, or ripples with a simulation mask
22

3-
To configure swell, agitation or ripples, use a Water Mask to affect the influence the simulation has on specific areas of the water surface.
3+
To configure swell, agitation, or ripples, use a simulation mask to affect the influence the simulation has on specific areas of the water surface.
44

55
Masks take into account the Wrap Mode of the texture. For Ocean, Sea, or Lake water surface types, select **Clamp** rather than the default **Repeat** value.
66

7-
To add a Water Mask:
7+
To add a simulation mask:
88

99
1. Create and import a texture where the color channels represent the fluctuations.
1010

@@ -21,7 +21,7 @@ To add a Water Mask:
2121

2222
The darker the color of a channel, the lesser the effect. For example, use white for 100% intensity and black for 0% intensity.
2323

24-
1. In the Water Volume Inspector window, drag the texture to the **Water Mask** property.
24+
1. In the Water Volume Inspector window, drag the texture to the **Simulation Mask** property.
2525

2626
<table>
2727
<tr>
@@ -34,7 +34,7 @@ To add a Water Mask:
3434
</tr>
3535
<tr>
3636
<td colspan="2">
37-
In this example, the red channel has a gradient that reduces the first and second simulation bands. The noise on the green channel reduces ripples. For more information, refer to the <a href="settings-and-properties-related-to-the-water-system.md#watermask">Water Mask property description</a>.
37+
In this example, the red channel has a gradient that reduces the first and second simulation bands. The noise on the green channel reduces ripples. For more information, refer to the <a href="settings-and-properties-related-to-the-water-system.md#simulationmask">Simulation Mask property description</a>.
3838
</td>
3939
</tr>
4040
</table>

0 commit comments

Comments
 (0)