Rendering out Custom Stencil Buffer to Masks

I’m also troubled by this problem, but unfortunately, almost all the tutorials I found are for the situation of only one custom stencil depth of a template. The situation where multiple custom stencil depths exist simultaneously was not mentioned.