https://playcanvas.com/project/671256/overview/stencil-buffer
This is the example project. You can rotate the scene via Mouse, and you can see the various examples.
It also works for particle effects, which i forgot to mention in my previous post.
Have fun