Difference between revisions of "Visleaf"
('Tis rather hard to read.)
|Line 1:||Line 1:|
Revision as of 12:00, 30 October 2005
This article needs to be cleaned up to conform to a higher standard of quality.
Visleafs, or just plain leafs, are sections in which your map is divided during the compiling process. Each leaf is a volume that contains a section of geometry that is drawn together. When any part of a leaf is visible from the current leaf, all of the geometry in the leaf is considered for rendering by the engine. You can view the current leaf in the engine by typing
mat_leafvis 1 at the developer console. A red wireframe box will be drawn showing the current leaf. As you move around in the level, the box will redraw each time a new leaf is entered. Another way of visualizing leaves is to use the
glview.exe command-line tool.
How are leafs created?
First, we'll take a look at an example level. We have a level with a few rooms in it:
This level is run through
vbsp.exe and it will divide the level into leafs. Each leaf starts, and ends at a plane where a brush begins. Like below:
Leafs, just like brushes, can't be concave. They can have any size (up to 1024 units, more on that later) and shape, as long as it's not concave. Notice how there are no entities in this room. I left them out to illustrate leafs are in no way affected by entities, not even brush-based entities, or displacements. That's exactly why tieing brushes to entities reduces visleafs: the less brushes in your level, the less leafs have to be made. If in our example all the middle walls wouldn't exist, we would only have one visleaf in our level.
Note: If your map has leaks,
vbsp.exe will not be able to divide your level into leafs. For more information, see leaks explained
vbsp.exe always cuts your level up at the green lines in the editor (and every 1024 units (= red/brown lines). You can choose to highlight these lines under [tools->options] tab 2d windows and select the highlight every...and enter 1024 units. If you look very carefull in the first pics, you can see a green line in the middle of the red leaf. So in reality, this red leaf can not exist and would have been cut in two. Not that that would have changed anything for our example though.
When your leaves are made,
vbsp.exe will write their data into a portalfile (mapname.prt).
Now, once our level is cut up into leafs,
vvis.exe will do it's job: It will read the portalfile made by
vbsp.exe into it's memory and it will try to figure out which leafs can see which ones. In our example,
vvis.exe would create a table like below:
- green can see blue and red
- blue can see green and red
- red can see all other leafs
- yellow can see purple and red
- purple can see yellow and red
vvis.exe can draw a straight line from one leaf to the other, the leafs are thought to see each other. This line can pass everything, apart from world-brushes.
All this data is stored into the mapfile, ready to be used by the game. Note that this process may take very long, if your map has a lot of leafs. Therefore, it's best to keep the amount of leafs as low as possible, yet still effective. One big leaf in your level would be low, but not effective: The entire map would be drawn at the same time.
So, what did we gain?
Well, you can see in the list above, that apart from the red leaf, all other leafs have been optimized: The engine will not render the entire game when the player is in those leafs.
If you ever want to cut up leafs at certain planes, be sure to read up on hinting. Careful planning on the placement of leafs can increase the speed of your map enormously, which is explained in detail in the aforementioned HINTs article.