[Tutorial] Areaportals - All you need to know

Discussion in 'Tutorials & Resources' started by Psy, Nov 2, 2009.

  1. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,463
    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.

    [​IMG]

    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

    [​IMG]

    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!

    [​IMG]

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

    [​IMG]

    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. ;)

    [​IMG]

    And now let's turn it on again.

    [​IMG]

    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.

    [​IMG]
    [​IMG]
    [​IMG]
    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.



    [​IMG]
    [​IMG]
    [​IMG]
    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.



    [​IMG]
    [​IMG]
    [​IMG]
    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.

    [​IMG]

    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...

    [​IMG]

    ...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.

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

    [​IMG]
    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.

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]

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

    [​IMG]

    ...to 8 and...

    [​IMG]

    ...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
     
    • Thanks Thanks x 78
    • Like Like x 1
    Last edited: Nov 2, 2009
  2. Micnax

    aa Micnax L0: Terribly Lazy Mapper

    Messages:
    1,940
    Positive Ratings:
    1,203
    I love you. Permanently. Forever.
     
  3. Ravidge

    aa Ravidge Grand Vizier

    Messages:
    1,543
    Positive Ratings:
    2,485
    • Thanks Thanks x 2
  4. gamemaster1996

    gamemaster1996 L13: Stunning Member

    Messages:
    1,065
    Positive Ratings:
    131
    Thanks i finally know how to do areportals without the compile getting in a strop.
    Saving this page for offline view now :)
     
  5. Nutomic

    Nutomic L11: Posh Member

    Messages:
    888
    Positive Ratings:
    177
    Could you also give the commands you used there? Only one i recognize is mat_wireframe.
     
  6. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,463
    All I used were r_DrawPortals and mat_wireframe.
     
    • Thanks Thanks x 2
  7. Terr

    aa Terr Cranky Coder

    Messages:
    1,591
    Positive Ratings:
    405
    IMO the real unsolved problem is determining when an areaportal is "worth it" from a performance standpoint.
     
  8. martijntje

    martijntje L8: Fancy Shmancy Member

    Messages:
    539
    Positive Ratings:
    168
    I'm realizing I dont have any areaportals in my map. I do have to do that.

    Nice tutorial, I didn't know that about the merging of areaportals
     
  9. Owlruler

    Owlruler L12: Fabulous Member

    Messages:
    964
    Positive Ratings:
    271
    Thanks!
     
  10. littleedge

    aa littleedge L1111: Clipping Guru

    Messages:
    983
    Positive Ratings:
    573
    So any mirrored map, like Panic, is going to experience that merging area portal thing? Good to know. Expect me to forget, though.
     
  11. Rexy

    aa Rexy The Kwisatz Haderach

    Messages:
    1,795
    Positive Ratings:
    2,355
    I didn't know that about the merging areaportals...that's extremely good to know.
     
    • Thanks Thanks x 1
  12. The Political Gamer

    aa The Political Gamer

    Messages:
    4,468
    Positive Ratings:
    1,680
    Sir you just got my 2,000th thank. :thumbup1:
     
    • Thanks Thanks x 3
  13. eerieone

    aa eerieone

    Messages:
    1,009
    Positive Ratings:
    569
    nice :D

    some x-tra info:

    one tricky thing is pulling areaportals through water, you´ll see a cut
    the solution is to cut the areaportal in two right at waterlevel
     
    • Thanks Thanks x 1
  14. Blue552

    Blue552 L3: Member

    Messages:
    137
    Positive Ratings:
    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.
     
    • Thanks Thanks x 1
  15. strangemodule

    strangemodule L5: Dapper Member

    Messages:
    223
    Positive Ratings:
    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
     
    • Thanks Thanks x 1
  16. grazr

    aa grazr Old Man Mutant Ninja Turtle

    Messages:
    5,433
    Positive Ratings:
    3,546
    Valve place it in pretty much every doorway and window. Make your assumptions from that.

    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.

    Spawn doors.
     
    Last edited: Nov 2, 2009
  17. Inqwel

    Inqwel L6: Sharp Member

    Messages:
    308
    Positive Ratings:
    57
    This. Is. Perfect.
     
    • Thanks Thanks x 1
  18. Acumen

    aa Acumen Annoyer

    Messages:
    704
    Positive Ratings:
    593
    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 !
     
  19. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,463
    No. VIS was run on full. Visleaf optimising is a very different beast.
     
  20. JSTProductions

    JSTProductions L1: Registered

    Messages:
    31
    Positive Ratings:
    10
    I think so, because otherwise the areaportals in badlands wouldn't work.

    @Psy: You helped me alot,thanks mate :).
     
    • Thanks Thanks x 1