Half-Life 2 Map Editing Optimization Guide

Hints


The way your level is cut up into visleafs affects the speed of the map a lot. Let's look back at the example from the previous chapter.

A level divided into visleafs

What if the level was cut up not like above, but like below?

Example: a level divided badly into visleafs

In this case, the visleaf the player is in ( blue ) can see all other leafs in the level. Thus, the entire level will be drawn when the player is standing here, as opposed to the situation above where the top visleaf would be hidden. This shows how the shape of visleafs can affect the framerate of your map, even when the brushwork in the map is completely the same!

There must be a way to control how your level is divided into visleafs, after all that's the purpose of this chapter. Hinting is a way to tell the compile-programs where YOU think THEY should cut visleafs. Offcourse they still cut up visleafs where they think it's needed, but they will always cut up visleafs where you say they should (they are very obedient dogs, arf). Making Hints is quite easy. All you have to know is that visleafs are cut whereever the "tools/toolshint"-texture is placed. This brush MUST have the "tools/toolsskip"-texture on all sides which aren't used for hinting. Therefore, hint-brushes can only have two textures: the hint and the skip texture. No more.

In our case we can either make brush A or B:

Making a HINT-brush

Where lightblue and brown are the brush-sides with the tools/toolsskip texture, and the blue line is the brush-side with the "tools/toolshint"-texture. Whether you make brush A or B, or a brush one hundred times as big doesn't matter, as long as the side with the "tools/toolshint"-texture is at the blue line we get our effect:

Visleafs changed due to HINT-brush

Not only does the visleaf span two rooms, we also optimised the map by making less visleafs! Because the compile programs found that the left room was already square, they did not see a reason to cut it up into multiple visleafs. Creating a hint-brush on the entrace of the other room would decrease the map by another two visleafs! Not much, but if you do this everywhere in your map, you are bound to get a faster compiling map. You can also take a look at the example map made by Valve in: "sourcesdk_content\hl2\mapsrc\sdk_hints.vmf" for more information on how to make these hint-brushes.

Hint brushes can be used to make sure certain visleafs don't see each other, but also to reduce visleafs

Most of the time vbsp ( the program that cuts up the map into visleafs ) makes the visleafs in a logical way, but not always. Doorways and windows are bound to cut up the room into visleafs:

A doorway cutting up adjacent visleafs

Sometimes this WILL improve mapspeed, eg when there is some heavy brushwork on the other side of the wall and the player isn't looking straight at the doorway, but in most cases it is just useless. So it's best to fit a hint-brush inside the doorway, OR make the entire wall (if possible) an entity. Offcourse you must remember when placing hints to make sure you don't create more visleafs than you need. Make sure your hints are as flush with the walls as possible, fit tightly (NO GAPS) and as straight as possible. If I ever catch you making a hint-brush out of a cylinder I swear I an going to kill you.

Ok, you now know what hints do, and you should know what to do with them: making sure certain visleafs don't see each other. But you don't know how? Hinting isn't the easiest thing in the world, hinting requires every braincell in your body (including the ones in your arse, haha). I will show you some examples on how and where to use hinting, but don't expect to become an expert right away. Hinting will mostly be trial-and-error, especially in the beginning. Play the map, find an area that isn't running smoothly, find out what causes it, place a hint-brush to stop the cause, compile again, play again, repeat. Finding out what the cause of the lag will be discussed in the checking progress chapter.

The essence of hinting is to make sure visleafs can't see around corners, over or under walls or buildings, or through openings in walls (eg doorways, windows).

1) not seeing around the corner

When dealing with corners, you have to imagine this example:

Hints at corners

In the current location, the player will not be able to see whatever is around the corner. However, it will still get rendered, as this image will show you:

Things around the corner being rendered

Because the visleaf the player is in (no 1) is able to see visleaf 2 (they touch each other) everything in the hallway around the corner will be rendered. To stop this, we need to make sure no straight line can be drawn from visleaf 1 to visleaf 2

Diagonal HINT in a corner

I made a diagonal hint-brush in the corner, touching the inner corner of this hallway. By doing so I did have to make an extra visleaf, but this one is for the better: when the player is in visleaf 1, only visleaf 1 and 3 will be drawn. Visleaf 2 will be invisible to visleaf 1, thus it won't be rendered at all. The player will be able to see everything when he is in visleaf 3 though, so no visleafs will be hidden in that case (in this example).

The angle of the diagonal HINT-brush doesn't matter. As long as it is one brush, both outer visleafs can't see each other. The shape of the hint-brush is equal to visleaf 3 (with only the diagonal side with the HINT-texture), but offcourse its perfectly legal to drag the bottom-right corner more to the middle so you can navigate easier through your level in the editor:

A smaller HINT-brush

You should be able to know why:

Bad usage of HINTS at corners

Corner < 180 degrees
Visleafs 1 and 3 see each other, a straight line can be drawn between them
Corner > 180 degrees
Visleafs 1 and 3 can't see each other, no straight line can be drawn between them, but the effect is less than above because visleaf 3 is bigger (and split)
Hint brush goes through the corner
This causes the same as the situation in the middle, only much worse!

this is how hints look like in Hammer
A HINT-brush in Hammer

2) Not seeing over or under walls/buildings/other objects

Normally players can't see through walls, so you also don't want the game to render what is on the other side of a wall. Usually this isn't done anyway, but occasionally it might. If that is the case, remember Weebl and Bob!

Weebl and Bob setup

Weebl and Bob are two eggs ( Their site ) but also players in this mini-level. This mini-level features walls, a ceiling, a floor and ugly pipes. Luckily the mapper put a wall between Weeble, Bob and the pipes so Weeble and Bob don't have to see the pipes. Even though that's nice and all, Weeble and Bob still have those ugly pipes rendered. The reason? Vbsp did a pis-poor job in dividing this level into visleafs:

Vbsp tried to make this map render better, but failed.

See? The visleaf Weeble and Bob are in (red) can see the visleaf with the pipes (blue). That's therrible? What will we do?

The solution is to place a horizontal hint-brush at the top of the wall, like so:

A horizontal hint atop of the wall

The selected brush is a hint-brush, with the bottom brush-side covered in HINT-texture. Because of this hint-brush, the new visleafs would look like this:

The new division of visleafs of our level

In this case, Weeble and Bob's visleaf can't see the visleaf with the pipes, so no pipes are drawn! Weeble and Bob are happy now. They wont be happy if they jumped or climb too high though: If they would do that, they would get into the green visleaf, which can see the blue visleaf with the pipes. So we must make sure they can't climb or jump that high, OR make the wall higher, or simply don't care if Weeble or Bob can see the pipes.

The same thing applies to houses in a village for instance. If your map has buildings which don't reach to the top of the skybox, add a horizontal HINT-brush at the top of the houses ( try to find the lowest possible height, where no player will be able to get up to ) to make sure nothing is rendered at the other side of the houses because the visleaf the player was in could see over the houses. Alternatively, make the skybox lower and put the top parts of the buildings in your town in a 3d skybox.

3) Not seeing through openings in a wall

Offcourse you want the player to be able to look through holes in a wall, but what if the player isn't standing right in front of the doorway or window?

doorway hinting-setup

If the player (the green box) would stand here he would only see the bottom four very_hard_to_render_entity's, but all eight of them would be rendered! That's eight very_hard_to_render_entity's! we could solve this situation similar to Weeble and Bob's wall:

doorway hinting-horizontal hints

Which would be ideal if these eight entities is all that is hard to render. But imagine this room being racked to the roof with these entities:

doorway hinting-horizontal hints

Not very ideal: still 23 entities will be drawn, about 1/3rd of the total. Isn't there an alternative? Offcourse there is! Don't you see this doorway is nothing more than the corner from the beginning?

doorway hinting-oblique hints

This seems far better, but think about this: If the player is just a teensy weensy more to the top, only three entities will be visible. However, if the player would move a teensy weensy more to the bottom, all entities would be rendered! What we need to do here is choose an angle where it is affordable to have more entities drawn. The more horizontal this hint-brush is, the less will be hidden from the player, but the bigger the space is where the player must be for this hiding to happen. The more the hint-brush is vertical, the more entities are hidden, but the smaller the area is where that will happen. Confused? You should ( NOT ) be. Look at the two pictures above and you will see what I mean. The hint-brush in the  bottom situation is near-useless, as the entities will only be hidden in a very small corner. However, if we could make the hint brush reach past an entrance of somekind, we would be hiding these entities for a larger area, as can be seen below:

doorway hinting-think ahead

Now for everyone being in the same visleaf as the player is here, or on the other side of the entrance at the top left, only four entities would be rendered. If this hint-brush would have been like it was in the previous situation, any player on the other side of this entrance would likely see a lot more entities rendered.

Hinting requires you to think miles ahead. Don't just try to hide one room from another. Try to hide them the most optimally. Try to hide roomS from other roomS. Think about what area's are the most intense (most players, most action, most monsters, most brushwork, most entities, HDR intensive, etc) and try to optimize those parts the most. For those area's, it might pay off to hide every small nook you can possibly hide. For other area's this isn't needed at all.

Carefull planning helps you a lot in optimizing as well. If you have a very calm/easy to render area between two very intensive area's you can make sure the player never has to draw both intensive area's at the same time. Compare the next two situations, the first is completely unoptimizationable (nice word for Scrabble), the second will actually be very easy to optimize:

room hinting-adding a hallway inbetween

As you can see, with the white line being a HINT-brush, there is no place in this bottom level where more than 40 entities are visible. When the player is in the left room, or in the middle hallway below the hint brush, only the left entities will be drawn. If the player is in the right room, or above the hint brush in the middle hallway, only the right entities will be drawn. Compare that to the top situation, and you will know which situation is best fps-wise. Offcourse, you must remember: Does this new hallway fit the theme? If it doesn't, be creative :P

I could make up examples all year long, but I got better things to do. Remember the lessons you have learned so far, remember the ones you are still going to get, and experiment with them. You know how it works, so get that useless grey matter in your head working! A usefull tip is to open up paint (or any other paint program) and start drawing lines on an overview screenshot from Hammer and Glview. Find out how your visleafs are made, and for all i care you start drawing lines in paint to see why that one visleafs draws that other visleaf when you dont want it to, and how you can fix it. Like all images above, they can help you determining where your HINT-brushes go best. Also remember the 3rd dimension! All these images are just 2d, but along with the extra dimension comes a complete new level of mathematics. I hope you are up for the task, I am not going to do it for you. Never. Ever. Now shoo to the next chapter.


«- Previous Chapter Next Chapter -»

© Webdesign Copyright by Kolezan, contents Copyright by Ralph 'zombie@computer' van Hoorn