Question On Portals Question submitted by (15 January 2002) | Return to The Archives

| Hi ... I've seen many times articles about Portals ... But I don't understand what a portal is ... Can you answer me plz? Bye Avatar.dx ps : I'm french so you may think my english is bad ... sorry !!! |

| Trust me when I say my French is worse than your English! :) I'm going to cover Portals in the most general terms. For anybody that's looking for specific details, there are plenty of places to get this information. You can always start right here on flipCode with The Phantom's Portal Engine Series.
According to my dictionary, a 'portal' is defined as "any point or place of entry". This is quite correct even in computer-graphics terms, although a bit lacking. Let's start with a few examples of common uses of portals in games.
Consider a simple room in one of your favorite FPS games. The room has a door that leads to another simple room. That doorway could be a portal (in a portal-based game, it would be.) How is this useful? Keep reading...
Let's assume these two rooms are different objects in the geometry. If you can't see the doorway (the portal) then you can't see the other room, hence you know you don't need to draw it (and you save yourself the time required to render it.)
In this case, a portal is used as a tool for visible surface determination. If the portal is visible, then the polygons on the other side of it (i.e. the other room) are clipped to the doorway (portal) and rendered. Because of this, portals are often represented by polygons, giving the engine something tangible to work with in order to perform the required actions (in this case, clipping.)
This visibility-and-clipping process can repeat recursively: another doorway (portal) might be visible through the first doorway (portal), in which case this third room would be clipped to both doorways (portals) and rendered.
Like any visibility scheme, portals come with their own set of limitations. Portals are usually placed manually by level designers using special editing tools. Also, your generic portal implementation will not work for visibility on terrains and other outdoor scenes, as they require specific "points of entry."
But don't let this deter you! Portals have a number of other great uses (even in situations where they're not the best solution for visibility.)
Most often, a portal is used to separate two distinct clusters of geometry (commonly referred to as 'sectors'.) In the above example, each room would be a sector. In this case, a portal would have two sectors associated with it so that the engine can locate and render the related geometry for each sector. So, standing on the front side of a portal, you can see the geometry on the back side, and vice versa.
Another great use for a portal is a mirror. We do this by modifying sectors that a portal references. Normally, the front side of a portal references the sector on the back side. However, if the front side of a portal referenced the sector on the front side, then when looking through that portal from the front, you would see the sector that you were standing in.
In order to complete the illusion of a mirror, we would need to calculate the proper reflection transform to get a properly reflected view through the portal. The work for calculating this in your engine is trivial. Because of this, portals often have transforms attached to them as well as sectors.
We're not done with our examples just yet... we can also apply portals to a portal transport (those magical things that you step through and appear at the other end of a level.)
This works just like the side-by-side-rooms example, with the exception that the two sectors are far away. But to a portal, it doesn't matter where the sectors are, they're just references. It also doesn't matter what orientation the sectors are because we can calculate the proper transform for each side of the portal to allow us to view the geometry with the proper viewpoint.
Hopefully, I've whetted your appetite for portals. There are plenty of references out there and various implementations. Good luck!
Response provided by Paul Nettle

This article was originally an entry in flipCode's Ask Midnight, a Question and Answer column with Paul Nettle that's no longer active.

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.