Results 1 to 10 of 10
  1. #1
    Bob Loblaw is offline
    Genetic Beast Lobster

    Join Date:
    7 Jan 2009
    Location:
    Canada
    Posts:
    2,444
    Thanked:
    656 in 316 Posts

    Bob's Guide to Optimization

    This is my optimization guide. I wanted to make it as clear as possible, because optimization is not an easy thing to understand.
    I tried to keep it as brief as I could while still fully explaining how things worked.

    Here it is and I hope it helps.

    Technique 1:
    Nodraw
    Nodraw every face of every brush that can never be seen by the player.
    If a player can never see a face of a brush, make sure you nodraw it. This prevents textures that can never be viewed, from being rendered.

    *Do this as you go, not at the end of your map.*
    I recommend creating every brush out of the nodraw texture then texturing the faces that can be seen.

    Example:
    Take this doorway for example.


    The wall meets the "trim" of the doorway. The face of the "trim" brush that is directly adjacent to the wall will never be seen. Likewise for the face of the wall that is adjacent to the "trim". Both of these faces should be nodrawn on each side of the doorway.


    As you can see, I went in and nodrawed said faces of the trim and the wall to save on rendering unecessary things.

    In this case each brush has 6 faces. Yet only 2 faces of each wall can be seen, and only 3 faces of each "trim" brush can be seen. More than 50% of the faces in this example should be nodrawn.

    Technique 2:
    Func_detail
    Turn small objects into func_details.

    World geometry (anything not an entity or displacement) cuts up the vis leafs. Vis leafs determine what can, vs can not be seen from where. If there are way too many vis leafs, it can cause lag.

    As a general rule of thumb, if it isn't large enough to really obstruct the view of a player, func_detail it.

    *Do this as you go, and not at the end of your map.*
    Don't go overboard on func_details. If you start func_detailing walls and the floor you will basically be anti-optimizing your map.

    Example:

    Because I created this wall initially with nodraw, it means I don't have to go in and find all the faces that can't be seen by the player and nodraw them. (There are 19 faces that would need nodraw applied in this instance)
    Since you can clearly see through it and it's not truly obstructing view, and considering they are all oddly shaped (cutting up the vis leafs in strange ways) they should be func_detailed. The 2 sections of the wall on each side of the "blast site" should not be func_detailed. They are good shapes to work with (squares are best), that do block visibility so should remain world geometry.

    Technique 3:
    Env_fog_controller's Far Z Clip Plane.
    Whatever the Far Z Clip Plane is set to, means that anything beyond that distance from the player will not be rendered. You can try to hide the Far Z Clip Plane with fog, but unfortunately fog isn't applied to the skybox, so it is very hard to make it look like natural fog would.

    Example:

    As you can see this Far Z Clip Plane looks very strange. Beyond a certain point nothing is rendered, and it looks very out of place. This example has fog disabled.
    You can try to hide the Far Z Clip Plane with fog enabled. It looks a lot better, but still not quite right.

    You can still see that beyond a certain point nothing is being rendered, and this is about as good as you can possibly get it, using a trick that Valve recommends. (Set the maps skybox to sky_day02_10. Then in the env_fog_controller set the primary fog colour to 176 192 202, and the secondary fog colour to 206 216 222. This skybox already has fog built into it, so the map fog blends in a lot better.)

    For these reasons I recommend you use this as a last resort optimization option.

    Technique 4:
    Areaportals
    Areaportals NEED to completely seal off a section of the map. Essentially think of it as a regular leak in a map. The map needs to be completely sealed with world geometry otherwise you will get a ***LEAKED*** error in your compile log. The same goes for areaportals. If there is any way into the sealed off section, aside from through world geometry or an areaportal, then the areaportal won't work. (Remember, entities such as func_detail don't seal off areas)
    Seal off every way in/out of the area with world geometry, or an areaportal and it will work.

    Func_areaportal
    When a func_areaportal is open, it calculates what can be seen from what angles. When it is closed, nothing beyond it is rendered, instead the skybox will be drawn in the areaportal's place.
    Example:
    Take this situation where there has been a massacre behind the wall:

    Sv_cheats 1, then mat_wireframe 1 shows what is being rendered (The blue lines are the bodies).
    As you can see, all of the bodies lying on the floor are currently being rendered, yet only one or two can actually be seen.
    If we fill the opening in the wall with a func_areaportal it will calculate what can be seen from where, and only render what can actually be seen:


    Instead of having ten bodies rendered, the areaportal made it so only two were.

    Func_areaportalwindow
    Func_areaportalwindows work very similarly to func_areaportals, but are set up slightly differently. First, create the areaportal like normal, but make it a func_areaportalwindow.

    Example:

    For rendered window you need to give it the name of the func_illusionary or func_brush that is going to be used.
    Translucency Limit determines whether or not the brush will become completely invisible when the player is closer than the distance set in "Start Fade Distance" (in this case, closer than 128 inches to the areaportal).
    By default the Translucency Limit is set to .2. If used in a window that the player cannot walk through, then this will suffice (because you don't want the window to be completely invisible, and want it to be "see through". If it's used in a doorway to increase FPS, then you will want it set to 0 so that it becomes completely invisible (as if nothing is obstructing your path).

    Next we need to make the Rendered Window. This is either a func_illusionary or func_brush (usually). Make this brush so it surrounds the func_areaportalwindow as shown:


    The purple lines are the func_illusionary, the blue lines are the func_areaportalwindow.
    In hammer, you will only see the black brush, because the areaportal is inside of it.


    Essentially what this does, is it makes the areaportal set to "Closed" when you are further than the End Fade Distance. (Closed means nothing behind it will be rendered)
    As you approach the areaportalwindow, and are closer than the End Fade Distance, the areaportal switches to "Open". Like a normal areaportal, it means it will calculate what can be seen from what angle, and render accordingly.
    In between the End Fade Distance and the Start Fade Distance, the "Rendered Window" (func_illusionary or func_brush) will fade to the Translucency Limit. When set to 0, it means the brush will become completely invisible.
    *If using a func_brush MAKE SURE the func_brush is set to "Never Solid" or it will be invisible, but you can't walk through it.*

    Technique 5:
    Hint Brushes
    The computer uses world geometry to determine how the vis leafs should be cut up. (If the character can "see" a vis leaf, everything in said vis leaf is rendered)
    The computer doesn't always do the greatest job at cutting the vis leafs, so overriding them with hint brushes is a good way to better optimize your map.

    Example:

    Take this very simple L shaped map. The engine determined that the visleafs should be cut as shown. This is not the optimal way to do it. As you can see in this next picture, everything is rendered, because at any point on the map, you can see both visleafs.



    Lets see what happens when we override the way the computer generates vis leafs with our own.
    Create a square block, and then cut it so that it's hypotenuse (the diagonal line) touches the corner of the wall. Create this block with the toolsskip texture. Then apply the toolshint texture to ONLY the hypotenuse face.
    It should come out looking like this (the highlighted brush being the hint/skip brush):


    Now the visleafs are cut up like this instead:


    In this instance, it won't make a huge difference, only removing a few things from being rendered when they can't be seen as shown:


    But imagine if there were lots of details on the walls, and many more things being rendered, then this can make a huge impact.

    The other most common example where hint brushes make a big impact, is with low walls.

    Example:

    Here there is a low wall, blocking your view from the bodies on the other side.
    Yet, as you can tell, the bodies are still being rendered. Why? Because the little gap between the low wall, and the roof, means you can "technically" see the visleafs on the other side, therefore it's all being rendered.

    If we create a hint brush who's "hinted" face is touching the top of the low wall, then it will break up the vis leafs.


    This will prevent the bodies on the other side from being rendered.


    Hint brushes can also be used very effectively in doorways.

    Example:

    In this picture there are more than 10 bodies being rendered. But how many can you see? Not a single one.

    We can use hint brushes to make it so much fewer are being rendered when they can't be seen.

    Using 2 hint brushes, you can greatly reduce what is being rendered.


    The green triangle is one hint brush, with the hint texture only applied to the hypotenuse (as always), the orange triangle is the other hint brush.

    Think of what these two brushes do like this:


    The map is, essentially, now split up into 6 visleafs, as labelled in the image. (The orange lines are the walls)
    Visleaf 1 can only see visleaves 2, 4 and 6 because the walls are hiding visleaves 3 and 5.
    That is why, in the middle area, most of the bodies are not being rendered, because they are in unseen visleaves.

    Visleaf 2 however can see every visleaf except for 3. So if you are in visleaf 2, the bodies in visleaf 5 will be rendered, but the bodies in visleaf 3 still will not be.

    Visleaf 6 can see every visleaf except for 5. If you are in visleaf 6 the bodies in visleaf 3 will be rendered, but the bodies in visleaf 5 will not be.

    This is why hint brushes can be a very powerful optimization tool. (An areaportal would also do extremely well here, probably better. But if areaportal is out of the question because there are other ways in that can't be areaportalled, then you can use hints for optimization)

    Technique 6:
    Render Distances
    By setting the render distance in props, you can prevent models that are very far away from being rendered by fading them out after a specified distance.

    Works similar to func_areaportalwindow's with the Start and End Fade Distances.

    As shown, you can set the Start Fade Dist/Pixels and End Fade Dist/Pixels. I have it set to start fading out at 300 units away, and be finished fading out (completely invisible) at 800 units away. Typically, these will probably be too small to make it look good.


    This image demonstrates how the props fade out. Like I said these distances would generally be too small to look good, because you have to be pretty close in order to see them.

    You can have brushes fade out, by making them func_lod, but generally the fading looks very unnatural, and doesn't end up looking very good.

    **Don't set the Start Fade Distance and the End Fade Distance too far apart or it could cause unwanted lag when are you between the two values.

    Technique 7:
    Func_occluders
    A func_occluder is made by creating a brush with the toolsoccluder texture, and making it a func_occluder.

    Example:
    In this example, there are many dead bodies on one side of a pillar.


    This really destroyed my fps, trying to render all these prop_ragdolls.
    Especially since I could only see a few bodies!

    To prevent the engine from rendering the bodies when they can't be seen you can use a func_occluder. Essentially they work as an areaportal does, but don't need to seal off a section.

    As you move it calculates what you can see and what you can't (if the occluder blocks your view of something, it stops it from being rendered). So all I did, was put a func_occluder inside the pillar.


    As you can see, this saves a lot of fps, because 15 unseen bodies are no longer being rendered.

    **Use occluders sparingly. Because calculations have to constantly be made according to what you can see, if you use them to block only 1, or 2 objects, it won't save on fps, and may end up worsening fps.



    Using any, or all of these techniques can drastically impact the fps of your map. Which is why I strongly suggest you take the time to fully understand how to optimize your map.

    I read a few of the lengthy guides to optimization myself, and afterwards found myself still not fully understanding how they worked (especially hint brushes). That is why I decided to create this guide with many pictures and examples.

    Feedback is appreciated so if this guide did help, or if you are still confused about something just let me know.
    Last edited by Bob Loblaw; 1 Jul 2010 at 06:15pm.

  2. Thanked by 5 users:
    Exacto-Be (3 Jul 2010), Pet Rock (9 Jan 2013), Spiral (1 Jul 2010), Whazaaaaa (2 Jul 2010), yardy (4 Jul 2010)

  3. #2
    Whazaaaaa is offline
    SG Addict
    Whazaaaaa's Avatar
    Join Date:
    20 Dec 2008
    Location:
    Netherlands
    Posts:
    623
    Thanked:
    46 in 33 Posts
    Nice tutorial very useful for people who don't know hope to see more tutorials from you :D
    And maybe use some screenshots for nodraw (people might not understand)

    EDIT!!: Maybe add a little example map with everythign you just explained in the tutorials so they can actualy see how its done in Source SDK - Hammer
    Last edited by Whazaaaaa; 2 Jul 2010 at 04:19pm.
    Rawr.

    ^,.,^

  4. #3
    mapper is offline
    Server Administrator

    Join Date:
    3 Aug 2009
    Location:
    Belgium
    Posts:
    1,448
    Thanked:
    237 in 180 Posts
    Donations:
    $5.00
    Great tut Bob. Keep them coming ^^

  5. #4
    Paul is offline
    Technical Administrator
    Paul's Avatar
    Join Date:
    6 Nov 2007
    Posts:
    4,420
    Thanked:
    2,044 in 573 Posts
    Donations:
    $512.00
    Fantastic

  6. #5
    Bob Loblaw is offline
    Genetic Beast Lobster

    Join Date:
    7 Jan 2009
    Location:
    Canada
    Posts:
    2,444
    Thanked:
    656 in 316 Posts
    If someone requests a guide in specific I might try making one in my spare time.
    I added occluders, images to the nodraw section, render distances, changed the image in my occluder section because I used subdivided displacements which appears as a white mesh, and might have been confusing for those who didn't know that that was the pillar I was talking about (so to clear things up)

  7. #6
    Prez is offline
    SG Addict
    Prez's Avatar
    Join Date:
    26 Jul 2009
    Location:
    Canada
    Posts:
    3,962
    Thanked:
    881 in 504 Posts
    Donations:
    $177.00
    Very good tut. Nice work!

  8. #7
    iNorris is offline
    SG Addict
    iNorris's Avatar
    Join Date:
    11 Mar 2010
    Location:
    Grande Olde U.S. of A.
    Posts:
    1,025
    Thanked:
    107 in 86 Posts
    Hey can you make a tutorial on HOW TO OPEN SDK FOR CSS? I message you, but you NEVER respond. CSS ISNT EVEN IN THE OPTIONS.
    Last edited by iNorris; 10 Aug 2010 at 10:27pm.

  9. #8
    Bob Loblaw is offline
    Genetic Beast Lobster

    Join Date:
    7 Jan 2009
    Location:
    Canada
    Posts:
    2,444
    Thanked:
    656 in 316 Posts
    Quote Originally Posted by iNorris View Post
    Hey can you make a tutorial on HOW TO OPEN FUCKING SDK FOR CSS? I message you, but you NEVER respond. CSS ISNT EVEN IN THE OPTIONS. FUCK IT.
    Lol sorry. If I don't respond on steam message me on the forums. I always leave CSS open, and I think it lets people message me even though my laptop is closed, and I come back with a bunch of new messages but they are offline at that point and so I just leave it.

    If I ever don't respond on steam, message me on the forums because I always reply to those.

    And in the dropdown menu I believe it comes up as (at work so I can't actually check) Source Engine 2009 and the first menu will be either Half Life 2, or Orange Box now possibly. I forget.

  10. #9
    mapper is offline
    Server Administrator

    Join Date:
    3 Aug 2009
    Location:
    Belgium
    Posts:
    1,448
    Thanked:
    237 in 180 Posts
    Donations:
    $5.00
    Quote Originally Posted by Whazaaaaa View Post
    EDIT!!: Maybe add a little example map with everythign you just explained in the tutorials so they can actualy see how its done in Source SDK - Hammer
    Maybe this helps

  11. #10
    Whazaaaaa is offline
    SG Addict
    Whazaaaaa's Avatar
    Join Date:
    20 Dec 2008
    Location:
    Netherlands
    Posts:
    623
    Thanked:
    46 in 33 Posts
    Quote Originally Posted by mapper View Post
    I don't need it, it was ment for other i know optimization :D (only never rly use it but i wil in my upcomming ze map)
    Rawr.

    ^,.,^

User Tag List

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •