Fog tutorial

From Valve Developer Community
Jump to navigation Jump to search
English (en)Русский (ru)中文 (zh)Translate (Translate)
Note how the fog doesn't impact the skybox

When you have fog in your map, you will most likely run into the problem that, while the geometry and models get affected by the fog, the skybox will not. You have several ways of fixing this.

Tip.pngTip:Match the fog settings in the sky_camera entity with the settings of your env_fog_controller for best results.

Fog basics

Add an env_fog_controller point entity to your level. For basic fog, you need to set the Fog Enable to "Yes", change the Primary Fog Color to the color of the fog you want.

Set the Fog Start and Fog End values to a distance in world units for how far away the fog will render. The Fog Start distance is how far away the fog will appear from the player, and Fog End is the distance the fog will appear totally opaque.

Fog Blend, Primary Fog Color and Secondary Fog Color allow you to change the color of the fog depending on the direction that the player is facing.

Set the primary fog color to red, the secondary color to blue, and keep the fog direction as 1 0 0 (i.e. East aka Right aka 0 degrees). In-game, the player will see red fog when they look east, blue fog when they look west, and purple fog if they look north or south.

Far Z clip plane – this setting is used for optimizing your map. Anything beyond this distance (in world units) will not be rendered. It is recommended to keep this number higher than your Fog End value.

Matching Fog Settings with the Skybox

This fog looks good because it matches the skybox

For good looking fog, you'll need to match the fog colors with the skybox colors. You can always fall back on the settings Valve used in their official maps.

For our example, we'll be using sky_day02_10. If you're using this skybox, your env_fog_controller settings would need to be set like this.

Primary fog color: 176 192 202
Secondary fog color: 206 216 222

The settings above were used for the bridge section of Highway 17.

Alternate Method using tools/toolsblack

Using tools/toolsblack can be more effective at achieving proper fog

Alternatively, you can change the skybox brushes to the tools/toolsblack texture. The sky will no longer be visible, allowing your fog settings to color the sky.

Note.pngNote:Since toolsblack won't cast sun/moonlight, it may be preferable to use a skybox such as black, blacksky, or sky_black or create a custom UnlitGeneric skybox with all sides pointing to vgui/black if none of those are available.

Creating a Custom Skybox Texture

Understanding the creation of 2D skyboxes is important. A more in-depth tutorial on creating one is available here.

Much like a regular skybox, you'll want to create six UnlitGeneric materials, each named corresponding to their direction. Leave off the $nofog parameter, however. This allows the fog to overdraw the skybox, without the need for it blending in.

Icon-Important.pngImportant:The Sky shader will always ignore fog. UnlitGeneric must be used if the fog should render over the skybox.

See also