[TUTORIAL] Basic visibility control

Shmitz

Old Hat
aa
Nov 12, 2007
1,128
746
This tutorial aims to be a guide to basic visibility control using the structure of your map. Visibility is what players are able to see from any given location, and thus what the game has to render.

Visleaves
While an in-depth understanding is not needed for this guide, it helps to know how the game uses these invisible regions to determine visibility. Let's assume you are standing in visleaf A. If any point in A can see into visleaf B, everything in B is considered visible, and is rendered. The exact spot you're standing is less important than the general area in which you are standing.

Layout: Small vs. Large
Inside a building or other small area, you'll probably have rooms that look something like this:
vis-control01.gif


Notice the red line representing visibility, and how every room can see every other room. That's probably fine, because in a small indoor area, it's likely that there's not going to be enough detail or enough players running around to cause any performance issues. However, let's pretend those three squares aren't rooms inside a building, but distinct areas of action of a much larger scale. There may be buildings, boulders, cliffs, bridges, and other objects in those areas that provide a framework for the action, but for the most part it's an open space where you can easily see everything in that area. Now when we look at that red line we see a situation where three very busy, complex areas can all see each other, and so are all being rendered at the same time. That's bad news for most computers.

Hallways
So, maybe if the areas aren't quite so big or quite so complex, we can get away with using hallways/tunnels instead of doorways, like this:
vis-control02.gif


Now we see that the left area can't see the bottom area and vice versa. They each can only see the middle. However, standing in the middle you can still see both, so there's still the potential for performance problems. So instead of just making the connections longer, we want to bend them a bit to play with that line of visibility.

The most basic way is using a 90 degree turn, like this:
vis-control04.gif


That only works if your areas aren't directly in line with each other though. Another common way is a zig zag:
vis-control03.gif


The third basic form is a switchback, which is the most twisty turny but is also practically a guarantee that your two areas won't be able to see each other:
vis-control07.gif


Of course, it's not the exact form of the tunnel that is the important thing, but the way the corners and walls prevent sight between areas. As long as you can't squeeze a straight line through from one area to the next, you can modify, mix, and match as you like. Here are a few examples:
vis-control05.gif

vis-control06.gif

vis-control08.gif


Not enough space!
Sometimes there's just not enough room to give your hallway the right proportions to block visibility completely. Many times though you can place the hallway such that only a corner of the other area can be seen from the first area. Once you determine what's visible, you can then use a pyramid shaped hint to section off that small corner, like this (hint in blue):
vis-control09.gif


If you're in the left area, you'll only be rendering a small amount of the right area. If you're in the right area, there's only a small section where you will be rendering both areas. You can further improve performance by using an areaportal in the hallway, if possible.

Benefits
The benefit of carefully controlling player visibility is not just in-game performance. By using the map's structure to limit visibility from one significant area to another, you can also drastically decrease vis compile time, because you're decreasing the complexity of the bsp tree.

Creativity
Don't let the above diagrams make you think that you need to have small tunnels or hallways between every area, however. Use your imagination, and take advantage of facades to make a vis blocking wall seem like part of the detail. Here are some examples:
zigzag_hydro.jpg

switchback_hydro.jpg

zigzag_roswell.jpg
 
Last edited:

l3eeron

L8: Fancy Shmancy Member
Jan 4, 2008
593
88
Awesome display for a person who knows not about this like myself

:thumbup1:
thanks dude
 

Koei

L4: Comfortable Member
Feb 23, 2008
186
4
I knew the basic stuff, but it's really helpful to have some clear examples :).
 

Termaximus

L5: Dapper Member
Jan 11, 2008
229
32
I have read much on optimization (including the bible by zombie) and this is probably the clearest explanation and examples of using layout for vis blocking. Great job.
 

phatal

L6: Sharp Member
Jan 8, 2008
259
21
I didn't even know about the pyramid hint brush which I think would be useful for me since I didn't use a layout like yours with the use of walls to block in between.

QUESTION: Why is it best to use diaganol hints instead of just horizontal or vertical like in a doorway?
 

Shmitz

Old Hat
aa
Nov 12, 2007
1,128
746
QUESTION: Why is it best to use diagonal hints instead of just horizontal or vertical like in a doorway?

Though there are several tutorials that cover this question more thoroughly, it's still relevant to basic visibility, so let's approach it from that angle.

The compiler is pretty dumb when it comes to cutting up your map into visleaves. All it really knows how to do is follow the lines of your map, which are, most of the time, going to be horizontal (x-axis) or vertical (y-axis). However, visibility just doesn't happen strictly along the X and Y axis. It's like looking through a porthole on a ship. The farther away from the porthole, the more you can see. You might see a vast island in the distance, but you don't see the secret agent crawling up the side of the ship. In other words, visibility acts on a diagonal, depending on what hole you're looking through.

In the context of this tutorial, we can replace "porthole" in the above example with "hallway", because that's what we're using to separate one area from another. We'll use the elbow-shaped hallway for our example. Left to its own, the compiler might end up making visleaves that look like this:
vis-control-hint01.jpg


Our Heavy is sitting there in the hallway, but from where he's standing, he can't actually see around the corner into the room outlined in green. The game thinks he can, though, because you can draw a straight line from the blue visleaf he's standing in to the green one.

We would have the same exact problem if the compiler switched it around, but still stuck to the x and y axis for its cuts, like this:
vis-control-hint02.gif


Even though the blue visleaf is not jutting out into the elbow of the hallway, it can still see, at a diagonal, into the green visleaf. So in order to guarantee that the Heavy is only rendering what he needs to render, we figure out what our bounds of visibility are, and create hints at roughly those angles (always erring to the outside of those bounds), like this:
vis-control-hint03.gif


So we're actually creating an extra visleaf or two when we do this. However, we are also minimizing when both rooms get rendered to when the Heavy is standing in that small purple corner of the hallway. When he's in blue, he can't see into the room on the left. When he's in orange, he can't see into the room on the bottom.
 

trainRiderJ

L5: Dapper Member
Mar 14, 2008
203
31
So in order to guarantee that the Heavy is only rendering what he needs to render, we figure out what our bounds of visibility are, and create hints at roughly those angles (always erring to the outside of those bounds), like this:
vis-control-hint03.gif

When you say "erring to the outside of these bounds", is that what you mean when I see the hint brushes in the pics extending past the doorway and into each of the rooms?
 

grazr

Old Man Mutant Ninja Turtle
aa
Mar 4, 2008
5,441
3,814
Basically, you can consider a visportal to be a window. When inside a visleaf, the portals (faces of the 3d area you reside in, cut by the vbsp during compile) dictate what can be seen, and thus rendered. Not what your screen is simply seeing. By using diagonal hints, you refrain one visleaf from seeing another along a 180 degree plane.

the plane (at the top of the blue visleaf) can see the green visleaf, (imagine you were standing on that plane). This room will be rendered from the blue visleaf, where ever you are inside it.
vis-control-hint02.gif


I tried not to reitterate what was said but maybe that is somewhat more explanative of the situation regarding horizontal/perpendicular visportals/visleaves.
 
Last edited:

Shmitz

Old Hat
aa
Nov 12, 2007
1,128
746
When you say "erring to the outside of these bounds", is that what you mean when I see the hint brushes in the pics extending past the doorway and into each of the rooms?

No, I apologize if there's confusion about the red lines. I am trying to maintain consistency with red lines representing visibility. Erring outside means your hints can be at an angle rotating away from and further out of view and you will generally achieve the same thing. I have not actually drawn the hints in that picture. For potential hint placement, consider this:
vis-control-hint04.jpg


In this case, the "1" dotted lines are the two places where hint brushes would be placed to create the visleaves in my previous examples. However, you could go all the way out to the "2" dotted lines and still effectively block visibility around that corner.

If you place them at "1" you minimize the area in which both rooms are rendered. At the same time, however, the Heavy is rendering the entire hallway from where he's standing. If you place them at "2", the two arms of the hallway can't see each other, but you've created a larger area in which both rooms are being rendered.

Since you can place your hints anywhere between the 1 and 2 positions, a happy middle ground is usually a straight line that touches that corner. Which is better depends on a number of factors including how detailed your "hallway" is and where the most important place to limit visibility is. As mentioned previously, this tutorial does not aim to explore the depths of ideal hint placement, but it's always good when laying out your map's structure to have some idea of what your hint options will be.