How can I make objects visible only when they are within a certain volume?

An effect similar to THIS. When an object overlaps the volume halfway through, the part of the object that is not within the volume should be invisible.

I’ve tried doing this with opacity masking, but that does not work well with shadows if the camera is not itself within that volume as well.

hey, did you have any success? I know that you can do similar things with the render texture, but I would also like to go for some direct shader solution.