Unreal Engine

Portal Mechanic Prototype

Ever wondered how the portal mechanic in Portal works?

In this Unreal Engine prototype, I'm recreating the effect of placing two portals, looking through one, and emerging from the other. At its core, a portal is just a surface displaying a render target generated by a camera. The trick is computing the projection camera's transform relative to the linked portal.

Proj_A = PlayerCamera * Inverse(PortalA) * Rotate180Yaw * PortalB;

Proj_B = PlayerCamera * Inverse(PortalB) * Rotate180Yaw * PortalA;

By transforming the player's camera into the source portal's space, applying a 180° rotation, and then transforming it into the destination portal's space, the projection camera sees exactly what should appear through the portal.

That's all it takes to create the illusion of a connected space between two distant locations.