How do I create a rendering mask which filters out what actors to render?

Is there a way for me to draw certain actors only under certain conditions, such as a specific rendering mask? To help give a better idea of what I’m trying to accomplish, here is a visualization:

Custom depth and custom stencil are exactly what you would use for that.