Mask object behind static geometry viewed from custom point

Help me please. I need to get a mask that will represent something like a shadow from custom point in space that I can use in shader. For example to hide parts of mesh that is invisible from given point in space.

May be somehow I can get depth map or something like that? But it must be a cubemap. And it must be realtime, and not to much expensive performance vise. Can I do that only inside shader or it must be done somehow else? Or may be some shadow volumes? Any ideas?