Mapping & Hammer

3D Skybox Guide for Hammer: Setup with sky_camera

How to build a 3D skybox in Hammer: 1/16 scale with sky_camera, clean alignment with the main map, matching fog and the most common mistakes.

A 3D skybox is a small, sealed room inside your map that holds the distant surroundings at 1/16 scale. The engine renders it from the position of the sky_camera entity and shows the result wherever the tools/toolsskybox texture is visible in the main map. The map looks far larger without mountains, a skyline or the sea existing at full size.

How the 3D skybox works

The engine first draws the regular 2D sky, then the 3D skybox, and finally the actual map on top. The camera inside the skybox moves along with the player, but only a sixteenth of the distance, so the scenery shifts believably as you walk.

Two rules follow from this:

  • The position of the sky_camera corresponds to the origin of the main map, the coordinate 0 0 0. The whole alignment depends on it.
  • Players never enter the skybox. Anything that should be reachable belongs in the main map.

Building it step by step

  1. Plan: Decide what is scenery only: mountain ranges, distant rows of buildings, bodies of water, forest.
  2. Build a reference: Copy the rough outline of the main map as simple brushes, for example ground edges and outer walls. Also place a small marker brush exactly on the origin 0 0 0 and include it in the copy.
  3. Scale: Select the entire copy and scale it with Tools → Transform (Ctrl+M) by a factor of 0.0625. That equals 1/16.
  4. Move: Move the shrunken reference to a free spot away from the main map.
  5. Place the camera: Put the sky_camera exactly on the marker brush. Leave the scale value in the entity at its default of 16.
  6. Build the scenery: Create the distant landscape around the miniature reference, for example with displacements, simple brushes and a few models.
  7. Seal it: Enclose the skybox room completely with brushes that use tools/toolsskybox. It has to be sealed like any other room.
  8. Remove the reference: Delete the miniature copy of the main map or move it into a hidden VisGroup. Hidden objects are not compiled.
  9. Prepare the main map: Wherever the distance should be visible, the faces need tools/toolsskybox. With tools/toolsnodraw the skybox stays invisible.
  10. Test: Compile the map and check the transitions in game. r_3dsky 0 and r_3dsky 1 toggle the 3D skybox off and on for comparison.

Checking scale and alignment

One unit in the skybox equals 16 units in the main map. A mountain meant to look 2048 units tall in game is therefore 128 units tall in the skybox. This has consequences:

  • Fine detail is not possible. Work with a small grid and coarse shapes.
  • An offset of one unit in the skybox becomes a 16 unit offset in game. Only ever move the scenery and the sky_camera together.
  • Models are not scaled down automatically. Use models made for skyboxes at the small scale. A regular model appears sixteen times too large.

Check the alignment where main map and skybox meet, for example along a road or a terrain edge. If height and direction match, the camera is in the right place.

Matching fog and light

The sky_camera has its own fog settings. The main map usually relies on an env_fog_controller instead. If the two do not match, you see a hard edge at the transition.

  • Use the same fog colour in both entities.
  • For start and end distance, begin with the same values as in the env_fog_controller and adjust after a test in game.
  • Pick a fog colour that fits the horizon of the 2D sky texture, which still sits behind the 3D skybox.

Fog also hides the low level of detail in the scenery. The sun from light_environment lights the skybox room as well, because it uses the same sky. Shadows quickly look coarse there because of the scale. The article on lighting in the Source Engine goes into more depth.

Keeping an eye on performance

According to the Source SDK code, the 3D skybox is rendered in addition to the main map whenever sky can be visible from the player's position, not only when a sky face is on screen. On open maps that is nearly always.

  • Keep the geometry simple and the room as small as the scenery allows.
  • Use few, simple models and leave out anything nobody can make out from a distance.
  • According to the Source SDK code, the 3D skybox is drawn in a single pass without its own reflection and refraction, so water with real-time reflections does not work there the way it does in the main map. A cheap water material with $forcecheap 1 is the safe choice.

More options are in the article on optimizing GMod map performance.

Common mistakes

SymptomCauseFix
The 3D skybox is not visibleNo sky_camera, or the main map does not use tools/toolsskybox at its edgesPlace the entity, check the textures, check r_3dsky
Scenery floats or is shifted sidewaysThe sky_camera is not on the scaled origin, or the factor is wrongRepeat the alignment with reference and marker
Leak after adding the skyboxThe skybox room is not sealedClose the room completely with world brushes
Hard edge at the horizonFog of sky_camera and env_fog_controller differsMatch colour and distances
Models in the distance are hugeRegular model instead of a skybox variantUse a small model
Miniature landscape visible in the main mapThe skybox room touches the main map or is open to itMove the room away and seal it separately

If VBSP reports a leak after you add the skybox, the compile log names the entity the leak was traced from, for example the sky_camera itself. How to find the gap is covered in the article on fixing the map leak error. The Map Scanner detects root causes, follow-up errors and matching fixes in VBSP, VVIS and VRAD logs.

FAQ

What scale does a 3D skybox use?

The default is 1/16. The value 16 is stored in the sky_camera and should stay unchanged, because existing skybox models are made for that scale. Scale your reference in Hammer by a factor of 0.0625.

Where do I put the skybox room?

In a free spot away from the main map. The room must not touch the main map and has to be sealed on its own. Where it sits in the editor does not matter, only the position of the sky_camera relative to the scenery.

Does a 3D skybox cost a lot of performance?

That depends on its contents. Simple scenery made of displacements and a few models hardly matters. Many models, elaborate materials or large water surfaces make it expensive.

Why can't I see the 3D skybox in game?

Usually the sky_camera is missing, or the main map faces do not use tools/toolsskybox. Also check that r_3dsky is set to 1.