How to mask 3D game object or 2D sprite?

70867-masking.jpg
I want to make a game object can only visible under a limited area. Just like the Mask Component for the UI game object, but I want it can also works on other non-UI game object too.
So how to make it?

Use a shader that writes to/tests the value in the stencil buffer.