Call of Duty 2: Portals

From COD Modding & Mapping Wiki
Revision as of 03:31, 13 February 2009 by CoDEmanX (talk | contribs) (New page: Image:Nutshell.png Portals explained by Infinity Ward Portals divide the world into cells. Each cell is a non-solid, non-detail volume inside the BSP that does not cross any portals. ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Portals explained by Infinity Ward

Portals divide the world into cells. Each cell is a non-solid, non-detail volume inside the BSP that does not cross any portals. Every non-solid part of the map exists in exactly one cell. Cells can have any arbitrary shape, such as L or cube. Portals connect two cells. The classic example is doorways in a house, where each room is a cell and the doorways are portals.


Whenever a cell is determined to be at least partially visible, all of the world geometry in that cell gets drawn. If a world surface exists on both sides of a portal, it gets drawn if either of the two cells are drawn.


Note: model bounding boxes will get clipped against the portals so they may not get drawn even if they are in a cell that is drawn.


Portals gives better culling than PVS since they effectively do the exact cell-to-cell PVS for a single view point. Portals can even cull geometry when you turn the mouse, rather than being fixed for a given point. Too many portals can slow the game down because it does too much time calculating what to draw. Portals do frustum culling of triangles, (strafe in front of a doorway in CoD2 with r_showtris 1 to observe this in action). Because of this it is not necessary to have portals inside of rooms, only at the windows and doors. Use r_showportals 1 in the game to see where IW placed their portals.

Too few portals can slow the game down because it quickly decides to draw too much.


You have to place portals in radiant for portal-based rendering. A portal can be any brush face; it doesn't have to be axial and it doesn't have to be square. To create a portal, create a brush and then make most sides “textures / common / portalnodraw” and one side "textures / common / portal".


portalnodraw is just like nodraw but is designed to be used with portal.


Only structural brushes can make up the other walls of a cell with portals. Open a map and filter out the patches (Alt-3), detail brushes (Ctrl-d) and entities (Alt-2) and observe whats left. Usually this will be just a few simple walls, the sky and some caulk brushes. This is what the portal render “sees”.


Portals are not allowed to have the same cell on both sides. If the compiler detects this, it will ignore the portal and issue a warning. This is known as a portal leak and it will generate a .lin file the same as a regular leak.


Portals are not allowed to have one side completely against a solid brush (partially is okay, including partially inside solid). If the compiler detects this, it will ignore the portal and issue a warning.


Portals are not allowed the T-junction with other portals. The portal whose face is touching the edge of the other perpendicular portal must have its face split along the edge it shares with that portal.


An example of placing 2 portals to cull geometry around a corner: The diagonal portals here each share 1 edge exactly on the inside corner of this hallway. Cell number 1 can not see the portal face which divides cell 2 from cell 3. Since it can not see this portal, it does not draw the triangles inside cell 3.


############

# 2  /   3

#   /

#  /########

# / #

#/  #

# 1 #


Another example. Position 4 can see through the portal into the cell where position 5 is, however... frustum culling keeps the observer at position 4 from drawing the object at position 5.

     4

 

##########-------##########

#                         #

#  5                      #

#                         #

#                         #

#                         #


Sources: Infinity Ward Docs