Portal Basics
Portals are not teleporters!
Portals are used to reduce the amount of work the renderer has to do. In essence, a portal is a window into an area of a map; if the renderer can not see a portal into an area of the map, it knows the area behind the portal can not be seen by the player either, and therefore does not need to render it. Similarly, if the player is very far from the portal, such that it only uses a few pixels on the screen, the renderer knows it's not worth rendering the area behind it.
The important thing to understand is that portals are only useful when used to distinguish separate areas, and when the area they hide is complex enough to make it worth not rendering. Hence portals are usually created in doorways or entryways that are crucial for the player to get from one part of the map to another.
There are several types of portals. 'Visportals' are the most basic and simply won't render the area behind it when it itself isn't on-screen (or is too small to be considered worth rendering). Other portals are used to control the flow of light and to alter the ambient lighting within the different interior sections of maps. However, all portals are created in the same way and follow the same basic rules.
Contents
Creating a portal
A portal is created by assigning all but one face of a brush the nodraw texture. The remaining face should be given the portal texture (visportal, outsideportal, or otherwise.) The face with the chosen portal should cut completely through the area to be portalled - that is, the portal-textured face should touch ceiling, floor, and walls on both sides. Usually, this means portals are rectangular.
It is also important to note that portals must completely seal areas from each other. So if you have two rooms joined by three doorways, if you add a portal to one doorway, you need to add a portal to the other two doorways as well. In other words, it should be impossible to look at one side of a portal and then look at the other side without needing to pass through a portal to do so.
Portal types
visportal
- Texture: /editor/visportal
The most common portal, used to hide areas of a map that should not be rendered when the portal is not in view. Note how the green visportal texture is placed in doorways - when those doorways are not in view, the areas behind them will not be rendered. Also note how the purple 'nodraw' texture in the first screenshot is actually the backside of the bigger portal in the second screenshot.
Uses
Visportals serve two main purposes:
- They can reduce the number of polygons that need to be drawn, hence
- They can reduce the number of textures that need to be in memory
The combination of these means that portals can lead to significant performance gains, as the renderer has less work to do. Hence some areas can use more detail than normal, knowing the additional detail will be culled away by portals when not in sight. Conversely, portals can also make the game more accessible on lower-spec machines as the renderer knows which areas can be safely culled without affecting the experience for the user.
The difficulty is placing portals and geometry appropriately. If placed badly, it can mean that two high-detail areas are in view at the same time, so the engine renders many more polygons and uses more texture memory, in some cases leading to a sudden decrease in performance.
ambientportal
- Texture: /editor/ambientportal
Used to separate ambient lighting areas defined by light_ambient entities.
audioportal
- Texture: /textures/editor/audioportal
Used to separate areas of sound, for example to make sure the sound of machinery in one room doesn't leak into an adjacent room.
aasclusterportal
- Texture: /textures/common/aasclusterportal
Distinguishes to areas for AAS generation purposes.
outsideportal
- Texture: /textures/editor/outsideportal
Used to separate the inside (indoors) and outside (outdoors) of a level, in order to control light (and shadow) from sunlight.
playzoneportal
- Texture: /textures/editor/playzoneportal
Used to separate a map into two or more playzones - in the same manner that Slipgate is split across two environments. Each of Slipgate's environments are surrounded with a playzone portal hull.
Developer Commands
- r_showPortals 0/1/2/3 - turns on rendering of portal outlines so it's possible to see which portals are active (rendered green) and which are not (rendered red). This is a good command to use to help understand how portals work and where they are placed in other maps. Setting r_showPortals 3 displays what type each portal is.
- r_usePortals 0/1 - turns on/off portals (when turned off, everything is drawn, whether it is visible or not)
Additional Resources
- Vis Portals - a good overview of visportals and explanation of how they work
- Visportal topic on modwiki - a slightly simpler explanation