Trouble with screen space and alpha-masked shader

Hello,
I've recently started using Amplify Shader Editor to replicate a shader showcased here. The objective is to dissolve the objects in front of the player, and it consists in a 3D noise generator tied to the world position, blended with the distance from screen center, witch then gets used as the value for opacity masking.

This is the result of just applying the noise. Shadows behave as expected.
However I've encountered a problem related with the use of screen position in the shader: Whenever the screen pos. value is involved in the final calulation, shadows stop working correctly. As you can see in the screenshot below, both the projected shadows and the self-shadowing keeps getting rendered for the pixels that are discarded by the opacity mask.

Then after a certain value of the Mask Clip, they disappear altogether. Interestingly enough, this value is either zero, one, or sqrt(2)/2.
This is the composition of the shader:



Does anyone know what am I doing wrong?
Thank you very much!
I've recently started using Amplify Shader Editor to replicate a shader showcased here. The objective is to dissolve the objects in front of the player, and it consists in a 3D noise generator tied to the world position, blended with the distance from screen center, witch then gets used as the value for opacity masking.

This is the result of just applying the noise. Shadows behave as expected.
However I've encountered a problem related with the use of screen position in the shader: Whenever the screen pos. value is involved in the final calulation, shadows stop working correctly. As you can see in the screenshot below, both the projected shadows and the self-shadowing keeps getting rendered for the pixels that are discarded by the opacity mask.

Then after a certain value of the Mask Clip, they disappear altogether. Interestingly enough, this value is either zero, one, or sqrt(2)/2.
This is the composition of the shader:



Does anyone know what am I doing wrong?
Thank you very much!