While using URP, I have 1 object that I want to always render on top of everything else. I’m using the default URP lit shader. Is there an option I can pass to the shader to set ztest to always?
Although you set material/shader’s ZTest
to Always
, it just only on the top of all objects whose ZTest
is not set to Always
or Great
etc.
First of all, UIs are excluded.
Then, there are some choices:
- Set material to a large render queue, maybe
Overlay
which value is 4000, and setZTest
toAlways
. Now, if you did not add any render feature, this material should be on the top of all scene objects.
AllRenderQueue
s you can choose:
public enum RenderQueue
{
Background = 1000,
Geometry = 2000,
AlphaTest = 2450, // we want it to be in the end of geometry queue
GeometryLast = 2500, // last queue that is considered "opaque" by Unity
Transparent = 3000,
Overlay = 4000,
}
- (More recommend) Add a render feature, with a event large enough, like
Before RenderingPostProcessing
(which means do rendering just before post-processing), and override itsDepth
option withWrite Depth
unchecked andDepth Test
isAlways
.
Finally it will like
(Don’t forget to select your appropriate Layer Mask
)
All Event
s you can choose:
public enum RenderPassEvent
{
BeforeRendering = 0,
BeforeRenderingShadows = 50,
AfterRenderingShadows = 100,
BeforeRenderingPrepasses = 150,
AfterRenderingPrePasses = 200,
BeforeRenderingOpaques = 250,
AfterRenderingOpaques = 300,
BeforeRenderingSkybox = 350,
AfterRenderingSkybox = 400,
BeforeRenderingTransparents = 450,
AfterRenderingTransparents = 500,
BeforeRenderingPostProcessing = 550,
AfterRenderingPostProcessing = 600,
AfterRendering = 1000,
}
5 Likes
Setting the render queue of the material to 4000 via script seemed to work perfect for me. Thanks!
1 Like