Possible to make something transparent (ideally a depth mask shader) receive shadows?

Pretty much as the title suggests. I’m working on AR apps, and I would like to be able to create the illusion of virtual objects casting shadows on the real world. However, none of the transparent shaders (nor the Depth Mask shader from the QCAR package) receive shadows. How can I add the ability to receive shadows to an object that is otherwise invisible?

(I did try turning “Lighting On”, but it appears it was not to be so easy)

Shader "DepthMask" {
   
    SubShader {
        // Render the mask after regular geometry, but before masked geometry and
        // transparent things.
       
        Tags {"Queue" = "Geometry-10" }
       
        // Turn off lighting, because it's expensive and the thing is supposed to be
        // invisible anyway.
       
        Lighting Off

        // Draw into the depth buffer in the usual way.  This is probably the default,
        // but it doesn't hurt to be explicit.

        ZTest LEqual
        ZWrite On

        // Don't draw anything into the RGBA channels. This is an undocumented
        // argument to ColorMask which lets us avoid writing to anything except
        // the depth buffer.

        ColorMask 0

        // Do nothing specific in the pass:

        Pass {}
    }
}

I was wondering the same thing :slight_smile:

It is possible to draw just the shadows, but you’ll need to dig into the lighting code, and write a custom fragment/vertex shader, in stead of relying on what is automatically generated by the Shaderlab code you have right there.

If you feel adventurous, I recommend looking at the code generated by Surface Shaders to figure out the location of the shadow on your mesh. And there are actually already threads about receiving shadows in a custom fragment/vertex shader that might make it easier for you.

When you have the shadow data, you can use the clip function (in stead of removing everything using ColorMask 0, like in your example), to remove anything that’s not in the shadows. At that point you can draw anything you want in the location of the shadows.