Clipping Fragments that are in shadow

Hi,
I have another problem with shadows and clipping. This time the effect I am trying to achieve is a flashlight (spot light) that illuminates the scene, showing hidden objects and clipping the parts of the objects that are not currently in direct light of the spotlight.
Right now I am using a custom fragment / vertex shader and use LIGHT_ATTENUATION to compute, whether the fragment is in shadow or not. Doing so clips the fragments as intendet, but the object still blocks shadows behind it, in its original shape.

I know this might be solved, using a surface shader and #pragma addshadow, but I could not get the LIGHT_ATTENUATION to work in the surface function, so I was not able clip the fragments.

Top view of my setup

The shadow error

Here is the code I am currently using:

Shader "Unlit/Shadow_Test"
{
    Properties {}

    CGINCLUDE

    #include "UnityCG.cginc"
    #include "AutoLight.cginc"

    struct v2f_shadow {
        float4 pos : SV_POSITION;
        LIGHTING_COORDS(0, 1)
    };

    half4 _Color;

    v2f_shadow vert_shadow(appdata_full v)
    {
        v2f_shadow o;
        o.pos = UnityObjectToClipPos(v.vertex);
        TRANSFER_VERTEX_TO_FRAGMENT(o);
        return o;
    }

    half4 frag_shadow(v2f_shadow IN) : SV_Target
    {
        half atten = LIGHT_ATTENUATION(IN);
        if (atten == 0.0) {
            clip(-1.0);
        }
        return half4(atten, atten, atten, 1.0);
    }

    ENDCG

    SubShader
    {
        Tags { "Queue"="Geometry" }

        // Forward add pass
        Pass
        {
            Tags { "LightMode" = "ForwardAdd" }
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off
            CGPROGRAM
            #pragma vertex vert_shadow
            #pragma fragment frag_shadow
            #pragma multi_compile_fwdadd_fullshadows
            ENDCG
        }
    }
    FallBack "Diffuse"
}

Regards
Peter

Kind of the same bug as the last post you made. Just delete the fallback line entirely. This will remove the shadowcaster pass, but that’s only needed if you need to receive shadows from the main directional light and cast shadows from any light. If you don’t need that, which in this case you don’t seem to, then there’s no need for the fallback.

If you do want this object to cast shadows for your “reveal” light, but not show up in the camera depth texture … this is the same problem in the thread you linked to in your first post. And unfortunately while it’s possible to write a custom shadowcaster pass that can detect when you’re rendering to the camera depth texture vs for a shadow map, the caveat is you can’t differentiate between a perspective camera’s depth texture and a spot light’s shadow map!