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

2.2 KiB

Import a texture into the render graph system in SRP Core

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.

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.

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 instead, so the render graph system manages its lifetime.

Import a texture

To import a texture, follow these steps:

  1. Create a RenderTextureDescriptor object with the texture properties you need.

    For example:

    RenderTextureDescriptor textureProperties = new RenderTextureDescriptor(Screen.width, Screen.height, RenderTextureFormat.Default, 0);
    
  2. Use the RenderTextureDescriptor to instantiate a new render texture. For example:

    RenderTexture renderTexture = new RenderTexture(textureProperties);
    
  3. Create a handle to the render texture. For example:

    RTHandle renderTextureHandle = RTHandles.Alloc(renderTexture);
    
  4. Import the texture, to convert the RTHandle object to a TextureHandle object the render graph system can use.

    For example:

    TextureHandle texture = renderGraph.ImportTexture(renderTextureHandle);
    

You can then use the TextureHandle object to read from or write to the render texture.

Dispose of the render texture

You must free the memory a render texture uses at the end of a render pass.

For example, you can create the following Dispose method:

public void Dispose()
{
    renderTexture.Release();
}

Additional resources