Skip to content

Commit 13e28e0

Browse files
Merge pull request #8209 from Unity-Technologies/internal/master
Internal/master
2 parents 6eca600 + 6ec487b commit 13e28e0

File tree

1,018 files changed

+462857
-11238
lines changed

Some content is hidden

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

1,018 files changed

+462857
-11238
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
* [Create a simple render loop in a custom render pipeline](srp-creating-simple-render-loop.md)
1010
* [Execute rendering commands in a custom render pipeline](srp-using-scriptable-render-context.md)
1111
* [Scriptable Render Pipeline callbacks reference](srp-callbacks-reference.md)
12+
* [Creating a custom render pipeline using the render graph system](render-graph-system-landing.md)
13+
* [Render graph system](render-graph-system.md)
14+
* [Write a render pipeline with render graph](render-graph-writing-a-render-pipeline.md)
15+
* [Write a render pass using the render graph system](render-graph-write-render-pass.md)
16+
* [Resources in the render graph system](render-graph-resources-landing.md)
17+
* [Introduction to resources in the render graph system](render-graph-resources.md)
18+
* [Blit using the render graph system](render-graph-blit.md)
19+
* [Create a texture in the render graph system](render-graph-create-a-texture.md)
20+
* [Import a texture into the render graph system](render-graph-import-a-texture.md)
21+
* [Access a texture in a render pass](render-graph-read-write-texture.md)
22+
* [Use the CommandBuffer interface in a render graph](render-graph-unsafe-pass.md)
1223
* Camera components
1324
* [Free Camera](Free-Camera.md)
1425
* [Camera Switcher](Camera-Switcher.md)
1526
* [Render Requests](User-Render-Requests.md)
1627
* [Render from another camera inside a camera's rendering loop](in-loop-render-requests.md)
17-
* [Render Graph](render-graph-system.md)
18-
* [Benefits of the render graph system](render-graph-benefits.md)
19-
* [Render graph fundamentals](render-graph-fundamentals.md)
20-
* [Writing a Render Pipeline](render-graph-writing-a-render-pipeline.md)
2128
* [RTHandle system](rthandle-system.md)
2229
* [RTHandle fundamentals](rthandle-system-fundamentals.md)
2330
* [Using the RTHandle system](rthandle-system-using.md)

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

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Blit using the render graph system in SRP Core
2+
3+
To blit from one texture to another in the render graph system, use the [`AddBlitPass`](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.RenderGraphModule.Util.RenderGraphUtils.html#UnityEngine_Rendering_RenderGraphModule_Util_RenderGraphUtils_AddBlitPass_UnityEngine_Rendering_RenderGraphModule_RenderGraph_UnityEngine_Rendering_RenderGraphModule_Util_RenderGraphUtils_BlitMaterialParameters_System_String_System_Boolean_) API. The API generates a render pass automatically, so you don't need to use a method like `AddRasterRenderPass`.
4+
5+
Follow these steps:
6+
7+
1. To create a shader and material that works with a blit render pass, from the main menu select **Assets** > **Create** > **Shader** > **SRP Blit Shader**, then create a material from it.
8+
9+
1. Add `using UnityEngine.Rendering.RenderGraphModule.Util` to your render pass script.
10+
11+
1. In your render pass, create a field for the blit material. For example:
12+
13+
```lang-cs
14+
public class MyBlitPass : ScriptableRenderPass
15+
{
16+
Material blitMaterial;
17+
}
18+
```
19+
20+
1. Set up the texture to blit from and blit to. For example:
21+
22+
```lang-cs
23+
TextureHandle sourceTexture = renderGraph.CreateTexture(sourceTextureProperties);
24+
TextureHandle destinationTexture = renderGraph.CreateTexture(destinationTextureProperties);
25+
```
26+
27+
1. To set up the material, textures, and shader pass for the blit operation, create a [`RenderGraphUtils.BlitMaterialParameters`](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.RenderGraphModule.Util.RenderGraphUtils.BlitMaterialParameters.html) object. For example:
28+
29+
```lang-cs
30+
// Create a BlitMaterialParameters object with the blit material, source texture, destination texture, and shader pass to use.
31+
var blitParams = new RenderGraphUtils.BlitMaterialParameters(sourceTexture, destinationTexture, blitMaterial, 0);
32+
```
33+
34+
1. To add a blit pass, call the [`AddBlitPass`](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.RenderGraphModule.Util.RenderGraphUtils.html#UnityEngine_Rendering_RenderGraphModule_Util_RenderGraphUtils_AddBlitPass_UnityEngine_Rendering_RenderGraphModule_RenderGraph_UnityEngine_Rendering_RenderGraphModule_Util_RenderGraphUtils_BlitMaterialParameters_System_String_System_Boolean_) method with the blit parameters. For example:
35+
36+
```lang-cs
37+
renderGraph.AddBlitPass(blitParams, "Pass created with AddBlitPass");
38+
```
39+
40+
If you use `AddBlitPass` with a default material, Unity might use the `AddCopyPass` API instead, to optimize the render pass so it accesses the framebuffer from the on-chip memory of the GPU instead of video memory. This process is sometimes called framebuffer fetch. For more information, refer to [`AddCopyPass`](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.RenderGraphModule.Util.RenderGraphUtils.html#UnityEngine_Rendering_RenderGraphModule_Util_RenderGraphUtils_AddCopyPass_UnityEngine_Rendering_RenderGraphModule_RenderGraph_UnityEngine_Rendering_RenderGraphModule_TextureHandle_UnityEngine_Rendering_RenderGraphModule_TextureHandle_System_String_System_Boolean_) API.
41+
42+
## Customize the render pass
43+
44+
To customize the render pass that the methods generate, for example to change settings or add more resources, call the APIs with the `returnBuilder` parameter set to `true`. The APIs then return the `IBaseRenderGraphBuilder` object that you usually receive as `var builder` from a method like `AddRasterRenderPass`.
45+
46+
For example:
47+
48+
```lang-cs
49+
using (var builder = renderGraph.AddBlitPass(blitParams, "Pass created with AddBlitPass", returnBuilder: true))
50+
{
51+
// Use the builder variable to customize the render pass here.
52+
}
53+
```
54+
55+
## Additional resources
56+
57+
- [The RTHandle System](rthandle-system.md)
58+
- [Shaders](shaders.md)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Create a texture in the render graph system in SRP Core
2+
3+
To create a texture in the render graph system, use the `CreateTexture` method of the render graph instance.
4+
5+
When you create a texture inside a render pass, the render graph system handles the creation and disposal of the texture. This process means the texture might not exist in the next frame, and other cameras might not be able to use it. To make sure a texture is available across frames and cameras, [import a texture](render-graph-import-a-texture.md) instead.
6+
7+
When the render graph system optimizes the render pipeline, it might not create a texture if the final frame doesn't use the texture, to reduce the memory and bandwidth the render passes use.
8+
9+
## Create a texture
10+
11+
To create a texture, in follow these steps:
12+
13+
1. Create a [`TextureDesc`](xref:UnityEngine.Rendering.RenderGraphModule.TextureDesc) object with the texture properties you need.
14+
15+
2. Use the [`CreateTexture`](xref:UnityEngine.Rendering.RenderGraphModule.RenderGraph.CreateTexture(UnityEngine.Rendering.RenderGraphModule.TextureDesc@)) method of the render graph instance to create a texture and return a texture handle.
16+
17+
For example, the following creates a texture the same size as the screen.
18+
19+
``` lang-cs
20+
void RenderCamera(ScriptableRenderContext context, Camera cameraToRender)
21+
{
22+
...
23+
24+
var textureProperties = new TextureDesc(Vector2.one)
25+
{
26+
colorFormat = GraphicsFormat.R8G8B8A8_UNorm,
27+
width = cameraToRender.pixelWidth,
28+
height = cameraToRender.pixelHeight,
29+
clearBuffer = true,
30+
clearColor = Color.blue,
31+
name = "New render graph Texture",
32+
};
33+
34+
TextureHandle tempTexture = renderGraph.CreateTexture(textureProperties);
35+
36+
...
37+
}
38+
```
39+
40+
You can then [use the texture](render-graph-read-write-texture.md) in the same custom render pass.
41+
42+
The render graph system manages the lifetime of textures you create with `CreateTexture`, so you don't need to manually release the memory they use when you're finished with them.
43+
44+
## Additional resources
45+
46+
- [Import a texture into the render graph system](render-graph-import-a-texture.md)
47+
- [Textures](https://docs.unity3d.com/Manual/Textures.html)
48+

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

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Import a texture into the render graph system in SRP Core
2+
3+
To use a texture from outside the render graph system, or to make sure a texture is available across frames and cameras, import it into the render graph system using the `ImportTexture` API.
4+
5+
For example, you can import the back buffer, or create a texture that points to a texture in your project, such as a [texture asset](https://docs.unity3d.com/Manual/ImportingTextures.html).
6+
7+
The render graph system doesn't manage the lifetime of imported textures, so it can't optimize the render graph by removing unneeded render passes. Where possible, [Create a texture inside the render graph system](render-graph-create-a-texture) instead, so the render graph system manages its lifetime.
8+
9+
## Import a texture
10+
11+
To import a texture, follow these steps:
12+
13+
1. Create a [RenderTextureDescriptor](https://docs.unity3d.com/ScriptReference/RenderTextureDescriptor.html) object with the texture properties you need.
14+
15+
For example:
16+
17+
``` lang-cs
18+
RenderTextureDescriptor textureProperties = new RenderTextureDescriptor(Screen.width, Screen.height, RenderTextureFormat.Default, 0);
19+
```
20+
21+
2. Use the `RenderTextureDescriptor` to instantiate a new render texture. For example:
22+
23+
```lang-cs
24+
RenderTexture renderTexture = new RenderTexture(textureProperties);
25+
```
26+
27+
3. Create a handle to the render texture. For example:
28+
29+
``` lang-cs
30+
RTHandle renderTextureHandle = RTHandles.Alloc(renderTexture);
31+
```
32+
33+
4. Import the texture, to convert the `RTHandle` object to a `TextureHandle` object the render graph system can use.
34+
35+
For example:
36+
37+
``` lang-cs
38+
TextureHandle texture = renderGraph.ImportTexture(renderTextureHandle);
39+
```
40+
41+
You can then use the `TextureHandle` object to [read from or write to the render texture](render-graph-read-write-texture.md).
42+
43+
<a name="dispose-of-a-render-texture"></a>
44+
### Dispose of the render texture
45+
46+
You must free the memory a render texture uses at the end of a render pass.
47+
48+
For example, you can create the following `Dispose` method:
49+
50+
``` lang-cs
51+
public void Dispose()
52+
{
53+
renderTexture.Release();
54+
}
55+
```
56+
57+
## Additional resources
58+
59+
* [Textures](https://docs.unity3d.com/Manual/Textures.html)
60+
* [The RTHandle system](rthandle-system.md)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Use a texture in a render pass in SRP Core
2+
3+
You can use the render graph system API to set a texture as an input or output for a custom render pass, so you can read from or write to it.
4+
5+
## Set a texture as an input
6+
7+
To set a texture as an input for a custom render pass, follow these steps:
8+
9+
1. In your pass data, add a texture handle field to the data your pass uses.
10+
11+
For example:
12+
13+
``` lang-cs
14+
// Create the data your pass uses
15+
public class MyPassData
16+
{
17+
// Add a texture handle
18+
public TextureHandle textureToUse;
19+
}
20+
```
21+
22+
2. Set the texture handle to the texture you want to use. For more information, refer to [Create a texture in the render graph system](render-graph-create-a-texture.md) or [Import a texture into the render graph system](render-graph-import-a-texture.md).
23+
24+
3. Call the [`UseTexture`](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.RenderGraphModule.IBaseRenderGraphBuilder.html#UnityEngine_Rendering_RenderGraphModule_IBaseRenderGraphBuilder_UseTexture_UnityEngine_Rendering_RenderGraphModule_TextureHandle__UnityEngine_Rendering_RenderGraphModule_AccessFlags_) method to set the texture as an input.
25+
26+
For example:
27+
28+
``` lang-cs
29+
builder.UseTexture(passData.textureToUse, AccessFlags.Read);
30+
```
31+
32+
In your `SetRenderFunc` method, you can now use the `TextureHandle` object in the pass data as an input for APIs.
33+
34+
## Set a texture as the render target
35+
36+
To set a texture as the output for APIs, use the [`SetRenderAttachment`](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.RenderGraphModule.IRasterRenderGraphBuilder.html#UnityEngine_Rendering_RenderGraphModule_IRasterRenderGraphBuilder_SetRenderAttachment_UnityEngine_Rendering_RenderGraphModule_TextureHandle_System_Int32_UnityEngine_Rendering_RenderGraphModule_AccessFlags_) method. The `SetRenderAttachment` method sets the texture as write-only by default.
37+
38+
For example:
39+
40+
```lang-cs
41+
builder.SetRenderAttachment(textureHandle, 0);
42+
```
43+
44+
You don't need to add the texture to your pass data. The render graph system sets up the texture for you automatically before it executes the render pass.
45+
46+
You can't use `UseTexture` and `SetRenderAttachment` on the same texture in a `AddRasterRenderPass` render pass. Refer to [Change the render target during a render pass](#change-the-render-target-during-a-pass) for more information.
47+
48+
<a name="change-the-render-target-during-a-pass"></a>
49+
## Change the render target during a render pass
50+
51+
You can't change which texture Unity writes to during a render graph system render pass.
52+
53+
You can do either of the following instead:
54+
55+
- Create a second custom render pass, and use `builder.SetRenderAttachment` during the second render pass to change the render target.
56+
- Use the `UnsafePass` API so you can use the `SetRenderTarget` API in the `SetRenderFunc` method. For more information, refer to [Use the CommandBuffer interface in a render graph](render-graph-unsafe-pass.md).
57+
58+
You can use these methods to read from and write to the same texture, by first copying from the texture to a temporary texture you create, then copying back.
59+
60+
If you blit between several textures with different properties, rendering might be slow because Unity can't merge the blits into a single native render pass. Use the `AddUnsafePass` API and the `SetRenderTarget()` method instead.

0 commit comments

Comments
 (0)