Files
stas-barecky/Library/PackageCache/com.unity.render-pipelines.core@ce86d16dfe9d/Documentation~/render-graph-blit.md
2026-01-08 20:43:08 +05:00

3.9 KiB

Blit using the render graph system in SRP Core

To blit from one texture to another in the render graph system, use the AddBlitPass API. The API generates a render pass automatically, so you don't need to use a method like AddRasterRenderPass.

Follow these steps:

  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.

  2. Add using UnityEngine.Rendering.RenderGraphModule.Util to your render pass script.

  3. In your render pass, create a field for the blit material. For example:

    public class MyBlitPass : ScriptableRenderPass
    {
        Material blitMaterial;
    }
    
  4. Set up the texture to blit from and blit to. For example:

    TextureHandle sourceTexture = renderGraph.CreateTexture(sourceTextureProperties);
    TextureHandle destinationTexture = renderGraph.CreateTexture(destinationTextureProperties);
    
  5. To set up the material, textures, and shader pass for the blit operation, create a RenderGraphUtils.BlitMaterialParameters object. For example:

    // Create a BlitMaterialParameters object with the blit material, source texture, destination texture, and shader pass to use.
    var blitParams = new RenderGraphUtils.BlitMaterialParameters(sourceTexture, destinationTexture, blitMaterial, 0);
    
  6. To add a blit pass, call the AddBlitPass method with the blit parameters. For example:

    renderGraph.AddBlitPass(blitParams, "Pass created with AddBlitPass");
    

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 API.

Customize the render pass

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.

For example:

using (var builder = renderGraph.AddBlitPass(blitParams, "Pass created with AddBlitPass", returnBuilder: true))
{
    // Use the builder variable to customize the render pass here.
}

Additional resources