[Tutorial] Areaportals - All you need to know

Psy

The Imp Queen
aa
Apr 9, 2008
1,706
1,491
Here's a guide all about areaportals. Where to use them, where they are used, and just what the hell they do!


What is an areaportal?

An areaportal is a means of reducing the amount of objects that the engine has to render based on the player's viewing angle (the view frustrum) through an areaportal or a bunch of areaportals that are visible.

Here's a simple diagram.

diagram_1.png


Imagine this as a room with a wall dividing the area into 2 parts and in the center of the wall is a window. In this window, an areaportal is placed. On the one side of the wall is the player and on the other are 4 oildrums in a neat row represented by little black circles.. In red is the area outside the view frustrum and in green is the area inside the view frustrum.

As you can see, the two oildrums are inside the view frustrum (remember, this is the player's view) and so they are being rendered whilst the oildrums outside the view frustrum are not. This means that everything which the player cannot see is not being rendered. Useful!

Now let's put this to practice.


A simple example

hammer.jpg


Download this map! - Includes BSP and VMF

Here is the same example previously described but made for real. It's the exact same setup as shown in the diagram except their are considerably more oildrums. :p

Let's view this setup in game with some fancy comparisons to nail the point home!

headon_off.jpg


With the areaportal off, that's every single oildrum in that section of the room being rendered. All 32 of them.

headon_on.jpg


With it on, you will notice that oildrums on the left and the right are no longer being rendered. Clearly our areaportal friend is doing his job as he prevents the oildrums outside the view frustrum from being rendered!

Now let's move closer and into a corner to see what's being rendered - remembering how our viewing angle affects the number of objects being rendered. ;)

close_off.jpg


And now let's turn it on again.

close_on.jpg


As you can tell, that's a huge difference that when applied to real maps can greatly benefit it's performance. Speaking of which...


Show me more (real life) examples!

Now for a series of real-life examples taken from multiple stock and custom maps. Green bits represent where an areaportal has been placed. A description is written below each group of images.

example1.jpg

example1-off.jpg

example1-on.jpg

Looking to the right and left, you can see the number of objects that are no longer being rendered which includes both props and brushes.



example2.jpg

example2-off.jpg

example2-on.jpg

It's the same ordeal here but the difference is more extreme because the angle of the view frustrum is more acute then before. Most objects behind the wall on the left are no longer rendered.



example3.jpg

example3-off.jpg

example3-on.jpg

Again, it's the same. Lots of stuff being unrendered.



Basic Areaportal Construction

Areaportals are very easy to create within your map. Essentially, you place areaportals at every exit (doors, windows, etc) within an area to seal it off just like you would seal a map off from the void using world brushes. Creating one is as simple as creating a brush which completely fits the size of whatever you are trying to seal off, texturing it using toolsareaportal and then tieing it by hitting CTRL + T and choosing func_areaportal from the drop-down menu.

Here's a simple example of how you would use areaportals in a simple room with 2 areas.

diagram_2.png


Area 1 has two areaportals at either exit leading into Area 2. This will work correctly. However if we were to remove one of them...

diagram_3.png


...VBSP will get very angry and tell us that an areaportal "doesn't touch two areas". Loading up the pointfile will give us a red line which loops back out of the first leak it finds withing the area and back round into our single areaportal.



Where and When to Use Them

There are many ways in which areaportals are used. Here are some various methods.

The 'Door' Method

This method involves 'opening' and 'closing' an areaportal linked to a func_door. When the door opens, the areaportal opens; when it closes, the areaportal closes. You link your areaportal to your door by entering the name of the door under the 'Name of Linked Door' property of your chosen areaportal.

Remember, when the areaportal is closed, anything behind it will not be rendered so make sure the areaportal is thin enough to fit inside the door brush or model otherwise it will disappear when the areaportal closes.

The 'Always Open' Method

These areaportals are used extensively and are the same type used in the simple example shown earlier in this tutorial. Here are a few examples from Valve maps to show how they've used them.

hammer-1.jpg

hammer-3.jpg

This is by far the most common usage of areaportals; used to section internal rooms within a building nice and neatly.

hammer-2.jpg

This is where we start to get a little more creative. This areaportal splits the middle area of Badlands from the 2nd CP area by fitting between the forward spawn building and the skybox near-by.



Merging !- SUPER IMPORTANT -!

Merging is something important to note! If several areaportals are along the same plane AND share common edges then VBSP will merge them all into one areaportal regardless of distance.

merge-1.jpg


Here are two areaportals. They are both the same height and thickness and are both the same distance from the floor. If we look in game, and enable r_drawportals 1 we will see 1 gigantic green box extending between both areaportals.

merge-2.jpg


This means they have been merged into 1 single gigantic areaportal. Now merging isn't a problem unless you have 2 areaportals incredibly far apart that merge together thus rendering their purpose completely useless like in my experience. However stopping areaportals from merging is simple! Simply change the height, width, or thickness of the areaportal so it's different from the other areaportals along the same plane and it will prevent them from merging.

merge-3.jpg


So I would simply change areaportal 2 from a thickness of 16...

merge-4.jpg


...to 8 and...

merge-5.jpg


...voila. 2 seperate areaportals! :D


Conclusion

Hopefully you should have an understand of how areaportals work and where and when to use them. Hopefully. :p
 
Last edited:

gamemaster1996

L13: Stunning Member
Sep 30, 2009
1,064
134
Thanks i finally know how to do areportals without the compile getting in a strop.
Saving this page for offline view now :)
 

Nutomic

L11: Posh Member
Feb 7, 2009
888
177
Could you also give the commands you used there? Only one i recognize is mat_wireframe.
 

Terr

Cranky Coder
aa
Jul 31, 2009
1,590
410
IMO the real unsolved problem is determining when an areaportal is "worth it" from a performance standpoint.
 

Owlruler

L12: Fabulous Member
Dec 10, 2008
964
275
Thanks!
 

Rexy

The Kwisatz Haderach
aa
Dec 22, 2008
1,798
2,533
I didn't know that about the merging areaportals...that's extremely good to know.
 

Blue552

L3: Member
Sep 16, 2009
137
18
Nice tut - Guessing the pics where without vis. [off ones]

If someone could do a tutorial on how to use 'hint' properly that would be extremely helpful as well.
 

strangemodule

L5: Dapper Member
Sep 10, 2009
223
59
Good tutorial.

I have to ask though, is there ever a time you'd want to use the "door" method in a TF2 map? Because Valve just seems to use the "Always Open" method and that works out fine for them
 

grazr

Old Man Mutant Ninja Turtle
aa
Mar 4, 2008
5,441
3,814
IMO the real unsolved problem is determining when an areaportal is "worth it" from a performance standpoint.

Valve place it in pretty much every doorway and window. Make your assumptions from that.

Nice tut - Guessing the pics where without vis. [off ones]

If someone could do a tutorial on how to use 'hint' properly that would be extremely helpful as well.

Seriously, there are hundreds. Actually hundreds. Its basic function is to split visleafs to prevent rendition of items around corners, as rendering occurs from a visportal point of view, not the players FOV (like what is demonstrated here). So hints prevent visleafs from seeing around corners by limiting what is visible from the visleafs visportal's.

Good tutorial.

I have to ask though, is there ever a time you'd want to use the "door" method in a TF2 map? Because Valve just seems to use the "Always Open" method and that works out fine for them

Spawn doors.
 
Last edited:

Acumen

Annoyer
aa
Jun 11, 2009
704
628
since grazr brought up the vis-comparison...

i have a question for my better understanding. so this areaportal seems very smart, since it renders the seen parts indiviually and flexible, did i get this right ? from the oildrum example, if i move to the right it automatically renders only the left part of the drums ?

that'd be kinda fabulous and amazing :D
once again the mapper's world doesn't fail to impress me !
 

Psy

The Imp Queen
aa
Apr 9, 2008
1,706
1,491
Blue552 said:
Nice tut - Guessing the pics where without vis. [off ones]

No. VIS was run on full. Visleaf optimising is a very different beast.
 

JSTProductions

L1: Registered
Oct 15, 2009
31
10
i have a question for my better understanding. so this areaportal seems very smart, since it renders the seen parts indiviually and flexible, did i get this right ? from the oildrum example, if i move to the right it automatically renders only the left part of the drums ?

I think so, because otherwise the areaportals in badlands wouldn't work.

@Psy: You helped me alot,thanks mate :).