[URP] Access Scene Vertex Colors in Full-Screen Shaders
Solution
Unity 2021.3.x - Unity 6.3.x
Published 28 days ago
In a full-screen shader graph, the Vertex Color node provides data from the full-screen quad rather than scene geometry. This limitation prevents developers from masking effects or excluding specific objects based on baked vertex data during post-processing or full-screen blits.
To access scene vertex data, implement a custom render pass that renders the scene with a specific override material into a global texture. The standard Vertex Color node in a full-screen shader graph is bound to the mesh used for the blit operation, which is typically a single quad covering the camera view.
- Create a
Shaderthat outputsIN.vertexColorto the fragment color. - Create a
ScriptableRenderPassthat usesDrawingSettingswith aFilteringSettingsmask. - Configure the pass to render into a custom RenderTexture.
- Set that RenderTexture as a global shader property using
cmd.SetGlobalTexture. - In your full-screen shader graph, replace the
Vertex Colornode with aSample Texture 2Dnode referencing the global RenderTexture name.
Additional Tips:
- Use
RenderPassEvent.AfterRenderingOpaquesto ensure all static geometry has been processed before sampling. - Ensure the RenderTexture format supports the precision required for your vertex data (e.g.,
GraphicsFormat.R8G8B8A8_SRGB). - Utilize
ShaderTagIdin yourDrawingSettingsto only include objects with specific tags in the vertex color pass.
TL;DR
The Vertex Color node in a full-screen context samples the procedural quad's data. To access scene-specific colors, you must render them to a RenderTexture via a ScriptableRenderPass using a replacement shader.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.