文档

Unity Engine


User Manual

Script Reference

Unity Engine


Blit in URP

Understand the different ways to perform a blit operation in URP and best practices to follow when writing custom render passes.
阅读时间1 分钟最后更新于 1 个月前

To blit from one texture to another in a custom render pass in the Universal Render Pipeline (URP), use the following:
The shader you use with the
Blitter
API must be a hand-coded shader. Shader Graph shaders aren't compatible with the
Blitter
API.
注意
Don't use the
CommandBuffer.Blit
or
Graphics.Blit
APIs, or APIs that use them internally such as
RenderingUtils.Blit
. These APIs might break XR rendering, and aren't compatible with native render passes.
For example in the
Execute
function in a render pass, add the following:
{ Blitter.BlitCameraTexture(commandBuffer, sourceTexture, destinationTexture, materialToUse, passNumber);}
You can also use the
AddBlitPass
or
AddCopyPass
APIs in your
RecordRenderGraph
method to blit or copy textures. For example:
using UnityEngine.Rendering.RenderGraphModule.Util;... public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData) { // Set up the source texture, destination texture, material, and shader pass number for the blit RenderGraphUtils.BlitMaterialParameters parameters = new(sourceTexture, destinationTexture, materialToUse, passNumber); // Add the blit pass renderGraph.AddBlitPass(parameters, passName: "My Blit Pass"); }

Examples

For full examples of using the
Blitter
,
AddBlitPass
, and
AddCopyPass
APIs, follow these steps:
  1. Import the URP render graph samples. For more information, refer to Importing a package sample in URP.
  2. In the Project window, go to Samples > Universal Render Pipeline > 17.3.0 > URP RenderGraph Samples.
  3. Open
    Blit

    ?

    , BlitWithFrameData, or BlitWithMaterial.

Additional resources