SceneCapture Projection Matrix for Portal

Hi,

I am new to Unreal and GameDev in general, but I was playing around and trying to make portals for fun. I noticed that when objects were placed in front of the portal, they can get in the way of the projection captured by the SceneCaptureComponent.

Here is the problem:

An extra cube is placed in front of Portal2

From Portal1, this cube is seen, despite being in front of the portal:

While trying to fix this, I came across FClipProjectionMatrix and wrote these lines of code:

SceneCapture->ClipPlaneNormal = GetActorForwardVector();
SceneCapture->ClipPlaneBase = GetActorLocation();

SceneCapture->CustomProjectionMatrix = FClipProjectionMatrix(TargetPortal->GetCameraProjectionMatrix(), FPlane(GetActorLocation()));

(GetCameraProjectionMatrix() is from Creating Seamless Portals in Unreal Engine 4 | Froyok - Fabrice Piquet)

After compiling, I saw this horrible monstracity:

Technically the cube is gone, but now it looks awful. How could I fix this? I’m not really familiar with Matrices and Vectors (I’m only a HS Sophomore), but I’m trying to learn. Any help is appreciated!

1 Like