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:
Create a RenderTextureDescriptor object with the texture properties you need.
For example:
RenderTextureDescriptor textureProperties = new RenderTextureDescriptor(Screen.width, Screen.height, RenderTextureFormat.Default, 0);Use the
RenderTextureDescriptorto instantiate a new render texture. For example:RenderTexture renderTexture = new RenderTexture(textureProperties);Create a handle to the render texture. For example:
RTHandle renderTextureHandle = RTHandles.Alloc(renderTexture);Import the texture, to convert the
RTHandleobject to aTextureHandleobject 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();
}