Hello Unity community,
Anybody here familiar with customizing URP with the render graph API?
I am implementing a 3D trail renderer. Imagine Unity’s built-in trail renderer, except instead of drawing a strip of triangles that always face the camera, it’s a strip of cylinders.
Here is a good example image of what I hope to achieve:
I know how to procedurally generate meshes; that’s not what I need help with.
What I need help with is preventing overlapping frontfaces from applying the transparency effect twice to the same pixel.
Below is an image of the problem (Cull Back
, ZTest On
, ZWrite Off
):
I will have more than one of these 3D trail renderers at runtime. If two 3D trail renderers overlap, then I want both transparency effects to be applied. But again, if two frontfaces from the same trail renderer overlap, the transparency effect should only be applied once.
The solution I am trying to implement is as follows:
Do a depth prepass for each 3D trail renderer. Later when we go to actually render 3D trails to the screen, we can use the depth texture to cull frontfaces that are occluded by another frontface.
But I have never customized Unity’s render pipeline before in my life.
I am using URP and Unity 6 which uses the render graph API. With some research, I figured out how to add a custom ScriptableRendererFeature
and add custom ScriptableRenderPass
es. Using a RendererListDesc
, I can collect the trail renderers I need to render. But I don’t know how to allocate a separate pass and depth texture for each 3D trail renderer at runtime. How do I do this?
Any help would be appreciated. Thanks.