Z based occlusion works but now light passes through the meshes

Hi all,
I am using a material function to drive the opacity mask on my master material. This is used in top down games for when a player goes down stairs into a lower level. It works great, but when I use it, the meshes (which are instances) allows light to go through. If I disable it, light works correctly. Any idea why?

image

image