Visleaves – The Basics

One of the most important parts of a 3D engine is its ability to ‘cull’ objects that the player can’t see. Imagine if your brain had to try and perceive everything in the direction you were looking, regardless of whether or not you could actually see it with your eyes – you’d probably end up with a huge headache.

That’s that culling is for. The more a game engine has to load, the slower it’ll run and the longer it’ll take for vital actions to process properly. In most cases, the difference will be impossible to notice, but it’s still there and the engine still feels the weight of the visuals it’s loading. To put it into simple terms, an engine needs to know which surfaces the player will see at any given moment and react accordingly, whether that’s displaying visible ones or hiding ones that are out of sight.

Source, as you might expect, is no exception. However, unlike a surprising amount of modern engines, users have the ability to build the culling settings into their map directly as 3D objects, something that makes even the trickiest changes incredibly simple. It’s all thanks to one thing – visleaves.

Screenshot_819

Let’s say we have this little shack in an outdoor area – when the player is indoors, we’ll ideally want the area behind the shack to get culled, and when they’re away from the door we’ll want the inside to be culled instead. Since it’s a small area, the engine might not do it for us automatically, but we can force it to.

Screenshot_820

The texture tools/toolshint is just what we’ll need here. All I’ll do is draw a little block inside the doorway, which will tell the engine that I want a new visleaf to be created here. That doesn’t fully solve the problem, though, since the player indoors will still be able to see the outside world in full.

To fix this, I’ll draw two more, one on either side of the shack, at a point where players won’t be able to peek around the corners of the doorway and see them.

For this example, it’s a little more tricky, I need to use three different visleafs to cover the whole area – I can simply do that by putting them in place, grouping them, hitting ctrl + t  and telling them to act as a func_viscluster. Now the Source engine sees them as one block.

Now, if I hop into the game and load up the map for real, everything will look more or less normal. Did the visleaf actually work?

20190709094508_1
20190709094518_1

By turning on mat_wireframe 3 I can see that, yes, it did! When I’m on the other side of the house, the inside isn’t rendered at all: the faint red outlines in the first image don’t show any space inside the shack, and the second image shows that everything behind the shack isn’t loaded once I step inside.

This is only a small change, but it makes a big difference if used correctly. Source will try to make its own visleaves automatically, but it’s not always perfect and it can miss spots that desperately need their own culling. Imagine this shack as a giant, equipment-filled warehouse and the outside area as a lush green jungle, and you can see why it becomes so important – the more decorations and graphical “extras” you add to your map, the more load it’ll put on your computer, and culling is the easiest way to ease off some of the pressure a little.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: