How to access the Stencil Buffer using C++? [Portals]

Hi guys,

I want to recreate this portal rendering in Unreal:
https://en.wikibooks.org/wiki/OpenGL_Programming/Mini-Portal

They made use of the stencil buffer to achieve the visuals.

I got a working C++ code which shows the concept with OpenGL:
glPortal - YouTube (in the description)
I studied and debugged the code to understand what’s happening.

Now I have to translate it into Unreal, but I don’t know where to start, since the Renderer in Unreal is really complex.

Example of what I want to achieve:

Please help me.

All the best

Dennis

anyone? epic?

I’ve found out that you use could something called SetDepthStencilState via the RHI.
Could someone explain how to use it?
The documentation is non-existent… at least i couldn’t find one.

bump…
epic

I’m now at a point where I got portal doors working with SceneCatpure2D’s, material alignment tricks and it’s looking like a real door, but suffering from performance issues because of the high res captures.

The SceneCapture2D is rotating and moving around while looking at the portal door.
Would it be possible to stencil out the portal door in the scene capture so no rendering is wasted for the area around the portal?

I already inspected the SceneCaptureRendering.cpp but I don’t know where to setup up the stencil properly.
Could someone point me into the right direction please?