Download

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:
https://www.youtube.com/watch?v=_59h0I7LEy0 (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:
70475-unbenannt.png

Video Example: https://www.youtube.com/watch?v=Of3JcoWrMZs (done in Unreal by GalaxyMan2015)

Please help me.

All the best
Dennis

Bump.
Any help would be apreciated. :slight_smile:

I’ve found out that you could use 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.

You don’t need a stencil buffer, you just need to use ScreenAlignedUVs on the portal’s material.

Check out my example here: https://forums.unrealengine.com/showthread.php?94146-n00b-question-regarding-post-process-portal-effect&p=439050

I go a step further, using a SceneCapture2D that matches the main viewport resolution and then mapping that RenderTarget to the portal using the Pixel-Perfect variant of the ScreenAlignedUVs node.

If your post process quality is turned all the way down (don’t know why it interferes in 4.9), you shouldn’t be able to detect the transition (well, I couldn’t using the stock FPS character controllers).

Thanks for pointing me to this thread.
I actually experimented with CustomDepth and CustomStencil but I never had the idea to put it on the actual mesh.

Also thanks for uploading your solution.
I’ll try it later and report back then!

Still interested in a stencil buffer solution.

Best
Dennis

Still looking for a solution :slight_smile:

Necro, looking to do this for vr