Hole shader

Hey, I have a shader which is responsible for cutting holes in a mesh. This combined with an URP render object with the following settings. I have an issue where in some cases it shows through the object. Is it possible to prevent this, or maybe only make it work in a direction? Positive/Negative Z.

Name “Shell”
Event: AfterRenderingOpaques
Overrides Stencil: value equal to the one of the shader.
Compare function: Not equal
Pass: Keep
Fail: Keep
Z Fail: Keep

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
            }
        }
    }
}

I use this with 2 plates as a model. With one having the face pointing up, other down.

It seems to work good, but possible too good. It is also showing from the sides.

9805236--1407894--upload_2024-4-30_14-52-17.png

It seems fine if I make it longer, but not with more complex meshes.

Managed to solve it with some help. Thank you all! Don’t know how to delete this post.