Opacity Mask Shadow with Pixel Depth Problem

Hi,

I’m trying to achieve the same result of Uncharted 4 with the foliage so that the camera doesn’t clip with it. I did a material with a pixel depth node (even try the perInstanceFadeAmount with a different problem). The result I want is there as the foliage is dithering as the camera get close but the problem is there’s no shadow. As soon as I remove the pixel depth part the shadow is there? Is there a problem with using pixel depth and the shadow pass of the directional light?

the third image is the material function with the pixel depth and I multiply that to the opacity mask of the foliage

Any idea on the problem?

cheers

Dupe: