How do I hide/obscure an object behind a cull mask?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hoot_avi

If I have some geometry set up on a cull mask, is it possible to have any object that passes behind it become hidden? As if it was some sort of ‘cloaking device’?

For context, I’m making a mini-golf game akin to 3D Ultra Minigolf. The playfield is made of geometry that is culled by the camera, so the ball + putter remain visible. Then, a pre-rendered image is placed below the ball + putter viewport, so it looks like you’re putting on a pre-rendered image.

The problem is that when a ball goes ‘behind’ a wall, it doesn’t appear to do so because it’s just a flat image. I’ve made a material that darkens the ball when it goes behind a solid object, but it doesn’t work when all the geometry is culled.

Images for reference:

Image: ball being obscured by solid geometry, with the obscured part of the ball having a darker material
Above shows how I want the ball to look when its obscured by geometry. This is with the cull mask turned off.

Image: two golf balls on top of a pre-rendered image. Red ball is obscured by putter and has darkened material, but blue ball is not obscuring properly
Above is how it actually looks in-game with the cull mask turned on. You can see the red ball is being obscured by the putter correctly, but since there’s no geometry to obscure the blue ball, it looks as if its in front of the wall.

Ideally I’d like for the darkened material idea to work, but if it just hides the ball, I’d settle for that too.

Does anyone have any ideas on how to achieve this?