Tools Texture Use: Part 4
Tutorial Quick Nav 1.0 - Brief Intro. 2.0 - Areaportals Effect 3.0 - Proper Uses 3.1 - Intro 3.2 - Valve Map Examples 4.0 - Getting Started 5.0 - General Areaportals 5.1 - Brief Situation Intro 5.2 - Sealing Your Entrances 5.3 - Leaks - They happen 6.0 - Areaportal Windows 6.1 - Brief Situation Intro 6.2 - Sealing Your Windows 7.0 - Final Words/Warnings
Brief IntroAreaportals are among the best and greatest of optimization techniques in source mapping, quite simply the strongest and most effective form of breaking your level into many different sub-levels that can be rendered individually with absolute control by yourself where and when this slicing will occur, hint brush's can do this same effect yes, but they are just that, hints for the engine to consider but it may not know the intention in which you placed it there. That is where areaportals come into use, no matter what they will be used as you set them, the engine cannot ignore anything done or set with your areaportals. That fact alone makes them useful in several different situations.
For those familiar with hint brush's and vis leafs and what they all are in both the compilation process and final bsp product of a map, much of this will be the same with a few new twists and options thrown in, Be warned, this is a very touchy tool to work with, if not handled correctly you will do more harm than good, at best a failed compile / leak, at worst...well, we won't go there just yet. Much like hint brush's and vis leaf effects areaportals are also a client sided effect, where each user will have a different view on whats rendered and whats hidden, so if one person enters an area and the rest of the areas are off to him, doesn't mean another player in another area will have their current spot turn off too. While the visual effect itself is client sided, the server still controls them. The I/O triggered open/close states of areaportals enabled on all clients, so a closed/open areaportal in this case will be the same to all users. So their use must be chosen carefully otherwise you could wind up in a situation where you have an areaportal brush close and remove a section of the map that shouldn't be removed in another persons perspective if you've placed it very poorly in the open. Thats why they must be used correctly to avoid these errors.
Its much easier to design levels with all your optimization in mind first rather than as an afterthought as you will find that brushwork you thought turned out so well then becomes your worst nightmare, now don’t get me wrong its still very possible to optimize levels after the fact, its just more time-consuming and tedious to do in most cases. Nothing wrong with making a section messy and fixing it up afterwords, just make sure you do go back and fix it.
While I do suggest that any mapper interested in getting the best performance out of their creations read this tutorial, I still however, encourage you to look over some other basic optimization tutorials on hint brush's / vis leaf editing or some of my previous tools textures to start getting a feel for how delicate some of these systems can be. Especially if this is going to be your first jump into proper optimization, don't want to bite off more than one can chew here as you will just end up destroying your level. So please browse through the tutorial section here and read and understand the simple vvis process and hint/skip work before trying these out.
Areaportals EffectThe effect that can be gained by areaportals themselves are among the best if not top tool in which to optimize any level. What the areaportal texture itself can do can be compared to that of the cordon tool some of you may have experience with in the past. That hammer tool comes in handy for level designers in the beginning stages of their maps when they want to see sections of a map built quickly without having to process the rest of the map. It “Cordons” off the area you want, the same with areaportals, they enclose each area you would like to be its own separate section of the map to be rendered on its own with no external parts of it visible/processed, excluding a 3d skybox of course. And just like the cordon tool the areaportal brush will become the texture of the skybox you have selected in correct scaling and placement. Keep that little note in mind at all times as you don’t want something to be hidden by your sky when it makes no sense to be if using triggered areaportals in an open section of the map.
In the screenshot provided you can see that there is nothing but a simple hallway with alternating colours on the floor, Now where the caution strip is in the screenshot, thats the area where we have placed our triggered areaportal to seal off that part of the level.
So we step into the area that triggers the areaportal to turn on and viola:
The level has been cut in half completely, no models, brushes, decals, overlays etc. That no longer exists in the level and doesn't have to be processed anymore. Now a player on each side only sees their respective half, objects, bullets, props etc can pass through areaportals and be effected by objects on the other side as if it was not there because areaportals are just a visual effect to help computer performance and not a solid wall, the server still knows where everything is and you can walk through an areaportal just fine, it will simply hide the other half of the room for you. Just note, bots and NPC's do not take closed or open areaportals into consideration on whether they can see you or not, server says that your in their line of sight they will shoot regardless of your view towards them being disabled by a closed areaportal or completely opaque areaportal_window. HL2 campaign has a few moments like that for those who notice them anyways :P
Open areaportals have a benefit as well, most think of an open areaportal as a disabled one from experience with other tools, such as the occluder. Where when they are on they block what they are meant to and when off they don't do a single thing. Well, for areaportals this is not true. Both in the open and closed states they perform a function. Multiplayer games have the best use of open areaportals with closed/toggled ones used only on doors. The reason behind open areaportals being the main use is due to the aforementioned error that you could wind up with with toggled ones used in situations they shouldn't be. When in the open state they don't block off everything from that and beyond it as with the closed state, but rather block what you don't see through the areaportal itself. Think of it as a filter, removing all the visleafs that are to all the other sides of it leaving on the leafs that you can see through the areaportal being the ones rendered. Now while you could potentially achieve the same effect with some hint/skip work, but why take all that extra work to make every possible angle on all entrances/exits when you would probably just make a huge mess of the visleafs anyways.
Heres a comparison of the normal rendering done with just basic visleafs and then below it one with an areaportal to filter your view.
*Any connected visleafs are rendered in the other room.
*Only visleafs within the perspective through the open areaportal are rendered.
So now you can understand just how much this single tool can improve your level designs in terms of performance and speed. You can manually specify what you want the player to be able to see, unlike normal hint brush’s which can have several if not all leafs visible if it sees fit, even if you do not think it will act that way, 90% of the time normal vvis fails at understanding just how your level should be broken up and what should be visible at what time. It happens, no system is perfect, so we have our tools to use to improve this. Lets get to it shall we?
IntroLike any tool in real-life and in hammer, they must be used only when it is appropriate in which to do so, Can't use a sledgehammer everywhere even though it would be fun now can we? So we're just going to go over what you should and shouldn't be doing with areaportal entities in your levels. Now I may be using some terms that you don't understand but I will try my best to explain some concepts, using dictionary definitions if I have to.
You should try to build maps with each combat area in mind beforehand with access between them via paths, ie for a DE style map, there are generally around 7 different areas that make up the map, 2 spawns, 2 bombsites, 2 staging areas for those sites and Mid of course. These are your main zones for players to fight against one another, so we should limit what they see and interact with to just this single zone so that they get the best performance out of their own computers. So areaportals come in to divide the map into their each respective sections resulting in these main areas. But they should ONLY be used to define these zones in such a way that you have not overly complicated the system in which it functions, overuse of areaportals in a small space can create worse performance for the clients computer than if you didn't have them at all. Its all about smart placement, not spammed.
Valve Map ExamplesCS_Militia
Every areaportal used on a door has a setting built in to select the door entity itself so it will control the areaportals current state by its actions, freeing you up from having to set up some I/O system with trigger brushes to enable/disable it on its own or to have the door send commands to the areaportal manually. This quick and simple setting is one that should almost always be used whenever possible. Less work in programming and more work on the actual creation of the level.
Now while this is a powerful tool and you probably still wonder why its not used everywhere, well, overuse in itself would just complicate things and lead to errors, so you see why areaportals were used only on the house itself and not the outdoor areas around it. Separating the map into the two basic areas, Indoor and Outdoor :P. This vmf is provided with source SDK by default and you will find it within your sdk's mapsrc folder. So if you want to look at it in more detail/understanding its there for you to fool around in.
As you can see on the screenshot on the left here, there is an areaportal to seal the warehouse as just mentioned, and also a rather odd thing one might think is that they also added one into the small shack thats just outside the back area of the warehouse. This is just yet another open areaportal for nothing more than filtering out the models and details inside the shack when from other angles and not directly looking inside it. Small performance boost for an area where snipers need their best to spot quick movement. So the use of it doesn't really drain that much from processing the removal of the models and geometry thats there. Small area in a rather bland place, no harm done.
The second areaportal in this room is just a normal always open areaportal as seen throughout the rest of the map. Its use here is simple, remove all the extra detail that they had thrown into the room, the TV, cabinets, chair, trash etc that could put a drain on a pc the second the double doors would open, giving the player a sort of stutter effect upon opening them where frames just drop at the sudden addition off all that. So again, the small addition of a single area to filter out these details allows you to give small rooms details that you probably couldn't do to it hampering the gameplay experience.
Now, because of how visleafs work, just by seeing out of them would make all connected visleafs within a rather large area begin to render. That would be bad, so using the open areaportals to filter out all unneeded leafs other than those from the players perspective and through the areaportals performance is increased drastically than if they were not there at all.
That brings the total separate areas within the warehouse to 4. The main warehouse floor, initial hostage room, back hostage room, and lastly the vent system just mentioned. No real need to add in anymore, say in the stairwell from main floor to catwalks because an occluder along that wall does well enough for performance and another areaportal there would be a bit wasteful on processing because of the current number in the area.
Theres CT spawn, the underpass area beside it, back corner of the train overpass and then the area surrounding the warehouse itself. The way that the two larger areaportal brushes are used in the screenshot to divide the level up is among their best uses. The optimization of outdoor detailed areas. Because its got some rather large and open spaces the visleafs as well would be fairly long and take up a lot of area as well, so when you see a part of it your computer would render everything within it, even if it went from one side of the map to the other that you cannot see. So the areaportal breaks this up and then limits the leafs that are seen as you go around the corner to those only needed at those points rather than the entire section at once.
The hostage room itself has been designated its own single area as already stated, both via the door with areaportal attached to it as well as the holes in the roof to seal the area. There isn't a lot of detail in the room, but there are hostages and some trash props etc. But since knowing and seeing whats inside doesn't matter till you either go into the room via the door or look through the top roof. Really wouldn't hurt performance if the visleaf inside was rendered when looking at the door but again, just little things to help even the worst of computers.
Now if you were wondering why they didn't use more than those just mentioned, and like assault it is an outdoor area, but unlike assault, it doesn't need areaportals to optimize the space. Compound only needed them in the few areas that had more detail than the rest of the map, there is little to no detail given to the outside playing field or the skybox details as there was in assault. it had complicated brushwork, textures and props all around as the buildings, walls, skybox details. Compound has very little of this so none were included.
Valve could have added in more areas to the map, but each room is relatively small anyways and doesn't cover a whole lot of ground, so vvis and hint/skip work does keep performance running smoothly in any case. The only large rooms are the hall from T spawn to bombsite and the T spawn itself, the first is rather narrow and basic brushwork with several models used, but still nothing too draining on resources, T spawn just has several larger models in use but little details elsewhere, that and it doesn't need any performance increase because it doesn't see any play during the game other than the initial start of a round.
Getting StartedFor the duration of explaining and showing how to go about creating/fixing/checking areaportals I will be using a relatively completed Map In Progress available for download from here, DE_Inner-City by . It has several good aspects to it that make it perfect, one, to show off how to seal areas and what needs to be done, and two, a good testing ground for you to do the same thing if you wish while or even after reading this tutorial. Don't be afraid to rate it while your there either, or complete the map itself for that matter. Section exists for that purpose.
Anyways, back on track. Here is an simple overview of the entire map. I've made different sections highlighted with various colours to show off how I would be breaking this level up into its different areas. You could do it even further to have all intersections separated but that could add up just too many areaportals to provide benefit.
These are some of the ones I'm going to be making during this tutorial, you may have chosen different groups/divisions and thats perfectly fine, I may even have missed some I could have done but for the moment just the basics will be fine for this tutorial and also has to do with that the map is not complete so sections are missing as a result :P
Brief Situation IntroFor those that haven't downloaded and taken a look at the map already, the completed sections of the map in terms of structure are the snipers nest on the upper left corner of the overview, the street and underpass below that, the offices and elevator building, the warehouse section and side entrances, and lastly the sewer system and the few roads connecting everything.
As the map is for the moment, as most new mappers do constantly and the experienced ones use only in initial creation and testing of maps, the entire level is inside one giant box. This is hell on vvis to process and then as a result, for us to create and use areaportals in. But it takes no time at all to redo the skybox and have it hug all the walls around the routes for the map so it can then be broken into its smaller chunks by ourselves.
Now thats a rather quick and dirty fix I've done as personally have no intention of finishing/polishing the map, just using it for the examples. But you can see the benefit from making the skybox conform to that of the level itself rather than resorting to the giant box method. So now that the level is in proper form to begin work, lets start with the most complete area of the level, The snipers nest.
Sealing Your Entrances
When you move around in the map the snipers nest has a total of three possible ways to see in and out of the building. The main door, upper sniper nest itself and then also farther down the side of the building is another opening onto the street. These all need to be sealed and set up with areaportals. Starting with the main entranceway, first going to start by adding in an actual door rather than leave it left wide open, just so a closed areaportal can be used in this case to help performance, the player doesn't need to be able to render the interior when looking at the door, just went they actually intend to go inside by opening it.
Most doorframes should be funcdetail, since they pop out from the wall obviously, rather than make more visleafs than needed they are set to funcdetail, these ones aren't so its a simple matter to do that right now. Once thats done the door itself thats set within the frame needs to have some settings done to it for the areaportal to be toggled by its open/closed states. First and only really required setting is we need to give it a name, keep names unique and simple if possible. Going to use just sn_d1 for the tutorial.
Theres just the 4 settings available for the standard areaportal: Name, Name of Linked Door, Initial State and Portal Version. Portal version never needs to be touched or changed as its something for valve when making new things, not really for public use. The only settings however we will be using for this particular areaportal is setting the linked door and its initial state. So using the name we chose in the first part we add that into its linked door setting, and also set its initial state to closed as the door starts closed naturally. Should end up with the same thing as seen in the image on the above right.
The destroyed hole in the wall on the second floor has the cut of brushes all around it set to funcdetail to help vvis. Always try to keep in mind that areaportals need to seal normal world geometry, funcdetails don't seal anything. So we're going to create another areaportal brush that fills in the entire space of the hole. Now because this isn't a doorway, the areaportal brush should just be left flush with the existing size of the wall its being used on. Areaportals can overlap both normal geometry and func_details. But its best to keep them as restricted as possible to the area they are needed in rather than needlessly extend their boundaries and effect where its not needed.
Now tie the brush to func_areaportal and check to make sure its initial state is set to open, not closed. Thats all that needs to be done, so for the moment should have something similar if not exactly like the image on the right.
Now unlike the previous destroyed section, this one isn't made out of func_detailed brushes, but displacements, which also don't get counted in the vvis process or seal the map from the void etc. So using the edges of the only world based brushes as the sides of our new areaportal we get one shaped as seen in the screenshot on the right. You can make that shape either with the cutting tool or just vertex manipulation to line them up.
Now that we've sealed this area on all possible ways in and out of the rooms, time to do a compile and see if its worked. Recommended for a BSP only compile, no vis or rad at this point as we only want to see if our area is as sealed as we think it is. If you get errors in console, skip down to the Leaks section and follow those guidelines.
Once thats done, attempt another BSP only compile, if there are no areaportal errors then you have just successfully created a working and functional area within the level. If your still getting them, follow the guidelines in the leak section. Once working, time to load it up and see how it all works in-game.
*Use of the r_drawportals console command to view portals in-game.
From the above screenshot you can see how the inside area no longer renders the outside geometry through the door, or how it filters out the visleafs when looking out either the sniper nest or street connection area to only those within the perspective of the player, increasing how much more resources we have to process all the details and perform smoothly in game with high frame counts.
Leaks - They HappenBecause the areaportal acts like a cordoning tool in-game, each area that you seal off with this entity can leak independently of each other, that’s not so good, but the reason why is pretty clear. Since each of these areas are now considered their own levels when active, if there is a way that it can get outside of itself in any way, then just like a normal map, it will leak and a compile will fail or cause other errors.
Now when loading the pointfile, you may be confused to see a red line going from inside your map to inside your map, that’s due to the areaportals again, you need to take a good look at the situation in which you used these entities and make sure that every entrance was sealed completely with the areaportal entity. When in doubt, just compile BSP only, then load the pointfile, seal the gap in the area as shown, repeat as many times as necessary.
There cannot be any gaps, just like a normal map that will allow something to get outside of these areas. Precision is something you will get used to. Now you might as well optimize the use of these areaportals as well, in some cases you can use a single brush based entity and stretch it to cover two separate entrances, ie if you had two corridors separated by a wall between that led to a central room, might as well just have one brush go across both entrance ways so you don’t waste another 4 brush’s when you don’t need too. Areaportals are allowed to be inside normal map geometry, just don’t go overboard as trying to fix any leaks afterwards with that work gets messy to the point of a brick going through your monitor. Try to keep the brushwork clean and easy to work with so optimization becomes easier to do.
If you have any funcdetail entities in your map in any large quantity, those also may be the cause of a leak, you cannot rely on them to seal something from the void that is the rest of your map, the whole point you tied them to funcdetail was so that they would not be normal geometry and would be ignored by the vvis process completely and speed up the compilation process. Double check your geometry in the area of the leak for any of these entities. Use the auto visgroups tab to toggle on and off this group for quicker analysis of the area. Most of the time this is the issue and its quickly fixed by moving it back to world and selecting the more fine brush detail on the group and only tying those to func_detail. Entire walls generally shouldn't be detail brushes, but only the tiny smaller ones on its surface that are not needed to block visibility in any way.
Brief Situation IntroFor the windows section of this tutorial I'm going to be using the Office space area of de_inner-city as it has several spots we are going to turn into portal windows as well as some outside of it as well.
The fact that they are almost transparent when close up doesn't help us at all, so we need to fix that as well. You could just edit the translucency limit properties and set it to 1, but theres also the fact that when far away when the areaportals are completely closed the room disappears and because the texture is transparent we see the skybox through the windows. This is where the two variant textures come into play for those that want to fix this somewhat unique problem.
Now the windows match perfectly with the rest of the building when seen from a distance and also they still look like normal windows when close up too. Best of both worlds. Quite a bit of work but makes all the difference in the world.
Sealing Your WindowsSlapping areaportalwindows just on any window won't work. You still need to seal the rest of the area just as you did with the general areaportals section of this tutorial. These are just an extension of them with more settings. Always use the cordon tool to do simple bsp only compiles of your newly created areas to test them for leaks, during this tutorial I encountered dozens just from missing geometry to funcdetailed objects.
Also, keep in mind that window frames, just like doors, tend to be sticking out or being sunk into the existing wall geometry and are most likely func_detail as well. Therefore the areaportal window needs to encompass those gaps to correctly seal the area. Easiest way to construct areaportals either in the general format or window format is to use the autovis groups and hide everything not needed, brush entities, point entities, detail entities etc and just leave only the bare structure of your map intact.
Final Words/WarningsWhile areaportals are very powerful and seem like can be used everywhere and will improve your map drastically, they also exact a certain cost to resources when there are more than one on the screen at a time, so while they are great to have in maps, limit them to where you need them rather than having them everywhere as the performance increase may be minimal at that point. If your not sure if your getting a performance boost out of an area then disable it and compile it without them, if it runs better/worse act accordingly.
A simple warning about water. If you have an areaportal thats cutting off a section of a water brush and crosses the surface from above to below, you need to split the areaportal brush into two separate areaportal entities that meet right at the surface of the water.
Now just to reiterate some general rules/properties for areaportals: