Creating an alphaMask from scene depth map to use it masking a shader

Anyone an idea how to apply a masked shader based on a depth map?example