Cubemaps: Difference between revisions
m (Added a screenshot that shows one of the most-common issues with cubemaps in Source Filmmaker) |
m (Forgot to mention that it's only HDR cubemaps that may cause problems) |
||
Line 2: | Line 2: | ||
[[Image:Env_cubemap.png|left]] | [[Image:Env_cubemap.png|left]] | ||
[[Image:Specular.jpg|thumb|right|300px|Specular reflections on props.]] | [[Image:Specular.jpg|thumb|right|300px|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. | 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). | ||
== Building cubemaps == | == Building cubemaps == | ||
Building cubemaps is the process of generating their textures to | 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|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 × 4 = '''512''' -> 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 of 512x512 will be needed. (''128 × 4 = '''512''' -> 720x576 or higher'')}} | ||
{{note|Newly-built cubemaps will display after relaunching the game.}} | {{note|Newly-built cubemaps will display after relaunching the game.}} | ||
{{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|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.}} | ||
Line 13: | Line 13: | ||
=== Before building === | === Before building === | ||
{{tip|{{css}}'''Counter-Strike: Source''' | {{tip|Maps for {{css}}'''Counter-Strike: Source''' 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]].}} | ||
=== LDR === | === LDR === | ||
{{note|This step does not apply to {{csgo}}'''Counter-Strike: Global Offensive''' as its maps are compiled in [[#HDR|HDR]] | {{note|This step does not apply to {{csgo}}'''Counter-Strike: Global Offensive''' as its 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 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: | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 35: | Line 35: | ||
| <code>mat_specular 1</code> || Enables reflections | | <code>mat_specular 1</code> || Enables reflections | ||
|- | |- | ||
| <code>quit</code> || (optional) Closes the game. Relaunching | | <code>quit</code> || (optional) Closes the game. Relaunching it is required to display newly-built cubemaps | ||
|} | |} | ||
Line 71: | Line 71: | ||
| <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 | | <code>quit</code> || (optional) Closes the game. Relaunching it is required to display newly-built cubemaps | ||
|} | |} | ||
=== Half-Life: Source === | === Half-Life: Source === | ||
{{bug|Building cubemaps in {{hls}}'''Half-Life: Source''' is currently not possible as | {{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.}} | :{{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.}} | ||
=== Source Filmmaker === | === Source Filmmaker === | ||
[[Image:Cubemap_bug_sfm.jpg|thumb|right|300px|Improper rendering of cubemap | [[Image:Cubemap_bug_sfm.jpg|thumb|right|300px|Improper rendering of an HDR cubemap's face in Source Filmmaker.]] | ||
{{bug| | {{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 | :{{workaround|If recompiling a special version of an affected map with '''env_cubemaps''' now sizing 64x64 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 | ::{{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:}} | ||
"SearchPaths" | "SearchPaths" | ||
{ | { | ||
Line 102: | Line 102: | ||
{{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 embedded into the map at the time, so it's recommended not to embed custom textures before deleting 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, | 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: | ||
..\..\bin\bspzip -extractcubemaps mapname.bsp "foldername" | ..\..\bin\bspzip -extractcubemaps mapname.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 "''mapname''" with the map's actual name, and "''foldername''" with the actual name of the folder to extract cubemaps into.}} | ||
Line 108: | Line 108: | ||
=== Embedding cubemaps === | === Embedding cubemaps === | ||
To make a map use extracted cubemaps, create a text file that will be used | 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: | ||
materials/maps/mapname/c-128_384_64.hdr.vtf | materials/maps/mapname/c-128_384_64.hdr.vtf | ||
'''foldername\materials\maps\mapname\c-128_384_64.hdr.vtf''' | '''foldername\materials\maps\mapname\c-128_384_64.hdr.vtf''' | ||
Line 119: | Line 119: | ||
materials/maps/mapname/cubemapdefault.vtf | materials/maps/mapname/cubemapdefault.vtf | ||
'''foldername\materials\maps\mapname\cubemapdefault.vtf''' | '''foldername\materials\maps\mapname\cubemapdefault.vtf''' | ||
{{note|Replace "''mapname''" with the map's actual name, the cubemaps' | {{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.}} | ||
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, 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: | ||
..\..\bin\bspzip -addlist mapname.bsp textfile.txt newmapname.bsp | ..\..\bin\bspzip -addlist mapname.bsp textfile.txt newmapname.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 "''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).}} | ||
== Renaming a map == | == Renaming a map == | ||
Built cubemaps are saved into a folder within the map file that uses | 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). | ||
== See also == | == See also == | ||
* [[env_cubemap]] | * [[env_cubemap]] | ||
* [[$envmap]] | * [[$envmap]] | ||
[[Category:Level Design]] | [[Category:Level Design]] |
Revision as of 08:30, 1 December 2020
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).
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_cubemaps will remain unused and the map, depending on the game, will display either generic or "missing" textures as reflections due to nonexistent cubemaps.



Before building


LDR


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:
Command | Description |
---|---|
mat_specular 0 |
Disables reflections. Required to properly build cubemaps |
map cs_mymap |
Loads a map; replace "cs_mymap" with the map's actual name |
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 reflections |
quit |
(optional) Closes the game. Relaunching it is required to display newly-built cubemaps |
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:
Command | Description |
---|---|
mat_specular 0 |
Disables reflections. Required to properly build cubemaps |
map cs_mymap |
Loads a map; replace "cs_mymap" with the map's actual name |
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 |
sv_cheats 0 |
Disables cheat commands. Prevents command mat_reloadallmaterials from unnecessarily self-executing and briefly freezing 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 cs_mymap |
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 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. Relaunching it is required to display newly-built cubemaps |
Half-Life: Source


Source Filmmaker



Workaround:If recompiling a special version of an affected map with env_cubemaps now sizing 64x64 is not an option, move the map file into
Alien Swarm's "maps" folder, build its cubemaps in that game, then move the file back into Source Filmmaker's folder.
Note:Alien Swarm'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:
"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
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:
..\..\bin\bspzip -deletecubemaps mapname.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 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:
..\..\bin\bspzip -extractcubemaps mapname.bsp "foldername"

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:
materials/maps/mapname/c-128_384_64.hdr.vtf foldername\materials\maps\mapname\c-128_384_64.hdr.vtf materials/maps/mapname/c-128_384_64.vtf foldername\materials\maps\mapname\c-128_384_64.vtf materials/maps/mapname/c448_-256_64.hdr.vtf foldername\materials\maps\mapname\c448_-256_64.hdr.vtf materials/maps/mapname/c448_-256_64.vtf foldername\materials\maps\mapname\c448_-256_64.vtf materials/maps/mapname/cubemapdefault.vtf foldername\materials\maps\mapname\cubemapdefault.vtf

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:
..\..\bin\bspzip -addlist mapname.bsp textfile.txt newmapname.bsp

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).