This article's documentation is for the "GoldSrc" engine. Click here for more information.
This article's documentation is for anything that uses the Source engine. Click here for more information.

VIS optimization: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
 
(22 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{otherlang2
{{LanguageBar|title = Visibility optimization}}
|es=visibility_optimization:es
{{gldsrc topicon}} {{Source topicon}} [[Category:Hammer]] [[Category:Level_Design]]
|ru=visibility_optimization:ru}}
{{subpage|[[Optimization/Level_Design|Optimization (level design)]]}}
{{TabsBar|main=Visibility}}
{{cleanup|This article originally exclusively covered {{src|2}}, but {{gldsrc|2}} info has been added, as most of the same concepts apply. Nonetheless, much of the Source-only stuff is not properly marked as such, and the optimization features provided by [[ZHLT]] and the now-standard [[VHLT]] are not mentioned.}}
Without [[VIS]], everything in a map is drawn all the time regardless of whether or not the player can see it, which would reduce the game performance (and framerate). Clearly the list of objects to be rendered must be trimmed, but how? It would take far longer to test whether each object or surface could actually be seen than it would to render them in the first place!


Without "visibility", everything in a map is drawn all the time regardless of whether or not the player can see it. Clearly the list of objects to be rendered must be trimmed, but how? It would take far longer to test whether each object or surface could ''actually'' be seen than it would to render them in the first place!
Game engines have to make a compromise; {{gldsrc|2}} and {{Source|2}} both use the [[Binary Space Partition]] model, based on {{Wikipedia|John Carmack|John Carmack's}} implementation in {{quake|2}}. This page explains how it works and how to manipulate it.
 
Game engines have to make a compromise; Source's is the [[Binary Space Partition]] model, based on [[Wikipedia:John D. Carmack|John Carmack]]'s implementation in [[Wikipedia:Quake_(video_game)|Quake]]. This page explains how it works and how to manipulate it.


==Leaves==
==Leaves==
[[File:Visleaves.png|frame|left|Visleaves in a corridor.]]
[[File:Visleaves.png|frame|left|Visleaves in a corridor.]]


The interior (i.e. not occupied by a [[world brush]]) space of a BSP map is split into [[Visleaf|visleaves]]. Visibility between these 3D volumes is calculated when the map is compiled, and embedded into the map file for use by the engine. Like brushes, leaves are always convex.
The interior (i.e., not occupied by a [[world brush]]) space of a BSP map is split into [[Visleaf|visleaves]]. Visibility between these 3D volumes is calculated when the map is compiled, and embedded into the map file for use by the engine. Like brushes, leaves are always convex.


The image to the left shows how leaves might be created in u-turn corridors (gaps between them have been added for clarity). There is no line of sight between leaf 1 and 3, and therefore when the camera is in one the contents of the other are not drawn. Calculating this is as simple for the engine as glancing at the map's embedded visibility chart.
The image to the left shows how leaves might be created in u-turn corridors (gaps between them have been added for clarity). There is no line of sight between leaf 1 and 3, and therefore when the camera is in one the contents of the other are not drawn. Calculating this is as simple for the engine as glancing at the map's embedded visibility chart.
Line 17: Line 17:
But there is a problem with leaf 2. The contents of ''all three'' leaves are drawn when the camera is within it, [[:File:Frustum culling.png|frustum culling]] aside, even if the left-hand wall completely fills its view. There are tools to overcome this that we'll look at shortly,  but keep in mind that in a lot of cases fixing the problem will be more [[expensive]] than simply drawing the less-than-optimal scene.
But there is a problem with leaf 2. The contents of ''all three'' leaves are drawn when the camera is within it, [[:File:Frustum culling.png|frustum culling]] aside, even if the left-hand wall completely fills its view. There are tools to overcome this that we'll look at shortly,  but keep in mind that in a lot of cases fixing the problem will be more [[expensive]] than simply drawing the less-than-optimal scene.


Bear in mind at all times that [[displacement]]s, [[Point entity|point]] and [[Brush entity|brush]] entities (including [[#Detail_brushes|detail brushes]]) don't affect leaves. Create [[nodraw]] [[world brush]] 'foundations' if this is a problem: it's quite common for displacements to be created as detailed 'skin' on top of a world brush skeleton, for example.
Bear in mind at all times that [[displacement]]s, [[Point entity|point]] and [[Brush entity|brush]] entities (including [[#Detail_brushes|detail brushes]]) don't affect leaves. Create [[nodraw]] [[world brush]] "foundations" if this is a problem: it's quite common for displacements to be created as detailed 'skin' on top of a world brush skeleton, for example.
{{note|World brushes with [[$translucent]] textures '''do''' cut [[visleaves]].}}
{{note|World brushes with {{ent|$translucent}} textures ''do'' cut [[visleaves]].}}
 
{{warning|Leaves cannot be created if your map has a [[leak]].}}
{{warning|Leaves cannot be created if your map has a [[leak]].}}
{{tip|Leaves are split every 1024 [[unit]]s along the xy-plane regardless of brush geometry in order to break large areas down. Hammer's grid is highlighted to help you accommodate this.}}
{{tip|Leaves are split every 1024 [[unit]]s along the xy-plane regardless of brush geometry in order to break large areas down. Hammer's grid is highlighted to help you accommodate this.}}
{{note|Leaves work vertically as well as horizontally. Treat skies as extensions of the streets and rooms beneath them.}}
{{note|Leaves work vertically as well as horizontally. Treat skies as extensions of the streets and rooms beneath them.}}


===Reducing VIS compile time===
===Reducing VIS Compile Time===
 
[[VVIS]] (or [[VIS]]/[[HLVIS]] in {{gldsrc}}) the tool that calculates visibility between leaves (whereas [[VBSP]] (or [[QBSP2]]/[[HLBSP]] creates them). It shouldn't take more than a few minutes to finish work on even the most complex maps, and if it does, chances are you need to do some of the following. Even if it doesn't, they're good practice!
[[VVIS]] is the tool that calculates visibility between leaves (whereas [[VBSP]] creates them). It shouldn't take more than a few minutes to finish work on even the most complex maps, and if it does the chances are you need to do some of the following. Even if it doesn't they're good practice!


* Use [[#Detail_brushes|detail brushes]] appropriately.
* Use [[#Detail_brushes|detail brushes]] appropriately.
* Keep [[world brush]]es on the grid as much as you can. Dimensions in the power of two are good.
* Keep [[world brush]]es on the grid as much as you can. Dimensions in the power of two are good.
* Use simple world brushes that have not been manipulated via other tools excessively, such as carve or vertex manipulation
* Use simple world brushes that have not been manipulated via other tools excessively, such as carve or vertex manipulation
* Place {{EP2 add|[[func_viscluster]]}} in large areas with unbroken visibility. Leaves within it will be assumed able to see each other.
* Place {{Ent|func_viscluster}}{{hl2ep2|since}} in large areas with unbroken visibility. Leaves within it will be assumed able to see each other.
* Avoid creating large open areas that the player won't see or interact with in the first place, if it's reasonable to do so. Use a [[3D Skybox]] to reduce sky size, and create a world brush skeleton beneath [[displacement]]s.
* Avoid creating large open areas that the player won't see or interact with in the first place, if it's reasonable to do so. Use a [[3D Skybox]] to reduce sky size, and create a world brush skeleton beneath [[displacement]]s.


Remember that VIS compile time and in-game performance are two very different things. It may well be worth bearing a long compile if shortening it compromises your result.
Remember that VIS compile time and in-game performance are two very different things. It may well be worth bearing a long compile if shortening it compromises your result.


===Inspecting leaves===
===Inspecting Leaves===
Since {{src07|4}}, Hammer has a new function to view the current map's leaves in the 3D view: ''Map > Load Portal File''. This displays leaf edges that touch other edges as thick blue lines. It's a fantastic learning tool, as if you compile your map without VIS or RAD (then reload its portal file to refresh the display), you can see your changes' effects very quickly.


The [[Orange Box]] version of Hammer has a new function to view the current map's leaves in the 3D view: ''Map > Load Portal File''. This displays leaf edges that touch other edges as thick blue lines. It's a fantastic learning tool, as if you compile your map without VIS or RAD (then reload its portal file to refresh the display) you can see your changes' effects very quickly.
{{Src06|4}} users and earlier must rely on the [[glview]] application.
{{tip|For even more clarity, use auto [[visgroup]]s to remove objects from your map that don't block visibility—generally everything but "World Geometry," plus "Tool Brushes," "Water," and "Displacements."}}


[[Source 2006]] users must rely on the [[glview]] application.
For in-game inspections, there is a [[console variable]] called "{{ent|mat_leafvis}}". <code>mat_leafvis 3</code> will outline all the visleaves in the [[PVS]], while <code>mat_leafvis 1</code> will just outline the leaf that the camera is currently in. (This variable is a [[sv_cheats|cheat]].)


{{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".}}
You can also inspect the geometry itself through using the {{ent|mat_wireframe}} console variable. <code>mat_wireframe 1</code> will display how polygons are drawn in the current [[PVS]]. (This variable is a [[sv_cheats|cheat]] as well.)
 
For in-game inspections, there is a [[console variable]] called "[[mat_leafvis]]". <code>mat_leafvis 3</code> will outline all the visleaves in the [[PVS]], while <code>mat_leafvis 1</code> will just outline the leaf that the camera is currently in. (This variable is a [[sv_cheats|cheat]].)
 
You can also inspect the geometry itself through using the [[mat_wireframe]] console variable. <code>mat_wireframe 1</code> will display how polygons are drawn in the current [[PVS]]. (This variable is a [[sv_cheats|cheat]] as well.)


==Hints==
==Hints==
 
{{Main|Hint brush}}
[[File:Toolshint.gif|right|link=Hint brush|tools\toolshint]]
[[File:Toolshint.gif|right|link=Hint brush|tools\toolshint]]
[[File:Visleaves-hint.png|frame|left|All leaves draw at the same time until we hint.]]
[[File:Visleaves-hint.png|frame|left|All leaves draw at the same time until we hint.]]


Unfortunately, leaves don't always work out so well as they did in our first example. Consider the alternative layout on the left (in practice things would be configured as per the first image, but put that aside for a moment): in this example the leaves can all see each other, leading to the whole area being drawn at once for no good reason. This is where '''''[[Hint brush|Hints]]''''' come in.
Unfortunately, leaves don't always work out so well as they did in our first example. Consider the alternative layout on the left (in practice things would be configured as per the first image, but put that aside for a moment): in this example the leaves can all see each other, leading to the whole area being drawn at once for no good reason. This is where '''Hints''' come in.


A hint is a brush face [[Applying Materials|textured]] with the special <code>tools\toolshint</code> material, which slices any leaves it intersects in two (faces of the brush that should ''not'' split leaves must be textured with <code>tools\toolsskip</code>). In our example, we would place a hint where the purple line indicates, so that it slices leaves 1 and 3 to the same shape that they were in our first example.
A hint is a brush face [[Applying Materials|textured]] with the special <code>tools\toolshint</code> material, which slices any leaves it intersects in two (faces of the brush that should ''not'' split leaves must be textured with <code>tools\toolsskip</code>). In our example, we would place a hint where the purple line indicates, so that it slices leaves 1 and 3 to the same shape that they were in our first example.
Line 63: Line 57:
{{tip|It's a good idea to use hints to separate [[expensive]] and [[cheap]] areas of the same leaf, if doing so will reduce the amount of time that the expensive areas are drawn for.}}
{{tip|It's a good idea to use hints to separate [[expensive]] and [[cheap]] areas of the same leaf, if doing so will reduce the amount of time that the expensive areas are drawn for.}}


==Detail brushes==
==Detail Brushes==
As was mentioned above, leaves are molded around world brushes. But what if you ''don't'' want a brush to do that? If you have a brush that can be seen around at all times (e.g., a statue plinth, or a small free-standing wall), there’s no point in creating lots of extra leaves around it.


As was mentioned above, leaves are moulded around world brushes. But what if you ''don't'' want a brush to do that? If you have a brush that can be seen around at all times (e.g. a statue plinth, a small free-standing wall) there’s no point in creating lots of extra leaves around it.
In these situations you want '''{{ent|func_detail}}'''. It's an [[internal entity]] which makes the compilers ignore the brush when calculating visibility, without otherwise affecting its behaviour. [[func_detail#Good_candidates|It's not uncommon for large portions of a map's brushes to be detail]].


In these situations you want '''''[[func_detail]]'''''. It's an [[internal entity]] which makes the compilers ignore the brush when calculating visibility, without otherwise affecting its behaviour. [[func_detail#Good_candidates|It's not uncommon for large portions of a map's brushes to be detail]].
== Nodraw Surfaces ==
[[File:toolsnodraw.gif|right|link=nodraw|tools\toolsnodraw, in Source]]
[[File:DOD hlbasics-NULL.png|right|link=Tool_textures_(GoldSrc)#ZHLT.WAD|64px|NULL, from ZHLT.WAD and HLBASICS.WAD]]
If a player cannot see a brush face without cheating or being a spectator, it's a good idea to apply the special {{mono|toolsnodraw}} material {{src|in}} or {{mono|NULL}} texture {{gldsrc|in}} to it. Nodraw removes the entire face when the map is compiled without affecting visibility, which reduces both rendering time and, since no [[lightmap]] needs to be calculated, map file size.


== Nodraw surfaces ==
You do ''not'' need to apply Nodraw to faces that are touching the void (i.e., outside the map) or to brush faces touching other brush faces tied to the same entity (the world being one big entity of its own). See [[Brush#In-game]]. {{tip|{{src|in}} VBSP combines all <code>func_detail</code>s into one at compile time, so faces of <code>func_detail</code>s that are flush with each other don't need to be nodrawn, either, unless the brush contains a transparent or translucent material.<br>{{gldsrc|in}} HLCSG removes func_detail faces that share a detail level, or are flush with a lower detail level.}}
 
[[File:toolsnodraw.gif|right|link=nodraw|tools\toolsnodraw]]
 
If a player cannot see a brush face without cheating or being a spectator, it's a good idea to apply the special '''nodraw''' material to it. Nodraw removes the entire face when the map is compiled without affecting visibility, which reduces both rendering time and, since no [[lightmap]] needs to be calculated, map filesize.
 
You do ''not'' need to apply nodraw to faces that are touching the void (i.e. outside the map) or to brush faces touching other brush faces tied to the same entity (the world being one big entity of its own). See [[Brush#In-game]].
 
==Areaportals==


==Areaportals {{only|{{src|4.1}}}} ==
{{Main|Areaportal}}
[[File:Toolsareaportal.gif|right|link=Areaportal|tools\toolsareaportal]]
[[File:Toolsareaportal.gif|right|link=Areaportal|tools\toolsareaportal]]


Line 85: Line 77:
In the image to the left all of the leaves can see each other, and this time there is very little that hint brushes can achieve.
In the image to the left all of the leaves can see each other, and this time there is very little that hint brushes can achieve.


In this situation we should create '''''[[Areaportal]]s''''' at the mouth of selected openings. These make the engine perform the per-object line of sight testing that Carmack created the BSP/visleaf system to avoid – but with that system behind it, and with the calculations restricted to when the camera looks through the areaportal, performance can be gained if one blocks enough objects from view.
In this situation we should create '''[[Areaportal]]s''' at the mouth of selected openings. These make the engine perform the per-object line of sight testing that Carmack created the BSP/visleaf system to avoid—but with that system behind it, and with the calculations restricted to when the camera looks through the areaportal, performance can be gained if one blocks enough objects from view.


The image has areaportal locations marked over each mouth, but placing all four would likely hinder performance more than help it. Your strategy depends on the relative [[Budget|cost]] of each area - in most situations, creating the large areaportal to the right and leaving the corridors alone would be best.
The image has areaportal locations marked over each mouth, but placing all four would likely hinder performance more than help it. Your strategy depends on the relative [[Budget|cost]] of each area—in most situations, creating the large areaportal to the right and leaving the corridors alone would be best.
 
(It is ''possible'' to use hints to reduce visibility in this situation, but only with a ridiculous number of them at very precise angles, which impacts performance in its own way. If you can't see across a room for hint brushes then you should be using an areaportal!)


(It is ''possible'' to use hints to reduce visibility in this situation, but only with a ridiculous number of them at very precise angles, which impacts performance in its own way. If you can't see across a room for hint brushes, then you should be using an areaportal!)
{{tip|Areaportals are also useful because they can be closed to completely and [[cheap]]ly block visibility past them. It's a good idea to attach an areaportal to every window-less door in your map, so that they can automatically perform this function.}}
{{tip|Areaportals are also useful because they can be closed to completely and [[cheap]]ly block visibility past them. It's a good idea to attach an areaportal to every window-less door in your map, so that they can automatically perform this function.}}
{{note|Areaportals make no account for objects ''in front'' of them.}}
{{note|Areaportals make no account for objects ''in front'' of them.}}
{{warning|Areaportals can cause problems if placed incorrectly, [[Areaportal|so be sure to read about them carefully]].}}
{{warning|Areaportals can cause problems if placed incorrectly, [[Areaportal|so be sure to read about them carefully]].}}


== Occluders ==
==Occluders {{only|{{source|4.1}}}}==
 
[[File:Toolsoccluder.gif|right|link=func_occluder|tools\toolsoccluder]]
[[File:Toolsoccluder.gif|right|link=func_occluder|tools\toolsoccluder]]


Sometimes you want to block visibility in a way that visleaves simply don't allow: consider a destructible free-standing wall behind which are standing several expensive character models. You don't want to draw the models if they aren't being seen, but without any connected world brushes to work with except the ground you can't do it by separating leaves.
Sometimes you want to block visibility in a way that visleaves simply don't allow: consider a destructible free-standing wall behind which are standing several expensive character models. You don't want to draw the models if they aren't being seen, but without any connected world brushes to work with except the ground you can't do it by separating leaves.


An '''''[[func_occluder|Occluder]]''''' is the tool for the job. It's a brush that hides models (not brushes, alas) behind it when enabled in a similar manner to an areaportal hiding things that ''aren't'' behind it. For obvious reasons, it should be entirely contained inside an opaque object.
An '''[[func_occluder|Occluder]]''' is the tool for the job. It's a brush that hides models (not brushes, alas) behind it when enabled, in a similar manner to an areaportal hiding things that ''aren't'' behind it. For obvious reasons, it should be entirely contained inside an opaque object.


== Draw distance ==
It is possible, however, to convert some brushes into models with something like [[Propper]]. That way, it's possible to hide more models with an occluder. This should be done on [[func_detail|detail]] brushes, which aren't used for cutting [[visleaf|visleaves]].


If you are dealing with a large open area without any cover at all then there isn't a lot you can do but remove detail or employ [[env_fog_controller|fog]] to disguise a low [[draw distance]]. Configure draw distance with ''Map > Properties > Far z_clip plane''.
== Draw Distance ==
If you are dealing with a large open area without any cover at all then there isn't a lot you can do but remove detail or employ [[env_fog_controller|fog]] to disguise a low draw distance. Configure draw distance with ''Far z_clip plane'' ({{code|farz}}).


Draw distances can also be applied selectively to props, even [[prop_static]], with the '''Start Fade Dist/Pixels''' and '''End Fade Dist/Pixels''' [[keyvalue]]s. As the names suggest, these values can represent either distance in units or pixels on-screen as per the '''Screen Space Fade''' KV.
Draw distances can also be applied selectively to props, even {{ent|prop_static}}, with the <code>Start Fade Dist/Pixels</code>and <code>End Fade Dist/Pixels</code>[[keyvalue]]s. As the names suggest, these values can represent either distance in units or pixels on-screen as per the<code>Screen Space Fade</code>KV.{{tip|In fact, all entities with a model can be faded, as well as [[info_overlay|overlays]]. These keyvalues are {{not in FGD}} for most of these entities, however.}}


If you enter fade distances on props, it’s a good general rule to have the difference between the two numbers (start and end) be 200. It looks pretty good, and the larger that number is, the longer the model incurs an increased cost to render. Fading models do not go through the fast path and incur additional sorting cost.
If you enter fade distances on props, it’s a good general rule to have the difference between the two numbers (start and end) be 200. It looks pretty good, and the larger that number is, the longer the model incurs an increased cost to render. Fading models do not go through the fast path and incur additional sorting cost.


<code>[[func_lod]]</code> is a special brush entity that can fade out. You can't use any brushes tied to it as any other entity, however!
{{ent|func_lod}} is a special brush entity that can fade out. You can't use any brushes tied to it as any other entity, however!
 
== Sample maps ==


==Sample Maps==
* <code>sourcesdk_content\hl2\mapsrc\</code>
* <code>sourcesdk_content\hl2\mapsrc\</code>
** <code>sdk_func_detail.vmf</code>
** <code>sdk_func_detail.vmf</code>
** <code>sdk_hints.vmf</code>
** <code>sdk_hints.vmf</code>
** <code>sdk_occluders.vmf</code>
** <code>sdk_occluders.vmf</code>
----
'''''[[Optimization (level design)|<< Return to Optimization (level design)]]'''''
[[Category:Level Design]]
= See Also =


* [[Func_lod]] (World detail that doesn't need to be drawn far away, for performance reasons.)
= See also =
* [[Skybox Optimization]]

Latest revision as of 13:33, 22 March 2025

English (en)Español (es)Français (fr)Русский (ru)中文 (zh)Translate (Translate)

edit
Broom icon.png
This article or section needs to be cleaned up to conform to a higher standard of quality because:
This article originally exclusively covered Source Source, but GoldSrc GoldSrc info has been added, as most of the same concepts apply. Nonetheless, much of the Source-only stuff is not properly marked as such, and the optimization features provided by ZHLT and the now-standard VHLT are not mentioned.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.

Without VIS, everything in a map is drawn all the time regardless of whether or not the player can see it, which would reduce the game performance (and framerate). Clearly the list of objects to be rendered must be trimmed, but how? It would take far longer to test whether each object or surface could actually be seen than it would to render them in the first place!

Game engines have to make a compromise; GoldSrc GoldSrc and Source Source both use the Binary Space Partition model, based on Wikipedia icon John Carmack's implementation in Quake Quake. This page explains how it works and how to manipulate it.

Leaves

Visleaves in a corridor.

The interior (i.e., not occupied by a world brush) space of a BSP map is split into visleaves. Visibility between these 3D volumes is calculated when the map is compiled, and embedded into the map file for use by the engine. Like brushes, leaves are always convex.

The image to the left shows how leaves might be created in u-turn corridors (gaps between them have been added for clarity). There is no line of sight between leaf 1 and 3, and therefore when the camera is in one the contents of the other are not drawn. Calculating this is as simple for the engine as glancing at the map's embedded visibility chart.

But there is a problem with leaf 2. The contents of all three leaves are drawn when the camera is within it, frustum culling aside, even if the left-hand wall completely fills its view. There are tools to overcome this that we'll look at shortly, but keep in mind that in a lot of cases fixing the problem will be more expensive than simply drawing the less-than-optimal scene.

Bear in mind at all times that displacements, point and brush entities (including detail brushes) don't affect leaves. Create nodraw world brush "foundations" if this is a problem: it's quite common for displacements to be created as detailed 'skin' on top of a world brush skeleton, for example.

Note.pngNote:World brushes with $translucent textures do cut visleaves.
Warning.pngWarning:Leaves cannot be created if your map has a leak.
Tip.pngTip:Leaves are split every 1024 units along the xy-plane regardless of brush geometry in order to break large areas down. Hammer's grid is highlighted to help you accommodate this.
Note.pngNote:Leaves work vertically as well as horizontally. Treat skies as extensions of the streets and rooms beneath them.

Reducing VIS Compile Time

VVIS (or VIS/HLVIS in GoldSrc) the tool that calculates visibility between leaves (whereas VBSP (or QBSP2/HLBSP creates them). It shouldn't take more than a few minutes to finish work on even the most complex maps, and if it does, chances are you need to do some of the following. Even if it doesn't, they're good practice!

  • Use detail brushes appropriately.
  • Keep world brushes on the grid as much as you can. Dimensions in the power of two are good.
  • Use simple world brushes that have not been manipulated via other tools excessively, such as carve or vertex manipulation
  • Place func_viscluster(in all games since Half-Life 2: Episode Two) in large areas with unbroken visibility. Leaves within it will be assumed able to see each other.
  • Avoid creating large open areas that the player won't see or interact with in the first place, if it's reasonable to do so. Use a 3D Skybox to reduce sky size, and create a world brush skeleton beneath displacements.

Remember that VIS compile time and in-game performance are two very different things. It may well be worth bearing a long compile if shortening it compromises your result.

Inspecting Leaves

Since Source 2007 Source 2007, Hammer has a new function to view the current map's leaves in the 3D view: Map > Load Portal File. This displays leaf edges that touch other edges as thick blue lines. It's a fantastic learning tool, as if you compile your map without VIS or RAD (then reload its portal file to refresh the display), you can see your changes' effects very quickly.

Source 2006 Source 2006 users and earlier must rely on the glview application.

Tip.pngTip:For even more clarity, use auto visgroups to remove objects from your map that don't block visibility—generally everything but "World Geometry," plus "Tool Brushes," "Water," and "Displacements."

For in-game inspections, there is a console variable called "mat_leafvis". mat_leafvis 3 will outline all the visleaves in the PVS, while mat_leafvis 1 will just outline the leaf that the camera is currently in. (This variable is a cheat.)

You can also inspect the geometry itself through using the mat_wireframe console variable. mat_wireframe 1 will display how polygons are drawn in the current PVS. (This variable is a cheat as well.)

Hints

Main article:  Hint brush
tools\toolshint
All leaves draw at the same time until we hint.

Unfortunately, leaves don't always work out so well as they did in our first example. Consider the alternative layout on the left (in practice things would be configured as per the first image, but put that aside for a moment): in this example the leaves can all see each other, leading to the whole area being drawn at once for no good reason. This is where Hints come in.

A hint is a brush face textured with the special tools\toolshint material, which slices any leaves it intersects in two (faces of the brush that should not split leaves must be textured with tools\toolsskip). In our example, we would place a hint where the purple line indicates, so that it slices leaves 1 and 3 to the same shape that they were in our first example.

It isn't possible to merge leaves together, so after hinting there will be three separate leaves on the right-hand side. Thankfully this isn't a huge problem.

Tip.pngTip:It's a good idea to use hints to separate expensive and cheap areas of the same leaf, if doing so will reduce the amount of time that the expensive areas are drawn for.

Detail Brushes

As was mentioned above, leaves are molded around world brushes. But what if you don't want a brush to do that? If you have a brush that can be seen around at all times (e.g., a statue plinth, or a small free-standing wall), there’s no point in creating lots of extra leaves around it.

In these situations you want func_detail. It's an internal entity which makes the compilers ignore the brush when calculating visibility, without otherwise affecting its behaviour. It's not uncommon for large portions of a map's brushes to be detail.

Nodraw Surfaces

tools\toolsnodraw, in Source
NULL, from ZHLT.WAD and HLBASICS.WAD

If a player cannot see a brush face without cheating or being a spectator, it's a good idea to apply the special toolsnodraw material (in Source) or NULL texture (in GoldSrc) to it. Nodraw removes the entire face when the map is compiled without affecting visibility, which reduces both rendering time and, since no lightmap needs to be calculated, map file size.

You do not need to apply Nodraw to faces that are touching the void (i.e., outside the map) or to brush faces touching other brush faces tied to the same entity (the world being one big entity of its own). See Brush#In-game.

Tip.pngTip:(in Source) VBSP combines all func_details into one at compile time, so faces of func_details that are flush with each other don't need to be nodrawn, either, unless the brush contains a transparent or translucent material.
(in GoldSrc) HLCSG removes func_detail faces that share a detail level, or are flush with a lower detail level.

Areaportals (only in Source Source)

Main article:  Areaportal
tools\toolsareaportal
Teal lines indicate good areaportal locations.

In the image to the left all of the leaves can see each other, and this time there is very little that hint brushes can achieve.

In this situation we should create Areaportals at the mouth of selected openings. These make the engine perform the per-object line of sight testing that Carmack created the BSP/visleaf system to avoid—but with that system behind it, and with the calculations restricted to when the camera looks through the areaportal, performance can be gained if one blocks enough objects from view.

The image has areaportal locations marked over each mouth, but placing all four would likely hinder performance more than help it. Your strategy depends on the relative cost of each area—in most situations, creating the large areaportal to the right and leaving the corridors alone would be best.

(It is possible to use hints to reduce visibility in this situation, but only with a ridiculous number of them at very precise angles, which impacts performance in its own way. If you can't see across a room for hint brushes, then you should be using an areaportal!)

Tip.pngTip:Areaportals are also useful because they can be closed to completely and cheaply block visibility past them. It's a good idea to attach an areaportal to every window-less door in your map, so that they can automatically perform this function.
Note.pngNote:Areaportals make no account for objects in front of them.
Warning.pngWarning:Areaportals can cause problems if placed incorrectly, so be sure to read about them carefully.

Occluders (only in Source Source)

tools\toolsoccluder

Sometimes you want to block visibility in a way that visleaves simply don't allow: consider a destructible free-standing wall behind which are standing several expensive character models. You don't want to draw the models if they aren't being seen, but without any connected world brushes to work with except the ground you can't do it by separating leaves.

An Occluder is the tool for the job. It's a brush that hides models (not brushes, alas) behind it when enabled, in a similar manner to an areaportal hiding things that aren't behind it. For obvious reasons, it should be entirely contained inside an opaque object.

It is possible, however, to convert some brushes into models with something like Propper. That way, it's possible to hide more models with an occluder. This should be done on detail brushes, which aren't used for cutting visleaves.

Draw Distance

If you are dealing with a large open area without any cover at all then there isn't a lot you can do but remove detail or employ fog to disguise a low draw distance. Configure draw distance with Far z_clip plane (farz).

Draw distances can also be applied selectively to props, even prop_static, with the Start Fade Dist/Pixelsand End Fade Dist/Pixelskeyvalues. As the names suggest, these values can represent either distance in units or pixels on-screen as per theScreen Space FadeKV.

Tip.pngTip:In fact, all entities with a model can be faded, as well as overlays. These keyvalues are !FGD for most of these entities, however.

If you enter fade distances on props, it’s a good general rule to have the difference between the two numbers (start and end) be 200. It looks pretty good, and the larger that number is, the longer the model incurs an increased cost to render. Fading models do not go through the fast path and incur additional sorting cost.

func_lod is a special brush entity that can fade out. You can't use any brushes tied to it as any other entity, however!

Sample Maps

  • sourcesdk_content\hl2\mapsrc\
    • sdk_func_detail.vmf
    • sdk_hints.vmf
    • sdk_occluders.vmf

See also