Hi all,
Wondering if it is possible to create a depthmask shader in URP’s shader graph?
For example I have a tree model and a floor plane.
I would like the floor plane to intersect the tree trunk, obscuring everything that is below the floor, revealing the skydome behind it.
Then, I would like another model, say a pond shape to reinstate the buffer, like a portal.
In this screenshot I have the tree selected, and the cap for the pond shape that reveals the pond model that extends below the floor
With custom shaders in build in renderer it is trivial. You just need a depthmask shader for the floor, and set that model to a lower render Queue value than the other objects.
SubShader {
// Render the mask after regular geometry, but before masked geometry and
// transparent things.
Tags {"Queue" = "Geometry+10" }
// Don't draw in the RGBA channels; just the depth buffer
ColorMask 0
ZWrite On
// Do nothing specific in the pass:
Stencil
{
//Ref [_Stencil]
Comp equal
Pass Zero
}
Pass {}
}
}
Then another shader to put on the pond cap that cuts through it again with an even lower queue value.
Shader "Unlit/WriteStencil"
{
Properties
{
_Stencil ("Stencil ID", int) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
ColorMask 0
ZWrite off
Stencil
{
Ref [_Stencil]
Comp always
Pass replace
}
I have to use URP shader graph as I am trying to convert a game to Apple Vision Pro which only uses shader graph and the built in shaders, but the control you have of the depth buffer seems much more limited in URP. Am I wasting my time even looking at this?