The proper way to do this would be to do the alpha cutout only if you’re not in the shadow pass of the shader. I thought there was a way to do this, but I haven’t managed yet to find any information or documentation about it.
They plan to add a global variable called IN_SHADOW_PASS, but in the meantime this hack actually fixes the issue by only discarding the fragment when not in the shadow pass. Thanks for the GitHub issue link!
I’ve been try to do a similar x-ray shader for my project without much success. Any chance you could describe your setup in a bit more detail or maybe provide a small demo project of a working xray shader? I am not sure the shader snippet you posted works as is. Cheers!
Just to follow up I did manage to get your snippet working with some tweaks so I may be all good. I was originally trying to get the world space coordinates of the fragment between the player and camera to check if it should be alpha’d or not, but your solution seems to be doing the trick!
Nice! If you could share the result you achieved it would be cool.
The only problem with this shader is the depth based on the global Z axis, as this could be improved to use the camera orientation instead to be used in any camera angle other than top down games, but I don’t know how to calculate that.