So check out this sample project on Github:
https://github.com/carolight/Metal-Shadow-Map/blob/master/Shadows/Shader.metal#L67
This link refers to a shader that performs shadow map testing. In principle, it normalizes the position of the Z fragment that is being visualized and compares it with the Z-map of the shadow map. If it is smaller than shadow-Z, the pixel is fully lit (line 67), otherwise it is slightly colored (line 69).
Instead, you should write (0,0,0, shadow_opacity) for line 69 and (0,0,0,0) for line 67. This should emit transparent pixels. Set shadow_opacity as the uniform from [0.0..1.0].
The rest of the setup is shown as an example . Tilt the plane / camera to the desired setting, skip the cube / vase / all pattern in the main pass if you really do not want it in the scene (line 279 ). (However, pay attention to the shadow pass and save it there).
source share