Visleaf: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (hint brushes -> hint brush, codetags)
(Rewrite Template:Lang to Template:LanguageBar. This action was performed by a bot.)
 
(41 intermediate revisions by 24 users not shown)
Line 1: Line 1:
'''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 <code>mat_leafvis 1</code> 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]] (<code>glview.exe</code>) command-line tool.
{{LanguageBar|Visleaf}}
[[File:Opt_pvs_blank.jpg|thumb|A sample scene with two rooms.]]


=How are leafs created?=
[[File:Opt_pvs_good.jpg|thumb|The default visleaf structure for the above scene. Note how leaf 2 cannot see leaf 3.]]


First, we'll take a look at an example level. We have a level with a few rooms in it:
{{Distinguish|VisGroup}}


[[Image:Room1.JPG | an example map]]
Each '''visleaf''' (sometimes referred to simply as a '''leaf''') is a hollow volume in a map which defines a 'cluster' of visible surfaces. Every visible surface of a map is part of one visleaf or another. visleaves are used primarily by the ''Rendering Engine'' to determine (before rendering each frame) which areas of the map might need to be rendered on screen. When ''any part'' of a visleaf is [[PVS|potentially visible]] from ''any part'' of the current visleaf, the entire contents of that visleaf are considered for rendering.


This level is run through [[vbsp|VBSP]] (<code>vbsp.exe</code>) and it will divide the level into leafs. Each leaf starts, and ends at a plane where a brush begins. Like below:
Visleaves are generated automatically from the [[BSP|BSP tree]] by the [[vvis|VVIS]] compile tool. Each (internal) surface of a visleaf is either a [[World brush]] surface or a ''Portal'' to an adjacent visleaf.  


[[Image:Room2.JPG | another example map]]
== Examination ==


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.
There are three ways to inspect visleaves:
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 [[displacement]]s. 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 will not be able to divide your level into leafs. For more information, see [[leak]].}}
* From Hammer Editor since [[Orange Box (engine branch)|Orange Box]] (Source 2007 and later), the leaves of the current map can be viewed directly in the 3D view through the menu option ''Map > Load Portal File''. This displays leaf edges that touch other edges as thick blue lines.
*{{Note|VBSP always cuts your level up along the center lines (as shown by the two green lines in the editor) and every 1024 units (as shown by red-brown lines). If you look very careful in the first pics, you can see a green center line cutting through the middle of the red leaf, so in reality this leaf would be cut in two, not that that would have changed anything for our example though.}}


When your leaves are made, VBSP will write their data into a portalfile (<code>mapname.prt</code>).
* From the desktop, the [[glview]] tool application (located in the ''common\[game]\bin'' folder) can be used.


Now, once our map is cut up into leafs, [[vvis|VVis]] (<code>vvis.exe</code>) will do it's job: It will read the portalfile made by VBSP into it's memory and it will try to figure out which leafs can see which ones. In our example, VVis would create a table like below:
{{tip|For even more clarity use auto [[visgroup]]s to remove objects from your map that don't block visibility – i.e. everything but "World Geometry".}}


# green can see blue and red
* From the [[Developer Console]], the [[console variable]] [[mat leafvis]] can be used. (<code>mat_leafvis 3</code> will display all visleaves in the [[PVS]].)
# blue can see green and red
# red can see all other leafs
# yellow can see purple and red
# purple can see yellow and red


If VVis 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.
{{note|Do not confuse visleaves with the squares outlining worldbrush geography seen if you use <code>[[mat_wireframe]] 3</code>.}}
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 using hint brushes. Careful planning on the placement of leafs can increase the speed of your map enormously, which is explained in detail in the [[Hint brush]] article.
* From 3ds Max using {{wallwormmtools|4}}, the leaves of the current map can be viewed directly in the 3D view through the menu option ''Wall Worm > Wall Worm Level Design > Wall Worm Map Compile Tools > Load PRT File''. This displays leaf edges that touch other edges as thick yellow lines. You can select a line (portal) that will allow you to select or flash the leaves on either side. You can also find more portal and leaf options in the ''Go To Brush'' floater.
 
== See also ==
 
*[[PVS]] (Potentially Visible Set): the 'cluster' of visleaves that are currently being drawn
*[[PAS]] (Potentially Audible Set): as above, but for sound
*[[Visibility optimization]]
**[[Leaks]] are gaps in the BSP geometry that prevent leaf generation
** [[Hint brush]]es tell the compiler to split leaves
*Visleaf generation:
** [[vvis|VVIS]] compiler.
** [https://web.archive.org/web/20150527052701/http://rvanhoorn.ruhosting.nl:80/optimization.php?chapter=visleafs Ralph van Hoorn's explanation of visleaves].
* [[Optimization (level design)]]


[[Category:Level Design]]
[[Category:Level Design]]
[[Category:Glossary]]
[[Category:Glossary]]

Latest revision as of 17:42, 18 July 2025

English (en)Deutsch (de)Русский (ru)中文 (zh)Translate (Translate)
A sample scene with two rooms.
The default visleaf structure for the above scene. Note how leaf 2 cannot see leaf 3.
Not to be confused with VisGroup.

Each visleaf (sometimes referred to simply as a leaf) is a hollow volume in a map which defines a 'cluster' of visible surfaces. Every visible surface of a map is part of one visleaf or another. visleaves are used primarily by the Rendering Engine to determine (before rendering each frame) which areas of the map might need to be rendered on screen. When any part of a visleaf is potentially visible from any part of the current visleaf, the entire contents of that visleaf are considered for rendering.

Visleaves are generated automatically from the BSP tree by the VVIS compile tool. Each (internal) surface of a visleaf is either a World brush surface or a Portal to an adjacent visleaf.

Examination

There are three ways to inspect visleaves:

  • From Hammer Editor since Orange Box (Source 2007 and later), the leaves of the current map can be viewed directly in the 3D view through the menu option Map > Load Portal File. This displays leaf edges that touch other edges as thick blue lines.
  • From the desktop, the glview tool application (located in the common\[game]\bin folder) can be used.
Tip.pngTip:For even more clarity use auto visgroups to remove objects from your map that don't block visibility – i.e. everything but "World Geometry".
Note.pngNote:Do not confuse visleaves with the squares outlining worldbrush geography seen if you use mat_wireframe 3.
  • From 3ds Max using Wall Worm Model Tools Wall Worm Model Tools, the leaves of the current map can be viewed directly in the 3D view through the menu option Wall Worm > Wall Worm Level Design > Wall Worm Map Compile Tools > Load PRT File. This displays leaf edges that touch other edges as thick yellow lines. You can select a line (portal) that will allow you to select or flash the leaves on either side. You can also find more portal and leaf options in the Go To Brush floater.

See also