I have a custom ScriptableRenderPass that creates and renders to a global texture for use in my shaders. The texture doesn’t need to change every frame, so I only want to add the respective RasterRenderPass once.
As far as I can tell, I would need to call renderGraph.CreateSharedTexture() to create a texture that persists across the remaining lifetime of this render pass, not just a single frame. However, when calling this Method in RecordRenderGraph() I get the following exception: InvalidOperationException: A shared texture can only be created outside of render graph execution.
Now, I get why this is the case, but I don’t understand where/when else I’m supposed to call that method.
The docs don’t elaborate and the package examples don’t use it either.
You might want to use a custom ContextItem and only assign textures to a material when you actually need it.
Context Items can store data in a frame and can also carry data over to the next frame:
public class CustomPassData : ContextItem
{
public TextureHandle color = TextureHandle.nullHandle;
public TextureHandle depth = TextureHandle.nullHandle;
// Reset function required by ContextItem. It should reset all variables not carried
// over to next frame.
public override void Reset()
{
//only reset the parts we want
depth = TextureHandle.nullHandle;
}
}
You can than create and assign textures like this: (in RecordRenderGraph)
var customPassData = frameData.GetOrCreate<CustomPassData>();
var descriptor = renderGraph.GetTextureDesc(resourceData.activeColorTexture);
descriptor.name = $"CustomPassData Color ";
descriptor.clearBuffer = true;
customPassData.color = renderGraph.CreateTexture(descriptor);
//...
And access them again with frameData.get<CustomPassData>()
this is for CreateSharedTexture and not CreateTexture.
As of APR 06 2025, there’s no docs for the command so it’s probably an incomplete feature that should not be used. CreateSharedTexture is not even used anywhere in their own code.
The render graph system, while it is the fancy and new way of doing things that Unity is moving towards, it still has rough edges, especially with little bombs like CreateSharedTexture. People like us see these undocumented features and try to be clever and adopt them and try to adhere to the sales literature but it’s really at your own peril.
To summarize: A lack of documentation and/or prior implementation (by Unity) means you’ve ventured out-of-bounds.
Use RenderTextures and RTHandles for now. When they complete the feature they’ll probably tell us to go back and replace them. Don’t try and save yourself the trouble of updating your work to the new practices until they’re fully implemented. There’s basically an indeterminate amount of time before they complete these features or backtrack and eliminate them entirely, so don’t hinge any future plans upon them.
TL;DR: Unity is extremely diligent when it comes to marking API commands as [deprecated] but completely negligent when it comes to marking them as [unfinished]