|
1 | | -# URP blit best practices |
| 1 | +# Blit in URP |
2 | 2 |
|
3 | | -A blit operation is a process of copying a source texture to a destination texture. |
| 3 | +To blit from one texture to another in a custom render pass in the Universal Render Pipeline (URP), use the [Blitter API](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@latest?subfolder=/api/UnityEngine.Rendering.Blitter.html) from the Core Scriptable Render Pipeline (SRP). |
4 | 4 |
|
5 | | -This page provides an overview of different ways to perform a blit operation in URP and best practices to follow when writing custom render passes. |
| 5 | +The shader you use with the `Blitter` API must be a hand-coded shader. [Shader Graph](https://docs.unity3d.com/2022.3/Documentation/Manual/shader-graph.html) shaders aren't compatible with the `Blitter` API. |
6 | 6 |
|
7 | | -## The legacy CommandBuffer.Blit API |
| 7 | +**Note:** The recommended best practice is not to use the `CommandBuffer.Blit` or `Graphics.Blit` APIs with URP, or APIs that use them internally such as `RenderingUtils.Blit`. These APIs might break XR rendering, and aren't compatible with native render passes. You can still use `CommandBuffer.Blit` and `Graphics.Blit` with the Built-In Render Pipeline. |
8 | 8 |
|
9 | | -Avoid using the [CommandBuffer.Blit](https://docs.unity3d.com/2022.1/Documentation/ScriptReference/Rendering.CommandBuffer.Blit.html) API in URP projects. |
| 9 | +For example, add the following: |
10 | 10 |
|
11 | | -The [CommandBuffer.Blit](https://docs.unity3d.com/2022.1/Documentation/ScriptReference/Rendering.CommandBuffer.Blit.html) API is the legacy API. It implicitly runs extra operations related to changing states, binding textures, and setting render targets. Those operations happen under the hood in SRP projects and are not transparent to the user. |
| 11 | +```c# |
| 12 | +{ |
| 13 | + Blitter.BlitCameraTexture(commandBuffer, sourceTexture, destinationTexture, materialToUse, passNumber); |
| 14 | +} |
| 15 | +``` |
12 | 16 |
|
13 | | -The API has compatibility issues with the URP XR integration. Using `cmd.Blit` might implicitly enable or disable XR shader keywords, which breaks XR SPI rendering. |
| 17 | +For a full example, refer to [Example of a complete Scriptable Renderer Feature](../renderer-features/how-to-fullscreen-blit.md). |
14 | 18 |
|
15 | | -The [CommandBuffer.Blit](https://docs.unity3d.com/2022.1/Documentation/ScriptReference/Rendering.CommandBuffer.Blit.html) API is not compatible with `NativeRenderPass` and `RenderGraph`. |
| 19 | +## Additional resources |
16 | 20 |
|
17 | | -Similar considerations apply to any utilities or wrappers relying on `cmd.Blit` internally, `RenderingUtils.Blit` is one such example. |
18 | | - |
19 | | -## SRP Blitter API |
20 | | - |
21 | | -Use the [Blitter API ](https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Rendering.Blitter.html) in URP projects. This API does not rely on legacy logic, and is compatible with XR, native Render Passes, and other SRP APIs. |
22 | | - |
23 | | -The shader you use with the `Blitter` API must be a hand-coded shader. [Shader Graph](xref:um-shader-graph) shaders aren't compatible with the `Blitter` API. |
24 | | - |
25 | | -## Custom full-screen blit example |
26 | | - |
27 | | -The [How to perform a full screen blit in URP](../renderer-features/how-to-fullscreen-blit.md) example shows how to create a custom Renderer Feature that performs a full screen blit. The example works in XR and is compatible with SRP APIs. |
| 21 | +- The blit examples in the [URP Package Samples](../package-sample-urp-package-samples.md) |
| 22 | +- [Custom render pass workflow](../renderer-features/custom-rendering-pass-workflow-in-urp.md) |
| 23 | +- [Using textures](../working-with-textures.md) |
0 commit comments