Skybox Tutorial Updated: 10/31/07
1/16=0.0625
Before you even think about making a 3D skybox make sure the general map layout is complete. It is most important that the outer most walls are in their final positions.
First, let's go over what a skybox actually is. A skybox contains everything that can be seen outside the playable area of a map. This could be hills, trees or buildings that can be seen in the distance when looking over the outer walls of a map. A skybox has two main components. The box itself, and the 'sky_camera' entity. The box is a 1/16 scale, sealed area separate from the playable area of a map, that contains all the outside scenery.
To describe the 'skycamera' entity, consider the following. In hammer when you zoom all the way out in one of the 2D views you can see the entire grid. The center of this grid is the intersection of the thick green lines. This point is defined as coordinate 0,0,0 or the exact center of the building space. It is traditional to build a map with this point being near the center of your level. The 'skycamera' entity is a way for the skybox to reference this point. This way the skybox can be automatically moved to "surround" your map and it will also be properly aligned.
For example, let's say you build your map and you wish to add a skybox. You would create a small enclosed box outside your level and place all your background scenery inside. Then you place a 'skycamera' entity somewhere near the center of this box and compile your map. The game engine will take the box with the scenery inside and make it 16 times larger. The game will also move the box so that the 'skycamera' entity inside it, is exactly at the coordinates 0,0,0. If you have not taken the time to properly align everything, this could produce poor results. For example, some of the things in your skybox can appear in the middle of your level or too far away to see.
The following will teach you how to align your skybox perfectly. The included screenshot shows the skybox boundary in one of my levels. It is aligned so well that the boundary is almost invisible. The red dots mark the skybox boundary and the arrow points to a misaligned texture.
The first step in creating a 3D skybox is to place a temporary 'skycamera' entity at the coordinates 0,0,0. This does not necessarily have to be inside your level but it most likely will be. Then, select the 'skycamera' entity along with some of the main features of your map layout, especially the outermost walls. Only select brushes or displacement surfaces. Use the "copy" command on the selected objects then under "edit" select "paste special". The default settings are fine so just click 'OK'. You will now have an exact copy of your selection. This needs to be scaled down to 1/16 its original size. Make sure the copied material is still selected and right click on it. From the menu select "transform". We are interested in scaling to 1/16 size, so select "scale" and enter 0.0625 in for the x,y and z fields. (0.0625 is the decimal equivalent of 1/16) Now move this tiny version of your level to an out of the way location in the build space. Make sure to move the 'skycamera' entity along with everything else. The position of the skybox doesn't matter because the 'skycamera' entity will align the skybox for you. This next step is important. You must delete the original 'sky_camera' entity located at 0,0,0. Make sure not to delete the one that goes with your skybox.
At this point you should have your original level without a skycamera entity at 0,0,0. You should also have a shrunk down version of your main map geometry with a skycamera entity. It is now time to start building the skybox. Construct a box around your miniature map layout. The size doesn't matter but don't make it excessively larger than needed. You may now add background scenery to your level using the scaled down map geometry as a guide to help you judge the placement and scale of whatever you add to your skybox. This "reference geometry" must be removed before you compile. In addition to the scenery, two identical 'light_environment' entities should be added; one in the skybox and one in the main map area, to create sunlight. Remember, when you play your map in-game, it will appear that your entire level is inside this skybox and that the background scenery is 16 times its original size. Because the actual size of the scenery is very small, it is less work for the engine to render.
To see the skybox properly from in-game, make sure the parts of your level where you can see outside sky are textured with the "toolsskybox" texture. Another way to think about it is that you could build your level and just leave it open wherever there should be sky. To prevent leaks you can place brushes with the skybox texture over the top and sides of the open areas. These brushes are not visible in-game but will make the skybox visible.
Your skybox should now be operational when you compile your map. Using a skybox is much easier on your system than building full scale background scenery around your map.
If the boundary of the skybox is visible from the playable area of the map, such as in the included screenshot, an additional step has to be taken. All the outside walls of the map must be built to a grid size of 16 or larger. This is because when scaled to 1/16 they must still lie exactly on the grid, otherwise it is impossible to align the rest of the skybox so exactly. If you are off my 1/2 of a unit in your skybox there will be a gap of 8 units in-game.











