For what it’s worth, I am getting closer to achieving this effect, though not in a practical manner. I discovered that only Opaque & Masked materials are unable to read scene textures (I imagine because they are done in an earlier pass before stencil is available).
I moved the blue material to Translucent, and created a separate UE object for the inside and outside of the box. That, plus reading the stencil buffer produces this, which is what I’m going for, but with some big caveats:
Caveat one: If anyone from Epic is reading, it would be super great to have finer control over the stencil value! Right now it’s per-object, which is a big hammer. That means I have to spit my object in two, to have enough control over the stencil value, which is mighty inconvenient. I’d like to see per material at minimum, or ideally even per pixel from a material output. (It’s per pixel in the hardware).
Caveat two: Try as I might, I can’t get the translucent lighting model to behave anything like the opaque one, even with opacity=1. On my actual material it looks really bad, no matter the value of Translucency/Lighting Mode. Possibly I’m doing something wrong, but I don’t know what.
It’s really close though! It’s great that the stencil buffer became usable in 4.9. With a few more tweaks, it would do just what I want. An option to allow it to work with Masked materials, plus either per-pixel or at least per-material control, would be wonderful.