Skip to content

Instantly share code, notes, and snippets.

Last active May 5, 2022 23:01
Show Gist options
  • Save Jesse-Culver/e05eeef19c705439b66deca8b97ac711 to your computer and use it in GitHub Desktop.
Save Jesse-Culver/e05eeef19c705439b66deca8b97ac711 to your computer and use it in GitHub Desktop.
This is a basic run down of mapping optimization in the Source 1 Engine.

Optimization in the Source Engine is a critical component of mapping that not only makes your map compile faster but run better in game. However the two results are not always related.

"Why does it take so long for my map to compile?" The short answer is Source uses an optimization method called Binary Space Partitioning. The way this works is by cutting your map up into sections called leaves based on your brushes and then calculating what is in each leaf and then what leaves each leaf can see.

If you want a really good easy to follow explanation watch this video and this video

For optimizing in Source follow these in order and by the end you should have a fairly good understanding of how to optimize your map for performance and compile time. This is something you are going to have to practice and will be hard the first few times you do it but will eventually become second nature when you are building your maps.

  1. Watch "Basic Optimization" by TopHATTwaffle
  2. Watch "Advanced Optimization" by TopHATTwaffle
  3. Optimization in Source: A Practical Demonstration is an excellent guide by MangyCarface that includes plenty of pictures demonstrating different optimization techniques
  4. Read this old article from Interlopers that still contains valuable information with decent visuals
  5. When compiling visleafs are automatically generated every 1024 units on the X and Y plane.
  6. Understand how func_viscluster works. You will see well meaning people recommend you cover everything in a func_viscluster and this is the wrong advice most of the time. func_viscluster is a special optimization tool that tells the compiler that any visleaf inside of it can see any other visleaf inside of it. This will improve compile time however it can ruin in game frame rate by having things render that are outside of the players view. Use of this tool requires you to understand exactly how your leafs are working.
  7. Optimizing An Open Map is a great guide by will2k on MapCore, he has a lot of good guides on optimization you should check out such as the very well written Man vs Engine PDF.

Note: There is a common held belief that the number of numportals is directly related to performance. This is incorrect. Think about what would happen if you had only one portal in your entire map, everything would render. Having portals helps the engine determine what to render. There is no good number and there is no bad number. It is whatever number is appropriate for your map.

Commands for checking optimization:

cl_showfps: Displays your frame rate

cl_showpos: Displays your coordinates

mat_leafvis #: Will display visleafs, depending on value set determines which ones to display

mat_texture_list: Displays all current textures for the frame

mat_show_texture_memory_usage: Displays memory usage of textures

mat_wireframe #: Will show you what is being rendered even if out of view. If you see a wiremesh model through a wall understand the game is still trying to render that for the player.

perfui: Displays performance UI tools

r_novis: Will disable the PVS system and render everything in the map.

r_lockpvs: Will lock the current PVS and allow you to move around and see which leaves are a part of that PVS and what all is being rendered.

showbudget: Measures how long each frame takes to generate and tells you what is causing it. Use budget_panel_height to adjust height of the showbudget panel.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment