Welcome, Guest. Please login or register.

Author Topic: An optimization guide I made  (Read 4470 times)

0 Members and 1 Guest are viewing this topic.

Offline Bob Loblaw

An optimization guide I made
« on: July 06, 2010, 09:45:35 PM »
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 Edit: July 08, 2010, 12:40:52 AM by Skieski »

Offline Wholegrain

Re: An optimization guide I made
« Reply #1 on: July 06, 2010, 10:43:35 PM »
oh my god fucking incredible im going to sticky this

most mappers can learn from this and make more beast maps

Conjoint Gaming [Game On]

Re: An optimization guide I made
« Reply #1 on: July 06, 2010, 10:43:35 PM »

Offline vinnylord

Re: An optimization guide I made
« Reply #2 on: July 07, 2010, 05:11:36 PM »
hur fucking ray for you man nice work
*blanc* WOOT WOOT

Offline Christovski

Re: An optimization guide I made
« Reply #3 on: July 07, 2010, 08:28:52 PM »
hooray finally.  im so sick of explaining nodraw to people and now i can just be like BITCH READ THIS

Luna started the rover's engine.  "AEIOU!" She shouted as she slammed the gas and crashed through the wall.
whenbananasattack: Hot stuff is my life
Toukun: I wanna rock the fuck out.
Ninja Bunn3h: !sex @all

Offline Bob Loblaw

Re: An optimization guide I made
« Reply #4 on: July 08, 2010, 03:33:43 PM »
Thanks guys. If anyone has any questions just let me know. I haven't done any mapping for Gmod/TTT in specific yet, but I would assume it's much the same with a few different entities.

Offline IrishBandit

Re: An optimization guide I made
« Reply #5 on: July 16, 2010, 08:16:07 PM »
Shall be using occulders and areaportals, maybe a couple hints.

Offline Global_Meltdown

Re: An optimization guide I made
« Reply #6 on: August 07, 2010, 10:59:36 PM »
Greeeeeeeat stuff. This should be the preface to the mappers bible!


9:04 PM - (=CG=)Lone Mudkips: Something happened to me that is so vile, that I want to go out in a rampage
9:05 PM - (=CG=)Lone Mudkips: brb
9:05 PM - Global_Meltdown: k
9:05 PM - Global_Meltdown: :\
9:05 PM - (=CG=)Lone Mudkips: Do you want to know?
9:05 PM - Global_Meltdown: yeah
9:05 PM - (=CG=)Lone Mudkips: Do you REALLY want to know?
9:06 PM - (=CG=)Lone Mudkips: There is a Justin Bieber sticker on one of my binders for school.
9:06 PM - (=CG=)Lone Mudkips: That makes me mad
9:06 PM - Global_Meltdown: hahahaha
9:06 PM - Global_Meltdown: pwned
9:06 PM - (=CG=)Lone Mudkips: EFF U WURLD

Offline Redcow17

Re: An optimization guide I made
« Reply #7 on: August 17, 2010, 01:50:48 AM »
Bob if you see this post, add me on Steam.

Redcow17

Conjoint Gaming [Game On]

Re: An optimization guide I made
« Reply #7 on: August 17, 2010, 01:50:48 AM »

 


* ShoutBox!

Refresh History

SimplePortal 2.3.5 © 2008-2012, SimplePortal