Skip to main content
Share Your Experience: Take the 2024 Developer Survey

a doorway or opening that connects two areas of the game space, even if those areas aren't adjacent & aligned in the physical layout of the environment. Players can typically see and move through the portal into the linked space. Portals were most famously used in the Valve's Portal game series, where the player can shoot linked portals onto various surfaces and traverse between them to solve puzzles.

Portals in games can be static, constant features of a space created by the level designer, or dynamically placed by the player as in the Portal series and its predecessor Narbacular Drop.

A portal involves four key ingredients:

  • A "source" aperture in the game space, dictating the shape of the portal the player will see & interact with.

  • A destination in the game space, describing where the portal should lead. If the portal can be traversed both ways, this may itself be a source aperture, but it could be as little as a position & orientation for a one-way portal.

  • A system for rendering the view through the portal (more below).

  • A system for handling gameplay interactions at the portal boundary.

These gameplay interactions commonly involve....

  • Allowing the player or objects to pass into & through the portal (ignoring collisions with geometry behind the portal's aperture - eg. if the portal is placed like a decal on a solid wall)

  • Teleporting the player & objects from the source to the destination when they cross a threshold, and rotating them to account for any orientation difference.

  • Allowing influences (like beams or bullet raycasts, AI vision checks, sound propagation, etc.) to pass through the source and continue from the destination.

  • Handling physics interactions for objects near or straddling the portal

Rendering Portals

In modern 3D games, portals are typically drawn using a second or virtual camera. The position and orientation offset from the "source" to the "destination" portal is applied to the primary camera's view matrix to produce a camera looking into the scene through the destination portal from the corresponding angle. The secondary camera's near plane is normally adjusted to match the back of the portal/destination point, so no objects behind the portal are visible to this camera.

The view from this second camera can be rendered to an off-screen texture, and this texture used to paint the source aperture when rendering the primary camera's view. This is often simple to set up, but can suffer from sampling artifacts when the portal is viewed up-close or at shallow angles.

Alternatively, the stencil buffer can be used to mark pixels occupied by visible portal apertures, and the scene can be drawn recursively into these masked regions for each visible portal, adjusting the camera each time.

Usually some type of fallback is needed to avoid unlimited recursion when the visible area crosses multiple portals in a loop. This could include adding increasing opacity or fog to deeper portal levels, or sampling results from a previous frame to create a feedback loop.

Related: Portal Rendering / Portal-Based Engines

Some game engines use a technique called Portal Rendering as a form of occlusion culling. The game space is divided into discrete zones, and apertures through which one zone can be seen from within another are marked as portals. The rendering system then walks this visibility graph, recursing through visible portals as it collects geometry to draw, and using the portals' edges to reject occluded content.

A side effect of this system, at least as it was used in some early 3D games for PC, is that zones which are adjacent for visibility and navigation purposes might not need to be adjacent or aligned in the editor space where the level designer lays them out. This can help in assembling large and complex levels, without needing to shift a large number of connected zones with each small change. It can also be used to creative effect, deliberately creating magical doorways, or paradoxical and impossible spaces.

Duke Nukem 3D's Build engine implemented this technique in a way which famously allowed portals to lead back into the same zone with a modified orientation, and this was used to create mirrors in the game (a portal leading to itself with its handedness flipped).

Portals without Portals

Note that some portal-like effects for static portals can also be accomplished through clever level design, without special rendering effects. The level designer creates multiple copies of a space, some where the portal-linked portions are literally adjacent and some where they are not, and places triggers to teleport the player between the copies at carefully selected thresholds where they won't be able to detect the change. Care must be taken to keep all copies of the space in synch (eg. as the player moves objects or leaves marks) to avoid giving away the trick.