Cubemaps: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Added information about building cubemaps in HL:S)
(Rewrote the article for better readability)
Line 1: Line 1:
{{otherlang2
{{lang|Cubemaps}}
|fr=Cubemaps:fr
[[Image:Env_cubemap.png|left]][[Image:Specular.jpg|thumb|300px|right|Models with specular reflections.]]
|ru=Cubemaps:ru
A '''cubemap''' is a texture that represents a three-dimensional rendering of an area. The [[Source|Source Engine]] uses [[env cubemap|env_cubemaps]] as sampling points for generating these textures, which are then saved into the [[BSP]] file. Surfaces using the [[$envmap]] parameter with ''env_cubemap'' as its value will reflect the built cubemaps.
|es=Cubemaps:es
}}
[[Image:Env_cubemap.png|left]][[Image:Specular.jpg|thumb|350px|right|Specular reflections.]]


Many reflective [[material]]s must be combined with external data so that the [[Source]] engine can correctly generate their appearance. This data is stored as a ''cubemap'', a texture which represents a three-dimensional rendering of an area. The Source engine uses [[env_cubemap]] entities as sampling points for generating these textures, and saves the cubemaps inside each map's BSP file. While processing specular and environment-mapped materials, it utilizes them to more accurately generate environments. In other words, a cubemap creates the textures that a reflective surface will be reflecting.


{{note|[[Half-Life: Source]], [[Portal 2]] and [[Team Fortress 2]] have issues with building cubemaps. Their bugs are listed [[#Bugs|here]]. }}  
== Building cubemaps ==
For technical reasons, '''env_cubemaps''' remain unused in compiled maps until built manually; until then, and depending on the game, the map will use either generic reflections, or a missing texture due to non-existent cubemaps.
{{warning|Your game's resolution must be at least 4 times higher than the highest [[env cubemap#Keyvalues|size]] of an '''env_cubemap''' in a map, or else attempting to build them will either fall or even cause the game to crash. For example: if an '''env_cubemap''' sizes 128x128, you'll need a resolution of at least 512x512 (''128 × 4 = '''512''''' -> 720x576 or higher).}}
{{note|{{csgo}} '''Counter-Strike: Global Offensive''' must be launched with the <code>-insecure</code> parameter in order to be able to build cubemaps.}}
{{note|It's necessary to relaunch the game after building cubemaps in order to display them.}}
{{tip|Maxing out your game's visual settings prior to building cubemaps will generate their textures in the best-possible quality (based on the '''env_cubemaps'''<nowiki>'</nowiki> size).}}


== Building Cubemaps ==


Once a map has been compiled and lit by [[Vbsp|VBSP]] and [[Vrad|VRAD]] (respectively), the cubemaps can be built. After the map is finished loading, use the <code>buildcubemaps</code> [[Developer_Console|console]] command to begin building the cubemaps for the level. Here you’ll be able to see each facet of the cubemap (six per cubemap) render and this can take seconds or minutes to complete depending on your system configuration. Once finished, the map or the game must be restarted for the cubemaps to properly be applied to all surfaces.  
=== Before building ===
{{css}} '''Counter-Strike: Source''' maps are among the known ones to include pre-built, blank cubemaps on compile; they're built even if there are no '''env_cubemaps''' in the map, and it is recommended to erase them first as explained [[#Deleting cubemaps|here]].


{{note|Set <code>mat_specular</code> to 0 before running <code>buildcubemaps</code> or it will result in improper reflections! }}


{{note|Built cubemaps are saved in the BSP file the game loaded, which is in the maps folder, not the location where the BSP file was built. }}
=== LDR ===
{{note|This step does not apply to {{csgo}} '''Counter-Strike: Global Offensive''' as its maps are compiled in [[#HDR|HDR]] only.}}
A map compiled in '''LDR''' (''Low Dynamic Range'') will build only that mode's cubemaps, regardless of your game's current [[HDR]] (''High Dynamic Range'') setting. Submit the following commands into the game's console:
{| class="wikitable"
! Command !! Description
|-
| <code>mat_specular 0</code> || Disables specularity. Required to properly build cubemaps
|-
| <code>map</code> &lt;'''the map's filename'''&gt; || Loads the map (e.g., <code>''map cs_mymap''</code>)
|-
| <code>sv_cheats 1</code> || Enables the use of cheat commands. Required to build cubemaps
|-
| <code>buildcubemaps</code> || Starts building cubemaps
|-
| <code>disconnect</code> || Unloads the map, returning you to the main menu
|-
| <code>mat_specular 1</code> || Enables specularity. Required to see reflections
|-
| <code>quit</code> || (optional) Closes the game. Required to see reflections after building cubemaps
|}


{{note|If you intend to change the name of your bsp and build its cubemaps, you must <code>buildcubemaps</code> before renaming and packing the bsp. }}


{{note|If your map has big reflective surfaces facing each other (e.g skyscrapers), it is recommended to <code>buildcubemaps</code> twice, so your reflective surfaces in the reflections will also have reflections from the first build. }}
=== HDR ===
A map compiled with '''HDR''' support will need its cubemaps built twice; once for each mode ('''HDR''' and '''LDR'''). As opposed to a '''LDR''' map's case, your game's '''HDR''' setting must be set to "None" to build '''LDR''' cubemaps, and to "Full" to build '''HDR''' ones. Submit the following commands into the game's console:
{| class="wikitable"
|-
! Command !! Description
|-
| <code>mat_specular 0</code> || Disables specularity. Required to properly build cubemaps
|-
| <code>map</code> &lt;'''the map's filename'''&gt; || Loads the map (e.g., <code>''map cs_mymap''</code>)
|-
| <code>sv_cheats 1</code> || Enables the use of cheat commands. Required to build cubemaps
|-
| <code>buildcubemaps</code> || Starts building cubemaps
|-
| <code>sv_cheats 0</code> || Disables cheat commands. Prevents command ''<code>mat_reloadallmaterials</code>'' from self-executing and briefly freezing the game unnecessarily
|-
| <code>disconnect</code> || Unloads the map, returning you to the main menu
|-
| <code>mat_hdr_level 0</code> || Switches to '''LDR''' mode (from '''HDR'''). Submit <code>''mat_hdr_level 2''</code> instead if '''LDR''' cubemaps were built first
|-
| <code>map</code> &lt;'''the map's filename'''&gt; || Loads the map again to build cubemaps for the new mode
|-
| <code>sv_cheats 1</code> ||
|-
| <code>buildcubemaps</code> || Starts building cubemaps for the new mode
|-
| <code>disconnect</code> ||
|-
| <code>mat_specular 1</code> || Enables specularity. Required to see reflections
|-
| <code>mat_hdr_level ''0/1/2''</code> || If necessary, switches back to the mode it was before having submitted <code>''mat_hdr_level 0/2''</code>
|-
| <code>quit</code> || (optional) Closes the game. Required to see reflections after building cubemaps
|}


===HDR===


If the map has been compiled with the [[HDR]] lighting option enabled in [[Vrad|VRAD]], cubemaps '''must''' be built in both HDR '''and''' LDR (non-HDR) modes. Building cubemaps in only one mode will mean that cubemaps will not be present the other mode. For information on how to build cubemaps under HDR, see [[HDR Lighting Basics]].
=== Half-Life: Source ===
{{bug|Cubemaps in {{hls}} '''Half-Life: Source''' don't currently build properly as their textures, despite being generated, aren't saved into the '''BSP''' file afterward.}}
:{{workaround|Move the '''BSP''' file into the "maps" folder of a game of the same engine branch (such as {{hl2}} '''Half-Life 2'''), build the cubemaps in said game, then move the file back into '''Half-Life: Source'''<nowiki>'</nowiki>s.}}


Cubemaps should be built for LDR and HDR maps. Presuming you are already in HDR mode and have your map loaded fresh from compilation (VRAD must have the <code>-both</code> parameter enabled). Go to the console and execute the following commands:


buildcubemaps
=== Source Filmmaker ===
mat_hdr_level 0 ''(to go to LDR)''
{{bug|Cubemaps in {{sfm}} '''Source Filmmaker''' don't currently build properly as their textures are generated blankly.}}
  restart ''(to reload map)''
:{{workaround|Move the '''BSP''' file into {{as}} '''Alien Swarm'''<nowiki>'</nowiki>s "maps" folder, build the cubemaps in that game, then move the file back into '''Source Filmmaker'''<nowiki>'</nowiki>s.}}
  buildcubemaps
::{{note|For this procedure, '''Alien Swarm'''<nowiki>'</nowiki>s "gameinfo.txt" file will need to be edited to use assets from '''Source Filmmaker'''<nowiki>'</nowiki>s mod directories not to build cubemaps with missing textures/models. The file's "SearchPath" section should look like this:}}
mat_hdr_level 2 ''(to go back to HDR)''
"SearchPaths"
  restart ''(to reload map)''
{
"Game" "|gameinfo_path|."
"Game" "swarm_base"
"Game" "platform"
"Game" "..\SourceFilmmaker\game\hl2"
"Game" "..\SourceFilmmaker\game\tf"
"Game" "..\SourceFilmmaker\game\tf_movies"
"Game" "..\SourceFilmmaker\game\usermod"
  }
== Deleting cubemaps ==
Deleting cubemaps is useful to get rid of unnecessary or outdated ones and their associated files. Out of all other capable tools, [[BSPZIP]] is the safest way for doing so without potentially corrupting the map; from the "maps" folder where the '''BSP''' is located, execute the following command:
  ..\..\bin\bspzip -deletecubemaps mapname.bsp
{{note|Replace "''mapname''" with the map's actual filename.}}
{{warning|Cubemaps should be deleted before embedding texture ("[[Valve Texture Format|.vtf]]") files into the '''BSP''' file as this procedure actually deletes all the texture files in it.}}
== Extracting cubemaps ==
In cases where a map needs to be updated (recompiled) with minor changes and its built cubemaps vanish as a result, extracting said cubemaps beforehand will make it not necessary to go through the whole cubemap-building process again until it actually becomes so. Create a folder that will contain the extracted cubemaps within the "maps" folder and execute the following command:
  ..\..\bin\bspzip -extractcubemaps mapname.bsp "foldername"
{{note|Replace "''mapname''" with the map's actual filename, and "''foldername''" with the actual name of the folder to extract cubemaps into.}}


{{note|This does not apply to CS:GO as HDR cannot be turned off. }}
===Team Fortress 2 / Source 2012+ Games===
[[Team Fortress 2]] does not have a default cubemap applied to reflective surfaces. (There are also similar problems with some installations of [[Portal 2]], except cubemaps will simply not appear.) Everything shiny will shine with a pink and black checkered texture. If you were to build cubemaps now and one of your cubemap is able to see a large shiny surface; the cubemap will register that in its 6 images. That means some objects might shine as if there was something shining next to it with the pink and black texture. To solve this, you need to build the cubemaps with specular turned off. To build cubemaps for your TF2 map, go to the console and execute the following commands:
Building Cubemaps for LDR '''or''' HDR only:
{{note|Do not enable <code>sv_cheats</code> before loading the map; it will automatically execute <code>mat_reloadallmaterials</code> right after the map has loaded and will cause the next menu to freeze for a moment.}}
{{note|It is recommended to set <code>mat_specular</code> to 0 before loading a map, so it takes much less time to complete than doing so while/after a map has loaded.}}
mat_specular 0
map <your map>
sv_cheats 1
buildcubemaps
disconnect
sv_cheats 0
Building cubemaps for HDR requires you to repeat these steps after loading your map while HDR is enabled.
{{note|If the game crashes when you try to build cubemaps, this probably means your game resolution is set too low. Before you try to build cubemaps you must ensure your game width and height are over 512 pixels. This means that the minimal standard resolution to build is 800×600. The video resolution can be changed from the Video tab, found under the game Options menu.}}
{{note|If the map BSP file is renamed after the cubemaps have been built the cubemaps will no longer work and default to the sky cubemap. You must rebuild cubemaps again each time a map is renamed. However, the no-longer-working cubemaps are not removed, so this can lead to bloated files. If you plan to release a map so that others can download it, it is best to try to avoid any map-renaming after you compile it, to avoid problems.}}
{{note|For multiplayer maps in some games, you may need to enable cheats (<code>sv_cheats 1</code>) before running <code>buildcubemaps</code>.}}
===After SteamPipe Update===
Due to the SteamPipe update, a recognised problem might be building the cubemaps with no effective results. This problem can be fixed by the following steps: †
{{bug|{{csgo}} In Counter-Strike Global Offensive, editing your map file directly like this can have adverse side effects including node graph glitches and losing static_prop shadow data. [https://steamcommunity.com/app/211/discussions/0/846959998155287479/ This] method can prevent that.}}
# Place [[env_cubemap]] entities in valid locations in your map, and compile. '''Important''': Name has to be shorter than 30 characters (including the .bsp extension), or the BSP won't be writeable. Also, don't change the map name after compiling, or the cubemaps won't work.
# Use your favorite BSP pakfile editor (e. g. VIDE or Pakrat. Usage of these tools isn't included in this tutorial.), and load your BSP file.
# Delete all files that are a "Texture" or "Texture (HDR)" type. (Not "Material" files, only the VTF's!)
# Save the edited BSP file.
# Copy your map back to your game's maps folder.
# Open console and type: <code>map <nowiki><mapname></nowiki></code>. (e. g. <code>map ttt_mars_colony_cubemap</code>)
# Once in-game, open the console again and type <code>mat_specular 0</code> and <code>buildcubemaps</code>.
# Wait until completion, and then re-enable specular mapping with <code>mat_specular 1</code> and reload your materials with <code>mat_reloadallmaterials</code>.
{{note|If you want to pack custom content with your map, do it after building cubemaps.}}
† According to this [http://www.facepunch.com/showthread.php?t=1293081 thread]
===Source Filmmaker===
Building cubemaps in Source Filmmaker is currently broken and will only render a single face of a single cubemap. To build cubemaps for Source Filmmaker maps correctly, copy the map file and assets used by the map (textures, models, etc) to [[Alien Swarm]]. As the engine branch version is very similar, there is no need to recompile separate maps or models; copying the files should suffice. Load up your map in Alien Swarm and input the <code>buildcubemaps</code> command into the console. After the faces are rendered, your map will now contain cubemaps and can be copied back over to Source Filmmaker. This will only work with the newer map branch version, as maps from [[Team Fortress 2]] or [[Garry's Mod]] will crash the game upon loading.
Additional 'no-copy' version to hammer and build is using an additional mod configuration in Alien Swarm with 'alien' (relative) search pathes to the content of sfm. todo: absolute pathes.
Example for the 'common' location:
"SearchPaths"
{
"Game" "|gameinfo_path|."
"Game" "swarm"
"Game" ".\..\SourceFilmmaker\game\tf_movies"
"Game" ".\..\SourceFilmmaker\game\tf"
"Game" ".\..\SourceFilmmaker\game\usermod"
"Game" ".\..\SourceFilmmaker\game\hl2"
"Game" "swarm_base"
"Game" "platform"
}
===Portal 2===
When you want to build cubemaps for a map lying in ''Portal 2/portal2/maps'' (Hammer copies the maps to there by default) Portal 2 will crash because it expect that the map can be found under the highest DLC folder (DLC2 by default). To fix the crash, just copy your map into ''Portal 2/portal2_dlc2/maps'' (or whatever the highest DLC folder is), reload it and build cubemaps again. It should work now.
===Left 4 Dead 1/2===
To build cubemaps in [[Left 4 Dead 2]] the shader settings must be set to medium. If you change the shader settings while a map is loaded you may need to reload the map as sometimes overlays end up with broken lighting, making them appear [[UnlitGeneric|unlit]].
Once the cubemaps for one map are built you must restart the game to test them. Sometimes you must restart the game to build cubemaps on a second map aswell.
===Half-Life: Source===
Building cubemaps in Half-Life: Source is not possible for now, since it will generate but not add the cubemaps into the map (it will copy the TGA files into the <code>materialsrc</code> folder, but the game will not convert them into VTF towards the <code>materials</code> folder, and from there adding them into the pakfile).
The only solution passes by copying the map and assets/mount the content to another game of the same branch (like HL2), building the cubemaps there and then copying the BSP. It shouldn't be needed to recompile the map.
== Testing ==
Cubemaps are best tested by using the <code>[[impulse]] 81</code> console command. To do this; type in <code>[[impulse]]</code> 81 in the Console. Then, type <code>[[give]]</code> weapon_cubemap.
{{note| You can bind these two commands to separate keys so don't have to type this in every time.}}
This replaces the current weapon model with the "[[weapon_cubemap|cubemap weapon]]"; a set of spheres, each with different reflective surfaces. By moving around the level it is possible to see what cubemap is being applied at that position in space at any given time, as well as if that cubemap accurately describes the area’s lighting and color.
{{note|The [[weapon_cubemap|cubemap weapon]] can be copied from ''Steam\SteamApps\common\Half-Life 2\hl2\models\shadertest\envballs.mdl'' to a desired mod which doesn't have it.}}
{{note|If you run a recompiled copy of the same map without restarting the game, the cubemaps from the previous version will still be cached, making it appear as if cubemaps do not need to be rebuilt. These cubemaps are ''not'' in the map, however, as running the map again on another computer or after restarting the game will reveal. Every new compile wipes out all packed content, including cubemaps.}}
== Performance ==
The [[env_cubemap]] entity allows the user to define how large the target cubemap’s texture resolution is. While a larger texture resolution will provide more accurate and “sharp” results when sampled, it also incurs a cost in texture memory. Most cubemaps should only use the default setting in the env_cubemap entity for their texture resolution (32x32 pixels for each surface). This is generally acceptable in normal conditions. Some exceptions may be necessary for areas of high reflectivity or detail, such as set-pieces for acting.
Because surfaces must approximate their surroundings via cubemaps, using too many cubemaps in a small area can cause noticeable visual discontinuities when moving around. For areas of high reflectivity, it is generally more correct to place one cubemap in the center of the surface and no more. This avoids seams or popping as the view changes.
To determine the cost of cubemaps in any one area, first look at the World Rendering category using the <code>[[showbudget|+showbudget]]</code> console command. If this category is registering an unusually high cost, it may be due to using too many cubemaps in an area. A simple solution to check for this scenario is to use Hammer to Hide all the cubemaps in the map, and then compile and run the map again. If the performance is noticeably better, cubemap density or resolution may need to be reduced.
Eventually this can also be checked by turning off cubemaps, by using <code>mat_specular 0</code> to disable it, however this needs confirmation.
==Bugs==
{{note|For some games (L4D{{L4d}}/L4D2{{L4d2}}) a complete '''game restart''' is required after building the cubemaps in order to enable them.}}
{{bug|In [[Team Fortress 2]] [[VBSP]] fails to load the skybox to use it as the default cubemap, so all reflective surfaces will show the [[missing content]] texture, which resembles a pink and black checkerboard. To fix this you will need to build cubemaps manually.}}
{{bug|Building cubemaps in Portal 2 will crash the game if the map you are running is in the default ''common/portal 2/portal2/maps'' folder. This crash happens when the map is being reloaded, after the cubemaps have been saved to the file. To prevent the crash, set the 'Place compiled maps' option in the [[Hammer_Build_Programs|Build Programs]] tab of Hammer options to 'common/portal 2/portal2_dlc2/maps', then recompile the map before compiling the cubemaps.}}
{{bug|Some models require built cubemaps to look correct. Without them, they may end up looking super shiny and even glowing. Building cubemaps with such broken models will build those broken model materials into your cubemap. In those cases you may need to either build the cubemaps twice or lower your shader detail to a lower level where cubemaps will not be used, eliminating the broken texture bug for those few models}}
== See Also ==


=== Embedding cubemaps ===
To make use of extracted cubemaps, create a text file that will include the directory structure to use within the '''BSP''' file and the path to the file(s) to embed with '''BSPZIP'''. Here's an example of "packlist_mymap.txt" (the text file can be named anyhow; its name will later be referenced in '''BSPZIP'''):
materials/maps/mapname/c0_416_64.hdr.vtf
'''foldername\materials\maps\mapname\c0_416_64.hdr.vtf'''
materials/maps/mapname/c0_416_64.vtf
'''foldername\materials\maps\mapname\c0_416_64.vtf'''
materials/maps/mapname/c416_0_64.hdr.vtf
'''foldername\materials\maps\mapname\c416_0_64.hdr.vtf'''
materials/maps/mapname/c-416_0_64.hdr.vtf
'''foldername\materials\maps\mapname\c-416_0_64.hdr.vtf'''
materials/maps/mapname/c416_0_64.vtf
'''foldername\materials\maps\mapname\c416_0_64.vtf'''
materials/maps/mapname/c-416_0_64.vtf
'''foldername\materials\maps\mapname\c-416_0_64.vtf'''
materials/maps/mapname/cubemapdefault.vtf
'''foldername\materials\maps\mapname\cubemapdefault.vtf'''
{{note|Replace "''mapname''" with the map's actual filename, and "''foldername''" with the actual name of the folder that contains the extracted cubemaps.}}
Each file requires two dedicated lines (paths); the first line represents the structure of the directory that the file will use in the '''BSP''' file (always basing from the game's subfolder), while the second one is the actual location of the file to find and embed. The second line in this example used a relative path (considering that the text file is located inside the "maps" folder, alongside the folder that contains the cubemaps), but it can also be absolute. After the text file is created, execute the following command:
..\..\bin\bspzip -addlist mapname.bsp textfile.txt newmapname.bsp
{{note|Replace "''mapname''" with the map's actual filename, "''textfile''" with the text file's actual filename, and "''newmapname''" with the map's actual filename to override it (or type in a different filename to generate an additional '''BSP''' file).}}
== Renaming a map ==
Built cubemaps are saved into a directory within the '''BSP''' file, with the directory sharing its name; changing the name of the '''BSP''' will cause cubemaps not to load alongside the map, and therefore it will act as if there were none. To correct that, either delete then rebuild cubemaps, or extract then repack (embed) them with a matching map name in the cubemaps' directory.
== See also ==
* [[env_cubemap]]
* [[env_cubemap]]
* [[$envmap]]
* [[$envmap]]
[[Category:Level Design]]
[[Category:Level Design]]

Revision as of 15:21, 14 November 2020

English (en)Español (es)Français (fr)Português do Brasil (pt-br)Русский (ru)中文 (zh)Translate (Translate)
Env cubemap.png
Models with specular reflections.

A cubemap is a texture that represents a three-dimensional rendering of an area. The Source Engine uses env_cubemaps as sampling points for generating these textures, which are then saved into the BSP file. Surfaces using the $envmap parameter with env_cubemap as its value will reflect the built cubemaps.


Building cubemaps

For technical reasons, env_cubemaps remain unused in compiled maps until built manually; until then, and depending on the game, the map will use either generic reflections, or a missing texture due to non-existent cubemaps.

Warning.pngWarning:Your game's resolution must be at least 4 times higher than the highest size of an env_cubemap in a map, or else attempting to build them will either fall or even cause the game to crash. For example: if an env_cubemap sizes 128x128, you'll need a resolution of at least 512x512 (128 × 4 = 512 -> 720x576 or higher).
Note.pngNote:Counter-Strike: Global Offensive Counter-Strike: Global Offensive must be launched with the -insecure parameter in order to be able to build cubemaps.
Note.pngNote:It's necessary to relaunch the game after building cubemaps in order to display them.
Tip.pngTip:Maxing out your game's visual settings prior to building cubemaps will generate their textures in the best-possible quality (based on the env_cubemaps' size).


Before building

Counter-Strike: Source Counter-Strike: Source maps are among the known ones to include pre-built, blank cubemaps on compile; they're built even if there are no env_cubemaps in the map, and it is recommended to erase them first as explained here.


LDR

Note.pngNote:This step does not apply to Counter-Strike: Global Offensive Counter-Strike: Global Offensive as its maps are compiled in HDR only.

A map compiled in LDR (Low Dynamic Range) will build only that mode's cubemaps, regardless of your game's current HDR (High Dynamic Range) setting. Submit the following commands into the game's console:

Command Description
mat_specular 0 Disables specularity. Required to properly build cubemaps
map <the map's filename> Loads the map (e.g., map cs_mymap)
sv_cheats 1 Enables the use of cheat commands. Required to build cubemaps
buildcubemaps Starts building cubemaps
disconnect Unloads the map, returning you to the main menu
mat_specular 1 Enables specularity. Required to see reflections
quit (optional) Closes the game. Required to see reflections after building cubemaps


HDR

A map compiled with HDR support will need its cubemaps built twice; once for each mode (HDR and LDR). As opposed to a LDR map's case, your game's HDR setting must be set to "None" to build LDR cubemaps, and to "Full" to build HDR ones. Submit the following commands into the game's console:

Command Description
mat_specular 0 Disables specularity. Required to properly build cubemaps
map <the map's filename> Loads the map (e.g., map cs_mymap)
sv_cheats 1 Enables the use of cheat commands. Required to build cubemaps
buildcubemaps Starts building cubemaps
sv_cheats 0 Disables cheat commands. Prevents command mat_reloadallmaterials from self-executing and briefly freezing the game unnecessarily
disconnect Unloads the map, returning you to the main menu
mat_hdr_level 0 Switches to LDR mode (from HDR). Submit mat_hdr_level 2 instead if LDR cubemaps were built first
map <the map's filename> Loads the map again to build cubemaps for the new mode
sv_cheats 1
buildcubemaps Starts building cubemaps for the new mode
disconnect
mat_specular 1 Enables specularity. Required to see reflections
mat_hdr_level 0/1/2 If necessary, switches back to the mode it was before having submitted mat_hdr_level 0/2
quit (optional) Closes the game. Required to see reflections after building cubemaps


Half-Life: Source

Icon-Bug.pngBug:Cubemaps in Half-Life: Source Half-Life: Source don't currently build properly as their textures, despite being generated, aren't saved into the BSP file afterward.  [todo tested in ?]
PlacementTip.pngWorkaround:Move the BSP file into the "maps" folder of a game of the same engine branch (such as Half-Life 2 Half-Life 2), build the cubemaps in said game, then move the file back into Half-Life: Source's.


Source Filmmaker

Icon-Bug.pngBug:Cubemaps in Source Filmmaker Source Filmmaker don't currently build properly as their textures are generated blankly.  [todo tested in ?]
PlacementTip.pngWorkaround:Move the BSP file into Alien Swarm Alien Swarm's "maps" folder, build the cubemaps in that game, then move the file back into Source Filmmaker's.
Note.pngNote:For this procedure, Alien Swarm's "gameinfo.txt" file will need to be edited to use assets from Source Filmmaker's mod directories not to build cubemaps with missing textures/models. The file's "SearchPath" section should look like this:
"SearchPaths"
{
	"Game"	"|gameinfo_path|."
	"Game"	"swarm_base"
	"Game"	"platform"
	"Game" "..\SourceFilmmaker\game\hl2"
	"Game" "..\SourceFilmmaker\game\tf"
	"Game" "..\SourceFilmmaker\game\tf_movies"
	"Game" "..\SourceFilmmaker\game\usermod"
}

Deleting cubemaps

Deleting cubemaps is useful to get rid of unnecessary or outdated ones and their associated files. Out of all other capable tools, BSPZIP is the safest way for doing so without potentially corrupting the map; from the "maps" folder where the BSP is located, execute the following command:

..\..\bin\bspzip -deletecubemaps mapname.bsp
Note.pngNote:Replace "mapname" with the map's actual filename.
Warning.pngWarning:Cubemaps should be deleted before embedding texture (".vtf") files into the BSP file as this procedure actually deletes all the texture files in it.

Extracting cubemaps

In cases where a map needs to be updated (recompiled) with minor changes and its built cubemaps vanish as a result, extracting said cubemaps beforehand will make it not necessary to go through the whole cubemap-building process again until it actually becomes so. Create a folder that will contain the extracted cubemaps within the "maps" folder and execute the following command:

..\..\bin\bspzip -extractcubemaps mapname.bsp "foldername"
Note.pngNote:Replace "mapname" with the map's actual filename, and "foldername" with the actual name of the folder to extract cubemaps into.


Embedding cubemaps

To make use of extracted cubemaps, create a text file that will include the directory structure to use within the BSP file and the path to the file(s) to embed with BSPZIP. Here's an example of "packlist_mymap.txt" (the text file can be named anyhow; its name will later be referenced in BSPZIP):

materials/maps/mapname/c0_416_64.hdr.vtf
foldername\materials\maps\mapname\c0_416_64.hdr.vtf
materials/maps/mapname/c0_416_64.vtf
foldername\materials\maps\mapname\c0_416_64.vtf
materials/maps/mapname/c416_0_64.hdr.vtf
foldername\materials\maps\mapname\c416_0_64.hdr.vtf
materials/maps/mapname/c-416_0_64.hdr.vtf
foldername\materials\maps\mapname\c-416_0_64.hdr.vtf
materials/maps/mapname/c416_0_64.vtf
foldername\materials\maps\mapname\c416_0_64.vtf
materials/maps/mapname/c-416_0_64.vtf
foldername\materials\maps\mapname\c-416_0_64.vtf
materials/maps/mapname/cubemapdefault.vtf
foldername\materials\maps\mapname\cubemapdefault.vtf
Note.pngNote:Replace "mapname" with the map's actual filename, and "foldername" with the actual name of the folder that contains the extracted cubemaps.

Each file requires two dedicated lines (paths); the first line represents the structure of the directory that the file will use in the BSP file (always basing from the game's subfolder), while the second one is the actual location of the file to find and embed. The second line in this example used a relative path (considering that the text file is located inside the "maps" folder, alongside the folder that contains the cubemaps), but it can also be absolute. After the text file is created, execute the following command:

..\..\bin\bspzip -addlist mapname.bsp textfile.txt newmapname.bsp
Note.pngNote:Replace "mapname" with the map's actual filename, "textfile" with the text file's actual filename, and "newmapname" with the map's actual filename to override it (or type in a different filename to generate an additional BSP file).

Renaming a map

Built cubemaps are saved into a directory within the BSP file, with the directory sharing its name; changing the name of the BSP will cause cubemaps not to load alongside the map, and therefore it will act as if there were none. To correct that, either delete then rebuild cubemaps, or extract then repack (embed) them with a matching map name in the cubemaps' directory.

See also