I am super new to shaders and I need to basically be able to see through a large object where a mask overlaps it. I was able to achieve something like this with a stencil shader and URP RenderObjects Feature. But the problem is that, the stencil mask doesnt check for depth. I want to only be able to see the stencil mask, if it isnt occluded by anything.
What I have :

What I want to have :

Stencil Mask Shader :
Shader "Custom/StencilMask"
{
Properties
{
[IntRange] _StencilID ("Stencil ID", Range(0, 255)) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry-1" "RenderPipeline" = "UniversalPipeline"}
Pass
{
Blend Zero One
ZWrite Off
Stencil
{
Ref [_StencilID]
Comp Always
Pass Replace
}
}
}
}
Render Feature :
