Template:Archived Page History/Cubemaps/en: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
m (Cleanup and improvements)
Line 1: Line 1:
{{langsp}}
{{langsp}}
[[File:Env_cubemap.png|left]]
[[File:Env_cubemap.png|left]]
[[File:Specular.jpg|thumb|right|300px|Specular reflections on props<br>(exaggerated using {{ent|r_showenvcubemap}})]]
[[File:Specular.jpg|thumb|right|300px|Exaggerated specular reflections on props]]
A '''cubemap''' is a texture that represents a three-dimensional rendering of an area. The [[Source|Source Engine]] uses [[env_cubemap]] entities as sampling points to generate these textures, which are then automatically embedded into the [[BSP|map file]]. Cubemaps, when [[#Building cubemaps|built]], are reflected on surfaces that use the [[$envmap]] parameter (with ''env_cubemap'' as its value). If a map does not have any [[env_cubemap]] entities present, the game will use the default cubemap instead, located in {{path|materials/engine/defaultcubemap.vtf}}.
A '''cubemap''' is a texture that represents a three-dimensional rendering of an area. The [[Source|Source Engine]] uses [[env_cubemap]] entities as sampling points to generate these textures, which are then automatically embedded into the [[BSP|map file]]. Cubemaps, when [[#Building cubemaps|built]], are reflected on surfaces that use the [[$envmap]] parameter (with ''env_cubemap'' as its value). If a map does not have any [[env_cubemap]] entities present, the game will instead use a generic texture that does not reflect the map.




== Building cubemaps ==
== Building cubemaps ==
{{todo|Document {{ent|building_cubemaps}} cvar. Seems to disable bloom while HDR is enabled? No apparent function in SDR mode. It resets to 0 after cubemaps are built.}}
Building cubemaps is the process of generating their textures to then use them as reflections. For technical reasons, this process is not 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 generic or "missing" textures as reflections due to nonexistent cubemaps.
Building cubemaps is the process of generating their textures to then use them as reflections. For technical reasons, this process is not automated and is up to the user to do so; until then, existing '''env_cubemaps''' will remain unused and the map, depending on the game, will display either generic or "missing" textures as reflections due to nonexistent cubemaps.
{{warning|For people with epilepsy: building cubemaps on games running on Vulkan, like {{l4d2}}'''Left 4 Dead 2''', causes the screen to violently flash black and white.}}
{{warning|To build cubemaps, your game's screen resolution needs to be at least 4 times higher than the highest [[env cubemap#Keyvalues|size]] of an existing '''env_cubemap''', or else attempting to build them will either fail or even cause the game to crash. For example: if the highest '''env_cubemap''' sizes 128x128, a resolution of 512x512 will be needed. (''128 &times; 4 &#61; '''512''' -&gt; 720x576 or higher'')}}
{{warning|To build cubemaps, your game's screen resolution needs to be at least 4 times higher than the highest [[env cubemap#Keyvalues|size]] of an existing '''env_cubemap''', or else attempting to build them will either fail or even cause the game to crash. For example, if the highest '''env_cubemap''' sizes 128x128, a resolution no smaller than 512x512 will be needed. (''128 &times; 4 &#61; '''512''' -&gt; 720x576'' (as a valid resolution) or higher)}}
{{note|Newly-built cubemaps will display after clearing the texture cache, which is easily done with one of the following methods: Either by relaunching the game, by changing aspect ratios or by loading a different map followed by loading your map again.}}
{{note|The game may appear to freeze or become unresponsive during the cubemap-building process, and the length of said process depends on various factors. For successful results, don't switch away from the game until it's done.}}
{{note|It's possible the game may appear to freeze during building of cubemaps. But it keeps on building cubemaps in the background. Be patient and do not close the game, or unfocus the game (Alt-Tabbing) as it may cause the game to crash. }}
{{tip|Maxing out the game's visual settings before building cubemaps will generate their textures in the best-possible quality for the '''env_cubemaps'''<nowiki>'</nowiki> size.}}
{{tip|The <code>buildcubemaps</code> command optionally accepts the number of iterations to perform. For example, <code>buildcubemaps 2</code> will build cubemaps twice. This is useful when recursive reflections are needed to look correct, e.g. two buildings reflecting each other.
{{tip|The <code>buildcubemaps</code> command optionally accepts the number of iterations to perform. For example, <code>buildcubemaps 2</code> will build cubemaps twice. This is useful when recursive reflections are needed to look correct, e.g. two buildings reflecting each other.
{{Bug|Currently in {{p2ce}}, this does not work properly. To work around this, run buildcubemaps, let the map reload, then run the command again.}}}}
{{bug|This command doesn't currently work in {{p2ce}}'''Portal 2: Community Edition'''.
{{warning|Games running on Vulkan, like {{l4d2}}, will not pause the screen during building cubemaps, but the screen will violently flash black and white. But you must not alt tab out of this process to stop the flashing. If you are prone to epileptic seizures you should either look away or walk away from the computer.}}
{{workaround|Run the <code>buildcubemaps</code> command, reload the map, then run the command again.}}}}}}
{{warning|If you had used the command <code>Nav_Show_Ladder_Bounds</code> before building a cubemap, the green boxes will also be baked into the cubemap.}}
{{warning|If the <code>Nav_Show_Ladder_Bounds</code> command was used before building cubemaps, the green boxes will also be baked into the cubemap.}}
{{note|Lights enable sprite that use texture <code>engine/lightsprite</code> while building cubemaps. Only in {{Strata|4}} games you can disable sprite manually for each light (by default sprite is disabled in {{Strata|4}} games). To remove this sprite in other games you'll need to rewrite <code>.vmt</code> of the texture.}}
 
 
=== Before building ===
=== Before building ===
{{tip|Maps for {{src13|4.1}} games such as {{css}} and some other games are known for including pre-built, blank cubemaps after being compiled (even if there are no '''env_cubemaps''' in them). It is recommended to delete these cubemaps before building new ones, as explained [[#Deleting cubemaps|here]].}}
{{tip|Maps for {{src13|4.1}} games and others, such as {{css}}'''Counter-Strike: Source''', are known to include pre-built, blank cubemaps after being compiled (even if there are no '''env_cubemap''' entities in them). It is recommended to first delete these cubemaps before building new ones, as detailed [[#Deleting cubemaps|here]].}}
{{tip|It is recommended that you disable any addons (especially on {{gmod|4}}) prior to building cubemaps for both LDR and HDR, as it will significantly speeds up loading times.}}
{{tip|Maxing out the game's visual settings before building cubemaps will generate their textures in the best-possible quality for the '''env_cubemaps'''<nowiki>'</nowiki> size.}}
 


=== LDR ===
=== LDR ===
{{note|This step does not apply to {{l4d}} '''Left 4 Dead''' and {{csgo}}'''Counter-Strike: Global Offensive''' as its maps are compiled in [[#HDR|HDR mode]] only.}}
{{note|This step does not apply to {{l4d}}'''Left 4 Dead''' nor {{csgo}}'''Counter-Strike: Global Offensive''' as their maps are compiled in [[#HDR|HDR mode]] only.}}
Building cubemaps on 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:
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:
{| class="wikitable"
{| class="wikitable"
|-
|-
! Command !! Description
! Command !! Description
|-
|-
| <code>mat_specular 0</code> || Disables reflections. Required to properly build cubemaps
| <code>mat_specular 0</code> || Turns reflections Off; required to properly build cubemaps
|-
|-
| <code>map ''cs_mymap''</code> || Loads a map; replace "''cs_mymap''" with the map's actual name
| <code>map ''map_name''</code> || Loads a map; replace "''map_name''" with the map's actual name
|-
|-
| <code>sv_cheats 1</code> || Enables the use of cheat commands. Required to build cubemaps
| <code>sv_cheats 1</code> || Enables the use of cheat commands; required to build cubemaps
|-
|-
| <code>buildcubemaps</code> || Starts building cubemaps. Optionally, specify the number of iterations (default is 1)
| <code>buildcubemaps</code> || Begins building cubemaps. Optionally, specify the number of iterations (e.g.: <code>buildcubemaps 2</code> (default is 1))
|-
|-
| <code>disconnect</code> || Unloads the map, returning you to the main menu
| <code>disconnect</code> || Unloads the map, returning to the main menu
|-
|-
| <code>mat_specular 1</code> || Enables reflections
| <code>mat_specular 1</code> || Turns reflections On
|-
|-
| <code>quit</code> || (optional) Closes the game. Relaunching it is required to display newly-built cubemaps
| <code>quit</code> || (optional) Exits the game. Relaunching it is required to display newly-built cubemaps
|}
|}


=== HDR ===
=== HDR ===
Building cubemaps on a map compiled with [[HDR]] support needs to be done twice - once for each mode ('''HDR''' and '''LDR'''). As opposed to a '''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. To build the cubemaps, submit the following commands into the game's console:
Building cubemaps in 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. To build the cubemaps, submit the following commands into the game's console:
{| class="wikitable"
{| class="wikitable"
|-
|-
! Command !! Description
! Command !! Description
|-
|-
| <code>mat_specular 0</code> || Disables reflections. Required to properly build cubemaps
| <code>mat_specular 0</code> || Turns reflections Off; required to properly build cubemaps
|-
|-
| <code>map ''cs_mymap''</code> || Loads a map; replace "''cs_mymap''" with the map's actual name
| <code>map ''map_name''</code> || Loads a map; replace "''map_name''" with the map's actual name
|-
|-
| <code>sv_cheats 1</code> || Enables the use of cheat commands. Required to build cubemaps
| <code>sv_cheats 1</code> || Enables the use of cheat commands; required to build cubemaps
|-
|-
| <code>buildcubemaps</code> || Starts building cubemaps. Optionally, specify the number of iterations (default is 1)
| <code>buildcubemaps</code> || Begins building cubemaps. Optionally, specify the number of iterations (e.g.: <code>buildcubemaps 2</code> (default is 1))
|-
|-
| <code>disconnect</code> || Unloads the map, returning you to the main menu
| <code>disconnect</code> || Unloads the map, returning to the main menu
|-
|-
| <code>sv_cheats 0</code> || Disables cheat commands. Prevents command <code>''mat_reloadallmaterials''</code> from unnecessarily self-executing and briefly freezing the game
| <code>sv_cheats 0</code> || Disables cheat commands; prevents command <code>''mat_reloadallmaterials''</code> from unnecessarily self-executing, which briefly freezes the game
|-
|-
| <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>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 ''cs_mymap''</code> || Loads the map again to build cubemaps for the new mode
| <code>map ''map_name''</code> || Loads the map again to build cubemaps for the new mode
|-
|-
| <code>sv_cheats 1</code> ||
| <code>sv_cheats 1</code> ||
|-
|-
| <code>buildcubemaps</code> || Starts building cubemaps for the new mode. Optionally, specify the number of iterations (default is 1)
| <code>buildcubemaps</code> || Begins building cubemaps for the new mode
|-
|-
| <code>disconnect</code> ||
| <code>disconnect</code> ||
|-
|-
| <code>mat_specular 1</code> || Enables reflections
| <code>mat_specular 1</code> || Turns reflections On
|-
|-
| <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>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. Relaunching it is required to display newly-built cubemaps
| <code>quit</code> || (optional) Exits the game. Relaunching it is required to display newly-built cubemaps
|}
|}
== Required procedure for specific games ==
=== Black Mesa: Source ===
To build cubemaps in {{bms}}'''Black Mesa: Source''' maps, the game has to be launched with these parameters: <code>-oldgameui -dev -console +r_4way_use_fast_normals 0 +mat_specular 0</code><br>Then, submit the <code>buildcubemaps</code> command into the console.




=== Half-Life: Source ===
=== Half-Life: Source ===
{{bug|Building cubemaps in {{hls}}'''Half-Life: Source''' is currently not possible as their textures, despite being generated, aren't embedded into the map file afterward.
{{bug|Building cubemaps in {{hls}}'''Half-Life: Source''' is currently not possible as their textures, despite being generated, aren't embedded into the map file afterward.
{{workaround|Move the map file into the "maps" folder of a game of the same engine branch (such as {{hl2}}'''Half-Life 2'''), build its cubemaps in that game, then move the file back into '''Half-Life: Source'''<nowiki>'</nowiki>s folder.}}}}
{{workaround|Move the map file into the {{path|maps}} folder of a game of the same engine branch (such as {{hl2}}'''Half-Life 2'''), build its cubemaps in that game, then move the file back into '''Half-Life: Source'''<nowiki>'</nowiki>s folder.}}}}
 
 


=== Portal 2 ===
=== Portal 2 ===
{{bug|Building cubemaps in {{portal2}}'''Portal 2''' will fail if the BSP is not in the highest-numbered DLC folder (dlc2 by default).
{{bug|Building cubemaps in {{portal2}}'''Portal 2''' will fail if the '''BSP''' is not in the highest-numbered DLC folder ({{path|dlc2}} by default).
{{workaround|Either manually move the map there first, edit the "'''place compiled maps in this directory before running the game'''" option in the [[Hammer_Build_Programs|Build Programs]] options tab to do so automatically, or create a {{path|portal2_dlc3}} folder, create a {{path|maps}} folder in that folder, and put all your custom maps in there. The game will automatically recognize the dlc3 folder, so no gameinfo editing is necessary}}}}
{{workaround|Either manually move the map there first, edit the "'''Place compiled maps in this directory before running the game'''" option in the [[Hammer Build Programs|Build Programs]] options tab to do so automatically, or create a {{path|portal2_dlc3}} folder, create a {{path|maps}} folder in that folder, and put all your custom maps in there.}}}}
 


===Black Mesa===
To build a cubemaps in [[Black Mesa: Source|Black Mesa]], run the game with these parameters ''bms.exe -oldgameui -dev -console +r_4way_use_fast_normals 0 +mat_specular 0''<br>
Launch your map, then enter '''buildcubemaps''' in console.


=== Source Filmmaker ===
=== Source Filmmaker ===
[[File:Cubemap_bug_sfm.jpg|thumb|right|300px|Improper rendering of an HDR cubemap's face in Source Filmmaker.]]
[[File:Cubemap_bug_sfm.jpg|thumb|right|300px|Improper rendering of an HDR cubemap's face in Source Filmmaker.]]
{{bug|'''HDR''' cubemaps sizing lower than 128x128 built in {{tf2}}'''Team Fortress 2''' and some other games usually display graphical artifacts on reflections due to the last face of each cubemap not rendering properly in {{sfm}}'''Source Filmmaker'''. While rebuilding cubemaps in it would normally fix the issue, it is currently not possible to do so as '''Source Filmmaker''' generates blank textures.}}
{{bug|'''HDR''' cubemaps sizing lower than 64x64 built in {{tf2}}'''Team Fortress 2''' and some other games usually display graphical artifacts on reflections due to the last face of each cubemap not rendering properly in {{sfm}}'''Source Filmmaker'''. While rebuilding cubemaps in it would normally fix the issue, it is currently not possible to do so as '''Source Filmmaker''' generates blank textures.}}
{{workaround|If recompiling a special version of an affected map with '''env_cubemaps''' now sizing 128x128 is not an option, move the map file into {{as}}'''Alien Swarm'''<nowiki>'</nowiki>s "maps" folder, build its cubemaps in that game, then move the file back into '''Source Filmmaker'''<nowiki>'</nowiki>s folder.}}
{{workaround|If recompiling a special version of an affected map with '''env_cubemaps''' now sizing 64x64 (or higher) is not an option, move the map file into {{as}}'''Alien Swarm'''<nowiki>'</nowiki>s "maps" folder, build its cubemaps in that game, then move the file back into '''Source Filmmaker'''<nowiki>'</nowiki>s folder.}}
{{note|'''Alien Swarm'''<nowiki>'</nowiki>s "gameinfo.txt" file needs to be edited for this procedure so that the game can have access to assets used by other games' maps not to build cubemaps with missing textures or models. The file's "SearchPaths" section should be like this:}}
{{note|'''Alien Swarm'''<nowiki>'</nowiki>s "gameinfo.txt" file needs to be modified for this procedure so that the game can have access to assets used by other games' maps not to build cubemaps with missing textures or models. The file's "SearchPaths" section should look like this:}}
  "SearchPaths"
  "SearchPaths"
  {
  {
Line 108: Line 112:
  }
  }
{{note|{{tf2}}'''Team Fortress 2''' configurations were used for the example; consider replacing game subfolders (only those within '''Source Filmmaker''' paths) with the ones needed.}}
{{note|{{tf2}}'''Team Fortress 2''' configurations were used for the example; consider replacing game subfolders (only those within '''Source Filmmaker''' paths) with the ones needed.}}
{{workaround|Another option is to manually remove the [[$envmapsphere|sphere map]] (face 7) from the existing HDR cubemap textures. See [[$envmap#Creating_a_custom_static_cubemap_texture|creating a custom static cubemap texture]] for more info.
{{workaround|Another option is to manually remove the [[$envmapsphere|sphere map]] (face #7) from the existing HDR cubemap textures. See [[$envmap#Creating a custom static cubemap texture|Creating a custom static cubemap texture]] for more info.<br>Alternatively, deleting the affected HDR cubemap texture files will cause the LDR versions to be used, which do not suffer from this bug.}}
Alternatively, deleting the affected HDR cubemap texture files will cause the LDR versions to be used, which do not suffer from this bug.}}


== Deleting cubemaps ==
== Deleting cubemaps ==
Several tools make it possible to delete unnecessary or outdated cubemaps; of them all, [[BSPZIP]] not only is an official one, but is also the easiest and safest option for this procedure without potentially corrupting the map. To delete the cubemaps, execute the following command within the "maps" folder:
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 due to misuse. To delete cubemaps, execute the following command within the {{path|maps}} folder:
  ..\..\bin\bspzip -deletecubemaps mapname.bsp
  ..\..\bin\bspzip -deletecubemaps map_name.bsp
{{note|Replace "''mapname''" with the map's actual name.}}
{{note|Replace "''map_name''" with the map's actual name.}}
{{warning|Deleting cubemaps actually deletes all the texture ("[[Valve Texture Format|.vtf]]") files embedded into the map at the time, so it's recommended not to embed custom textures before deleting cubemaps.}}
{{warning|Deleting cubemaps actually deletes all the texture ("[[Valve Texture Format|.vtf]]") files currently embedded into the map, so it's recommended not to embed custom textures before deleting cubemaps.}}
{{bug|(tested in {{src13mp}}){{code|-deletecubemaps}} may actually delete the entire PAKFILE lump, rendering the map broken! Use {{vide|4}} instead.}}
{{confirm|Deleting {{file|cubemapdefault|vtf}} and {{file|cubemapdefault.hdr|vtf}} might mess building the other cubemaps....}}


== Extracting cubemaps ==
== 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 until it actually becomes so. To extract its cubemaps with '''BSPZIP''', create a folder that will contain the extracted cubemaps inside the "maps" one, then execute the following command:
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 {{path|maps}} one, then execute the following command:
  ..\..\bin\bspzip -extractcubemaps mapname.bsp "foldername"
  ..\..\bin\bspzip -extractcubemaps map_name.bsp "foldername"
{{note|Replace "''mapname''" with the map's actual name, and "''foldername''" with the actual name of the folder to extract cubemaps into.}}
{{note|Replace "''map_name''" with the map's actual name, and "''foldername''" with the actual name of the folder to extract cubemaps into.}}




=== Embedding cubemaps ===
=== Embedding cubemaps ===
To make a map use extracted cubemaps, create a text file that will be used by '''BSPZIP''' - the file should be created inside the "maps" folder, and will contain paths to the files to embed into the map file. The file's content should be like this:
For '''BSPZIP''' to make a map use extracted cubemaps, create a text file inside the {{path|maps}} folder. The file's content should look like this:
  materials/maps/mapname/c-128_384_64.hdr.vtf
  materials/maps/map_name/c-128_384_64.hdr.vtf
  '''foldername\materials\maps\mapname\c-128_384_64.hdr.vtf'''
  '''foldername\materials\maps\map_name\c-128_384_64.hdr.vtf'''
  materials/maps/mapname/c-128_384_64.vtf
  materials/maps/map_name/c-128_384_64.vtf
  '''foldername\materials\maps\mapname\c-128_384_64.vtf'''
  '''foldername\materials\maps\map_name\c-128_384_64.vtf'''
  materials/maps/mapname/c448_-256_64.hdr.vtf
  materials/maps/map_name/c448_-256_64.hdr.vtf
  '''foldername\materials\maps\mapname\c448_-256_64.hdr.vtf'''
  '''foldername\materials\maps\map_name\c448_-256_64.hdr.vtf'''
  materials/maps/mapname/c448_-256_64.vtf
  materials/maps/map_name/c448_-256_64.vtf
  '''foldername\materials\maps\mapname\c448_-256_64.vtf'''
  '''foldername\materials\maps\map_name\c448_-256_64.vtf'''
  materials/maps/mapname/cubemapdefault.vtf
  materials/maps/map_name/cubemapdefault.vtf
  '''foldername\materials\maps\mapname\cubemapdefault.vtf'''
  '''foldername\materials\maps\map_name\cubemapdefault.vtf'''
{{note|Replace "''mapname''" with the map's actual name, the cubemaps' filenames with correct ones, and "''foldername''" with the actual name of the folder that contains the extracted cubemaps.}}
{{note|Replace "''map_name''" with the map's actual name, the cubemaps' filenames with correct ones, and "''foldername''" with the actual name of the folder that contains the extracted cubemaps.}}
A file requires two dedicated lines (paths): the first line represents the path it will use within the map file, while 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:
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 mapname.bsp textfile.txt newmapname.bsp
  ..\..\bin\bspzip -addlist map_name.bsp textfile.txt newmap_name.bsp
{{note|Replace "''mapname''" with the map's actual name, "''textfile''" with the text file's actual name, and "''newmapname''" with either the map's actual name, or a new name not to overwrite the original file (and instead create a separate one).}}
{{note|Replace "''map_name''" with the map's actual name, "''textfile''" with the text file's actual name, and "''newmap_name''" with either the map's actual name, or a new name not to overwrite the original file (and instead create a separate one).}}
 
== Renaming a map ==
== Renaming a map ==
Built cubemaps are saved into a folder within the map file that uses its name; renaming it will cause the cubemaps not to load alongside the map, and therefore it will act as if there were none. To fix that, either delete then rebuild the cubemaps, or extract then embed them back (with their folder's name matching that of the 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 the folder within it, 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.
{{todo|Ficool2 has a tool that can automate this.}}


== See also ==
== See also ==

Revision as of 04:00, 22 February 2024

Flag-white.pngEnglish (en)
Env cubemap.png
Exaggerated specular reflections on props

A cubemap is a texture that represents a three-dimensional rendering of an area. The Source Engine uses env_cubemap entities as sampling points to generate these textures, which are then automatically embedded into the map file. Cubemaps, when built, are reflected on surfaces that use the $envmap parameter (with env_cubemap as its value). If a map does not have any env_cubemap entities present, the game will instead use a generic texture that does not reflect the map.


Building cubemaps

Building cubemaps is the process of generating their textures to then use them as reflections. For technical reasons, this process is not 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 generic or "missing" textures as reflections due to nonexistent cubemaps.

Warning.pngWarning:For people with epilepsy: building cubemaps on games running on Vulkan, like Left 4 Dead 2Left 4 Dead 2, causes the screen to violently flash black and white.
Warning.pngWarning:To build cubemaps, your game's screen resolution needs to be at least 4 times higher than the highest size of an existing env_cubemap, or else attempting to build them will either fail or even cause the game to crash. For example, if the highest env_cubemap sizes 128x128, a resolution no smaller than 512x512 will be needed. (128 × 4 = 512 -> 720x576 (as a valid resolution) or higher)
Note.pngNote:The game may appear to freeze or become unresponsive during the cubemap-building process, and the length of said process depends on various factors. For successful results, don't switch away from the game until it's done.
Tip.pngTip:The buildcubemaps command optionally accepts the number of iterations to perform. For example, buildcubemaps 2 will build cubemaps twice. This is useful when recursive reflections are needed to look correct, e.g. two buildings reflecting each other.
Icon-Bug.pngBug:This command doesn't currently work in Portal 2: Community EditionPortal 2: Community Edition.
PlacementTip.pngWorkaround:Run the buildcubemaps command, reload the map, then run the command again.
  [todo tested in ?]
Warning.pngWarning:If the Nav_Show_Ladder_Bounds command was used before building cubemaps, the green boxes will also be baked into the cubemap.


Before building

Tip.pngTip:Maps for Source 2013 Source 2013 games and others, such as Counter-Strike: SourceCounter-Strike: Source, are known to include pre-built, blank cubemaps after being compiled (even if there are no env_cubemap entities in them). It is recommended to first delete these cubemaps before building new ones, as detailed here.
Tip.pngTip:Maxing out the game's visual settings before building cubemaps will generate their textures in the best-possible quality for the env_cubemaps' size.


LDR

Note.pngNote:This step does not apply to Left 4 DeadLeft 4 Dead nor Counter-Strike: Global OffensiveCounter-Strike: Global Offensive as their maps are compiled in HDR mode only.

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
mat_specular 0 Turns reflections Off; required to properly build cubemaps
map map_name Loads a map; replace "map_name" with the map's actual name
sv_cheats 1 Enables the use of cheat commands; required to build cubemaps
buildcubemaps Begins building cubemaps. Optionally, specify the number of iterations (e.g.: buildcubemaps 2 (default is 1))
disconnect Unloads the map, returning to the main menu
mat_specular 1 Turns reflections On
quit (optional) Exits the game. Relaunching it is required to display newly-built cubemaps

HDR

Building cubemaps in 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. To build the cubemaps, submit the following commands into the game's console:

Command Description
mat_specular 0 Turns reflections Off; required to properly build cubemaps
map map_name Loads a map; replace "map_name" with the map's actual name
sv_cheats 1 Enables the use of cheat commands; required to build cubemaps
buildcubemaps Begins building cubemaps. Optionally, specify the number of iterations (e.g.: buildcubemaps 2 (default is 1))
disconnect Unloads the map, returning to the main menu
sv_cheats 0 Disables cheat commands; prevents command mat_reloadallmaterials from unnecessarily self-executing, which briefly freezes the game
mat_hdr_level 0 Switches to LDR mode (from HDR); submit mat_hdr_level 2 instead if LDR cubemaps were built first
map map_name Loads the map again to build cubemaps for the new mode
sv_cheats 1
buildcubemaps Begins building cubemaps for the new mode
disconnect
mat_specular 1 Turns reflections On
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) Exits the game. Relaunching it is required to display newly-built cubemaps

Required procedure for specific games

Black Mesa: Source

To build cubemaps in Black MesaBlack Mesa: Source maps, the game has to be launched with these parameters: -oldgameui -dev -console +r_4way_use_fast_normals 0 +mat_specular 0
Then, submit the buildcubemaps command into the console.


Half-Life: Source

Icon-Bug.pngBug:Building cubemaps in Half-Life: SourceHalf-Life: Source is currently not possible as their textures, despite being generated, aren't embedded into the map file afterward.
PlacementTip.pngWorkaround:Move the map file into the 🖿maps folder of a game of the same engine branch (such as Half-Life 2Half-Life 2), build its cubemaps in that game, then move the file back into Half-Life: Source's folder.
  [todo tested in ?]


Portal 2

Icon-Bug.pngBug:Building cubemaps in Portal 2Portal 2 will fail if the BSP is not in the highest-numbered DLC folder (🖿dlc2 by default).
PlacementTip.pngWorkaround:Either manually move the map there first, edit the "Place compiled maps in this directory before running the game" option in the Build Programs options tab to do so automatically, or create a 🖿portal2_dlc3 folder, create a 🖿maps folder in that folder, and put all your custom maps in there.
  [todo tested in ?]


Source Filmmaker

Improper rendering of an HDR cubemap's face in Source Filmmaker.
Icon-Bug.pngBug:HDR cubemaps sizing lower than 64x64 built in Team Fortress 2Team Fortress 2 and some other games usually display graphical artifacts on reflections due to the last face of each cubemap not rendering properly in Source FilmmakerSource Filmmaker. While rebuilding cubemaps in it would normally fix the issue, it is currently not possible to do so as Source Filmmaker generates blank textures.  [todo tested in ?]
PlacementTip.pngWorkaround:If recompiling a special version of an affected map with env_cubemaps now sizing 64x64 (or higher) is not an option, move the map file into Alien SwarmAlien Swarm's "maps" folder, build its cubemaps in that game, then move the file back into Source Filmmaker's folder.
Note.pngNote:Alien Swarm's "gameinfo.txt" file needs to be modified for this procedure so that the game can have access to assets used by other games' maps not to build cubemaps with missing textures or models. The file's "SearchPaths" section should look like this:
"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"
}
Note.pngNote:Team Fortress 2Team Fortress 2 configurations were used for the example; consider replacing game subfolders (only those within Source Filmmaker paths) with the ones needed.
PlacementTip.pngWorkaround:Another option is to manually remove the sphere map (face #7) from the existing HDR cubemap textures. See Creating a custom static cubemap texture for more info.
Alternatively, deleting the affected HDR cubemap texture files will cause the LDR versions to be used, which do not suffer from this bug.

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 due to misuse. To delete cubemaps, execute the following command within the 🖿maps folder:

..\..\bin\bspzip -deletecubemaps map_name.bsp
Note.pngNote:Replace "map_name" with the map's actual name.
Warning.pngWarning:Deleting cubemaps actually deletes all the texture (".vtf") files currently embedded into the map, so it's recommended not to embed custom textures before deleting cubemaps.

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 🖿maps one, then execute the following command:

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


Embedding cubemaps

For BSPZIP to make a map use extracted cubemaps, create a text file inside the 🖿maps 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
Note.pngNote:Replace "map_name" with the map's actual name, the cubemaps' filenames with correct ones, and "foldername" with the actual name of the folder that contains the extracted cubemaps.

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
Note.pngNote:Replace "map_name" with the map's actual name, "textfile" with the text file's actual name, and "newmap_name" with either the map's actual name, or a new name not to overwrite the original file (and instead create a separate one).

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 the folder within it, 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