Is there any way to use stencils in a masked or opaque material?

Take a look at this Custom Depth and Custom Depth Stencil in UE4 - Superyateam Gamedev