Cubemaps

A cubemap is a texture that represents a three-dimensional rendering of an area. uses entities as sampling points to generate these textures, which are then integrated into the map file. Cubemaps, when built, are reflected on materials that use the $envmap parameter (surfaces such as reflective glass, tiles, water, etc.) A map without built or existing env_cubemap entities will instead use other kinds of "reflections" (such as default cubemap texture, see below) that don't properly depict it, or appear broken (missing textures, reflections appear bright, etc...).
==Building cubemaps==
Building cubemaps is the process of generating textures to use as reflections. For technical reasons, this process isn't automated and is up to the user to do so; until then, existing env_cubemap entities will remain unused and the map, depending on the game, will display either:
*Blank (black) texture (which basically make it look the same as /reflections being disabled)
** During compilation, VBSP will generates blank cubemap textures.
** If you skip VBSP blank cubemap generation (either by using Mapbase VBSP without adding , using VBSP with , or if you deleted the cubemaps, it will display the missing or generic texture instead, and building cubemaps for first time (without disabling ) will instead generate blank textures, until building it again second time, so don't forget to disable it. must be also disabled prior to loading the map, otherwise disabling them after the map have been loaded, will cause to generate blank textures aswell.
*Default cubemap textures (see image on right)
** If the cubemap is missing, the game first tries to fall back to LDR cubemaps (and fails), so the game ended up using this texture instead.
*Cubemaps appear bright (HDR only)
** If HDR version of the cubemap isn't present, the game will fall back to LDR version, which will cause it to appear bright on HDR.
*Missing textures as reflections
** If the cubemap is missing and the game fails to use the default cubemap texture for some reasons, missing texture will show up as reflections.
===Before building===
* If you are using , you can add to launch game () command line in . The game will automatically build cubemaps
* VBSP features the command, which skips automatically generating skybox cubemaps on map compile.
===LDR===
Building cubemaps in a map compiled in LDR (Low Dynamic Range) mode will generate textures only for that mode, regardless of your game's High Dynamic Range video setting. To build the cubemaps, submit the following commands into the game's console:
Command 	Description
 	Turns reflections off, which is necessary if using only one iteration of buildcubemaps, and if all cubemaps has been deleted.It also meant that disabling reflections would avoid some case where missing textures or default cubemap texture (, aka a desert with orange sunset sky), might ended up reflected on the cubemap itself.
map_name</code>	Loads the map; replace "map_name" with the map's actual name
 	Enables the use of cheat commands; required to build cubemaps
 	Begins building cubemaps. Optionally, specify the number of iterations (e.g.: buildcubemaps 2 (default is 1))
 	Unloads the map and returns to the main menu
 	Turns reflections on, then follow the step below, or optionally you can repeat the process again by following instructions on Improve reflections by rebuilding cubemaps.
map_name</code>	Loads the map again, your cubemaps should display after doing these steps.
(requires ) 	In some games, such as , if it doesn't display new cubemap textures after loading the map, run this command to display the newly-built cubemaps. This command may run automatically when you load up the map while cheats is already enabled.
===LDR + HDR===
Building cubemaps in - game, with a map compiled with HDR support needs to be performed twice - once for each mode (HDR and LDR). As opposed to an LDR map's case, your game's High Dynamic Range video setting has to be set to "Full" to build HDR cubemaps, and to "None" to build LDR ones (or using the command. To build the cubemaps for both LDR + HDR, submit the following commands into the game's console:
Command 	Description
 	Turns reflections off, which is necessary if using only one iteration of buildcubemaps, and if all cubemaps has been deleted.It also meant that disabling reflections would avoid some case where missing textures or default cubemap texture (, aka a desert with orange sunset sky), might ended up reflected on the cubemap itself.
map_name 	Loads the map; replace "map_name" with the map's actual name
 	Enables the use of cheat commands; required to build cubemaps
 	Sets HDR exposure to a consistent value, which will make sure that one cubemap won't look as bright or darker than others. This will automatically reset back to 0 after cubemaps are built.
 	Begins building cubemaps. Optionally, specify the number of iterations (e.g.: buildcubemaps 2 (default is 1))</br>In singleplayer games, the map will be automatically reloaded after building cubemaps.
 	Unloads the map and returns to the main menu
 	Disables cheat commands; prevents command mat_reloadallmaterials from unnecessarily self-executing (which briefly freezes the game)
 	Switches to LDR mode (from HDR); submit mat_hdr_level 2 instead if LDR cubemaps were built first
map_name 	Loads the map again to build cubemaps for the new mode
 	
 	Begins building cubemaps for the new mode
 	
 	Turns reflections on, then follow the step below, or optionally you can repeat the process again by following instructions on Improve reflections by rebuilding cubemaps.
 	If necessary, switches back to the mode it was before having submitted mat_hdr_level 0/2
map_name</code> 	Loads the map again, your cubemaps should display after doing these steps.
</br>(requires )</br>or / Restart game	In some games, such as , if it doesn't display new cubemap textures after loading the map, run this command to display the newly-built cubemaps. This command may run automatically when you load up the map while cheats is already enabled.</br>If this command does not reload cubemaps in-game, you can instead + while in fullscreen or simply restart the game can sometime reload the texture (and display the new cubemap) aswell.
===HDR===
This section is for games running on the and later, or engine branches that only support HDR (such as ). To build cubemaps in HDR only, submit the following commands into the game's console:
Command 	Description
 	Turns reflections off, which is necessary if using only one iteration of buildcubemaps, and if all cubemaps has been deleted.It also meant that disabling reflections would avoid some case where missing textures or default cubemap texture (, aka a desert with orange sunset sky), might ended up reflected on the cubemap itself.
map_name 	Loads the map; replace "map_name" with the map's actual name
 	Enables the use of cheat commands; required to build cubemaps
 	Sets HDR exposure to a consistent value, which will make sure that one cubemap won't look as bright or darker than others. This will automatically reset back to 0 after cubemaps are built.
 	Begins building cubemaps. Optionally, specify the number of iterations (e.g.: buildcubemaps 2 (default is 1))</br>In singleplayer games, the map will be automatically reloaded after building cubemaps.
 	Unloads the map and returns to the main menu
 	Turns reflections on, then follow the step below, or optionally you can repeat the process again by following instructions on Improve reflections by rebuilding cubemaps.
map_name</code> 	Loads the map again, your cubemaps should display after doing these steps.
</br>(requires )</br>or / Restart game	In some games, such as , if it doesn't display new cubemap textures after loading the map, run this command to display the newly-built cubemaps. This command may run automatically when you load up the map while cheats is already enabled. In (or some Source games), this command may not reload cubemaps in-game, so instead + while in fullscreen or simply restart the game can sometime reload the texture (and display the new cubemap) aswell.
==Building cubemaps in specific games==
===Black Mesa ===
To build cubemaps in maps, the game has to be launched with these parameters: -oldgameui -dev -console +r_4way_use_fast_normals 0Then, load the map, follow the instructions on HDR section.
After building cubemaps, you can proceed to #Improve reflections by rebuilding cubemaps or simply quit the game, then launch the game again without the command line argument.
===Half-Life: Source===
=== Half-Life 2 ===
; All versions
; 20th anniversary only
=== Left 4 Dead / Left 4 Dead 2 ===
 and restrict certain console commands, such as and . While it seems to be optional, the latter command is recommended to make HDR cubemap have consistent exposure.
;For , you must use in order to use these commands (since VScript wasn't introduced until L4D2):
:
:
;For , you can either use SourceMod or run these VScript command:
:
:
Additionally, unlike or other Source branches, does not reload the cubemap texture, so after you built the cubemap, you will need to restart the game, or alternatively, while in fullscreen mode, + to desktop then back to the game (while the map is already loaded) will reload the cubemap texture in-game.
===Portal 2===
===Source Filmmaker===
:
 "SearchPaths"
 {
 	"Game"	"|gameinfo_path|."
 	"Game"	"swarm_base"
 	"Game"	"platform"
 	"Game" "..\SourceFilmmaker\game\usermod"
 	"Game" "..\SourceFilmmaker\game\tf_movies"
 	"Game" "..\SourceFilmmaker\game\tf"
 	"Game" "..\SourceFilmmaker\game\hl2"
 }
=== Source 2013 MP / Team Fortress 2 ===
== Improve reflections by rebuilding cubemaps ==
This step is optional but after building cubemaps once and enable reflections (), you can build cubemaps again to improve reflections. The improvement it makes is only noticeable if the size was increased to higher resolutions and/or there are two reflective surfaces near each other.
To improve reflections, run the following commands:
Command 	Description
Follow the same instructions as LDR, LDR + HDR or HDR, up until the and command. Make sure is set to "0" first.	Follow the same instructions as LDR, LDR + HDR or HDR, up until the and command. Make sure is set to "0" first.
 	Sets HDR exposure to a consistent value, which will make sure that one cubemap won't look as bright or darker than others. This will automatically reset back to 0 after cubemaps are built.
 	Begins building cubemaps.
 	Unloads the map and returns to the main menu</br>Skip both and if the game (usually singleplayer like ) reloads map automatically.
map_name 	Loads the map again
 	Turns reflections on.
 	Sets HDR exposure to a consistent value again. This will automatically reset back to 0 after cubemaps are built.
 	Building cubemaps the second time.
 	Once you are done, unloads the map.Alternatively, you can switch to LDR or HDR mode using , then repeat the steps starting from the first command. You can also optionally repeat the process again multiple times to further improve reflections, but 2 iterations should be enough.
map_name 	Loads the map again, it should display the new cubemap textures after doing these steps.
or / Restart game 	In some games, such as , if it doesn't display new cubemap textures after loading the map, run this command to display the newly-built cubemaps. This command may run automatically when you load up the map while cheats is already enabled. In (or some Source games), this command may not reload cubemaps in-game, so instead + while in fullscreen or simply restart the game can sometime reload the texture (and display the new cubemap) aswell.
		
==Deleting cubemaps==
Several tools make it possible to delete unnecessary or outdated cubemaps; BSPZIP is one official, command-line tool which is usually the preferred option for this procedure, allowing for an usage unlikely of corrupting the map file due to misuse. To delete cubemaps, execute the following command within the folder:
 ..\..\bin\bspzip -deletecubemaps map_name.bsp
==Extracting cubemaps==
In cases where a map has to be recompiled with minor changes (and its built cubemaps vanish as a result), extracting them beforehand will make it not necessary to go through the whole cubemap-building process again. To extract cubemaps with BSPZIP, create a folder that will contain the extracted cubemaps inside the one, then execute the following command:
 ..\..\bin\bspzip -extractcubemaps map_name.bsp "foldername"
===Embedding cubemaps===
For BSPZIP to make a map use extracted cubemaps, create a text file inside the folder. The file's content should look like this:
 materials/maps/map_name/c-128_384_64.hdr.vtf
 foldername\materials\maps\map_name\c-128_384_64.hdr.vtf
 materials/maps/map_name/c-128_384_64.vtf
 foldername\materials\maps\map_name\c-128_384_64.vtf
 materials/maps/map_name/c448_-256_64.hdr.vtf
 foldername\materials\maps\map_name\c448_-256_64.hdr.vtf
 materials/maps/map_name/c448_-256_64.vtf
 foldername\materials\maps\map_name\c448_-256_64.vtf
 materials/maps/map_name/cubemapdefault.vtf
 foldername\materials\maps\map_name\cubemapdefault.vtf
A file requires two dedicated lines (paths): the first line represents the path it will use within the map file, whereas the second one is the actual location of the file to embed into the map file. Relative location paths were used for the example, but they can also be Absolute. Once the text file is ready, execute the following command:
 ..\..\bin\bspzip -addlist map_name.bsp textfile.txt newmap_name.bsp
==Renaming a map==
For built cubemaps to work, they must be located in a folder that is named after the map; this folder is automatically created within the map file during the building process. Renaming the map file will not also rename said folder, and therefore cubemaps will not be accessed. Some third-party apps allow renaming the folder, though it is not advisable to do so as it may corrupt the file. Instead, either delete and then rebuild the cubemaps, or revert the map to its original name.
==See also==
* env_cubemap
* $envmap
* parallax_obb - For Parallax Corrected Cubemaps.
Category:Cubemaps
Category:Level Design