Mapping & Hammer

Custom Skybox, Fog and Colour Correction for GMod Maps

Set the sky, fog and look of a map: 2D skybox and custom sky textures, env_fog_controller with Far Z, color_correction and HDR exposure.

You define the sky of a map through two things: faces with the material tools/toolsskybox and the sky name under Map > Map Properties. Fog comes from an env_fog_controller, the colour mood from a color_correction with a .raw file, and HDR exposure is limited by an env_tonemap_controller. Fog colour, sunlight and colour correction have to match the sky image.

How the 2D skybox works

Faces with tools/toolsskybox are windows to the sky. The engine draws a cube of six images there that always sits around the camera and therefore appears infinitely far away. Which images these are is set by the field "SkyBox Texture Name" (skyname) in the Map Properties. The default is sky_day01_01.

You enter only the base name, without skybox/ and without an extension. The engine appends a suffix for each side of the cube and looks for the material under materials/skybox/:

SuffixSideExample
uptopmaterials/skybox/sky_day01_01up.vmt
dnbottommaterials/skybox/sky_day01_01dn.vmt
lf, rtleft, rightsky_day01_01lf.vmt, sky_day01_01rt.vmt
ft, bkfront, backsky_day01_01ft.vmt, sky_day01_01bk.vmt

Most Half-Life 2 skies also come as a set for HDR with _hdr in front of the suffix, for example sky_day01_01_hdrup. In game, sv_skyname shows the current name. Distant scenery made of geometry is built with the 3D skybox, which is drawn in front of this image.

Using a stock sky or adding your own

GMod ships the Half-Life 2 skies (sky_day01_01 to sky_day03_06, sky_borealis01, sky_wasteland02) and an adjustable one: with the sky name painted and the entity env_skypaint you set the sky colours directly. You do not have to pack anything for these skies.

A custom sky consists of six VTF files and six VMT files in materials/skybox/. The VMT of a stock sky is the best template:

"UnlitGeneric"
{
	"$basetexture" "skybox/mymap_skyup"
	"$nofog" "1"
	"$ignorez" "1"
}
  • $nofog excludes the sky from fog, $ignorez draws it without a depth test so that it stays behind all geometry.
  • The stock sky textures carry the VTF flags Clamp S, Clamp T, No Mipmap and No LOD. Without clamping, seams can become visible at the edges of the cube.
  • The HDR set of the templates uses the shader sky with $hdrcompressedtexture. Test a custom sky without an HDR set specifically in an HDR map.

All twelve files belong in the BSP, see Pack custom content into a BSP. How VTF and VMT files are made is covered in Create custom textures with VTF and VMT.

Matching the light to the sky

The sky is only an image, the light comes from the light_environment. Pitch and Yaw must match the position of the sun in the image, "Brightness and Color" has the colour of the sunlight and "Ambient Color and Brightness" the colour of the sky. For Valve's skies, the Valve Developer Community keeps a Sky List with values from the official maps. The entities themselves are explained in the Source Engine lighting guide.

Fog with env_fog_controller

KeyvalueDefaultEffect
Fog Enable (fogenable)NoTurns the fog on, a new entity shows nothing otherwise
Fog Start (fogstart)500Distance at which the fog begins
Fog End (fogend)2000Distance at which maximum density is reached
Fog Max Density (fogmaxdensity)1Maximum density from 0 to 1
Primary Fog Color (fogcolor)255 255 255Fog colour
Far Z Clip Plane (farz)-1Distance beyond which nothing is drawn. -1 means off

Fog alone saves no performance, it only tints distant surfaces. The gain comes from Far Z: what lies beyond is not drawn, and VVIS reads the value from the env_fog_controller and uses it to limit visibility already at compile time. According to the FGD, Far Z should be higher than Fog End, and Fog Max Density should be 1, because otherwise the void behind becomes visible. More levers are covered in Optimize GMod map performance.

Because the sky is excluded from fog, fully fogged buildings stand out against it as flat single-coloured shapes. So choose a fog colour that matches the horizon.

The 3D skybox has its own fog in the sky_camera, with the same fields for colour, start, end and density. The engine converts start and end to the scale of the skybox itself, so you enter the same numbers as in the env_fog_controller. If there are several controllers, the FGD gives priority to the one with the "Master" flag. Different fog per area is switched in GMod by a fog_volume.

Colour mood with color_correction

A colour correction is a lookup table that replaces every colour of the finished image with another one. It comes as a .raw file of roughly 96 KB and is created in game:

  1. Place a color_correction in the map and leave "Lookup Table Filename" empty for now.
  2. Load the map, enable sv_cheats 1 and enter colorcorrectionui.
  3. Create filters in the tool window and adjust them. Stay within range of the entity while doing so.
  4. Save the result as .raw and put the file under materials/colorcorrection/.
  5. Enter the path in the entity, recompile and pack the file into the BSP.

The file name (filename) is relative to the game folder and includes the extension, for example materials/colorcorrection/mymap.raw. gmad's whitelist allows .raw files only under materials/colorcorrection/.

"Lookup Falloff Start Distance" defaults to 0 and "Lookup Falloff End Distance" to 200. The correction then only applies within 200 units of the entity and fades towards the outside. For the whole map, enter -1 in both fields. "Maximum Weight" controls the strength, and with Enable and Disable you switch between moods.

HDR exposure with env_tonemap_controller

In an HDR map the engine adjusts exposure continuously: it darkens bright scenes and brightens dark ones. The env_tonemap_controller sets limits for this. In GMod's FGD it has no keyvalues for this, you control it through inputs, most simply from a logic_auto:

My Output    Target Entity   Target Input         Parameter
OnMapSpawn   tonemap         SetAutoExposureMin   0.8
OnMapSpawn   tonemap         SetAutoExposureMax   1.6
OnMapSpawn   tonemap         SetBloomScale        0.5

The numbers are example values. SetAutoExposureMin limits how far a bright scene is darkened, SetAutoExposureMax how far a dark one is brightened. In the Source SDK the initial values are 0.5 and 2. SetBloomScale controls the glow around bright surfaces. SetTonemapRate is meant to set the speed of the adjustment, but according to the Valve Developer Community it only took effect in single player in engine branches before CS:GO. So check it on a server. The inputs SetTonemapScale and BlendTonemapScale are commented out in GMod's FGD, with the note that they never worked. The structure of outputs is shown in Hammer inputs and outputs.

Typical problems

SymptomCauseFix
Sky is black or shows a pink and black checkerboardName misspelled, files not packed or wrong suffixesCheck the console for Unable to load sky, check sv_skyname, pack
Sky does not match the 3D skyboxThe fog of the sky_camera differs from the env_fog_controllerAlign colour, start, end and density
Geometry is visibly cut off in the distanceFar Z lower than Fog End, density below 1 or fog offFar Z above Fog End, density 1, "Fog Enable" set to Yes
Colour correction only works in one spotFalloff is still at 0 and 200Set both values to -1
Colour correction is missing for players.raw not packed, path without extension, or turned off by the playerCheck the path, pack, cross-check with mat_colorcorrection 0 and 1

Colour correction and HDR are graphics options, and a server can block colour correction through sv_allow_color_correction. So the map must remain readable without either. Whether the sky materials and the .raw are in the pakfile can be seen in the Map Scanner, which lists the embedded files.

FAQ

Can a map have several skies?

No. The sky name is a property of the whole map and applies wherever tools/toolsskybox is visible. Different moods per area are achieved through fog, colour correction and light.

How large should sky textures be?

The default sky sky_day01_01 uses 512 × 512 pixels for the top and 512 × 256 for the sides. Larger textures are sharper, but with six sides they count six times towards the file size of the map.

Why does my map look different for other players?

Mostly because of graphics options. With HDR, the HDR lightmaps, tonemapping and the HDR sky apply, without HDR the LDR version. If colour correction is turned off, your colour mood is missing. Test both variants before you publish.