Cubemaps: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(not anymore)
m (Minor improvements)
Line 1: Line 1:
{{lang|Cubemaps}}
{{lang|Cubemaps}}
[[Image:Env_cubemap.png|left]][[Image:Specular.jpg|thumb|300px|right|Models with specular reflections.]]
[[Image:Env_cubemap.png|left]][[Image:Specular.jpg|thumb|300px|right|Models with specular reflections.]]
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.
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 for generating these textures, which are then saved into the [[BSP|map]] file. Once [[#Building cubemaps|built]], cubemaps will be reflected on surfaces that use the [[$envmap]] parameter with ''env_cubemap'' as its value.




== Building 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.
Building cubemaps is the process of generating their textures for reflective effects. For technical reasons, this process is not automated and should be done by the user; until then, '''env_cubemaps''' will remain unused and the map, depending on the game, will display either generic or "missing" textures on reflections 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).}}
{{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 fail 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|It's necessary to relaunch the game after building cubemaps in order to display them.}}
{{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).}}
{{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).}}
Line 12: Line 12:


=== Before building ===
=== 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]].
{{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 delete them first 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]] only.}}
{{note|This step doesn't 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:
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"
{| class="wikitable"
Line 74: Line 74:


=== Half-Life: Source ===
=== 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.}}
{{bug|Cubemaps in {{hls}} '''Half-Life: Source''' currently don't build properly as their textures, despite being generated, aren't saved into the map 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.}}
:{{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 that game, then move the file back into '''Half-Life: Source'''<nowiki>'</nowiki>s.}}




=== Source Filmmaker ===
=== Source Filmmaker ===
{{bug|Cubemaps in {{sfm}} '''Source Filmmaker''' don't currently build properly as their textures are generated blankly.}}
{{bug|In {{sfm}} '''Source Filmmaker''', loading a map whose cubemaps were built in another game will display weird artifacts on reflections due to a sixth cubemap face that it doesn't seem to recognize (it uses only five of them). Rebuilding the cubemaps would fix the issue, but '''Source Filmmaker''' currently doesn't properly build cubemaps as their textures are generated blank.}}
:{{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.}}
:{{workaround|Move the '''BSP''' file into {{as}} '''Alien Swarm'''<nowiki>'</nowiki>s "maps" folder, build the cubemaps in said game, then move the file back into '''Source Filmmaker'''<nowiki>'</nowiki>s.}}
::{{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:}}
::{{note|For this procedure, '''Alien Swarm'''<nowiki>'</nowiki>s "gameinfo.txt" file will need to be edited to have access to assets from the mod directories within '''Source Filmmaker''' not to build cubemaps with missing textures/models. The file's "SearchPath" section should look like this:}}
  "SearchPaths"
  "SearchPaths"
  {
  {
Line 93: Line 93:
  }
  }
== Deleting cubemaps ==
== 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:
Deleting cubemaps gets 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''' file should be located), execute the following command:
  ..\..\bin\bspzip -deletecubemaps mapname.bsp
  ..\..\bin\bspzip -deletecubemaps mapname.bsp
{{note|Replace "''mapname''" with the map's actual filename.}}
{{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.}}
{{warning|Cubemaps should be deleted before embedding texture ("[[Valve Texture Format|.vtf]]") files into the map file as this procedure actually deletes all of its embedded textures.}}
== Extracting cubemaps ==
== 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:
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:
Line 104: Line 104:


=== Embedding cubemaps ===
=== 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'''):
To make a map use extracted cubemaps, create a text file within the '''BSP''' file's location that will include paths to the cubemap textures to embed into it with the use of '''BSPZIP'''. Here's how such a file should look like:
  materials/maps/mapname/c0_416_64.hdr.vtf
  materials/maps/mapname/c0_416_64.hdr.vtf
  '''foldername\materials\maps\mapname\c0_416_64.hdr.vtf'''
  '''foldername\materials\maps\mapname\c0_416_64.hdr.vtf'''
Line 120: Line 120:
  '''foldername\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.}}
{{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:
Two lines (paths) are required per file; the first line represents the directory structure that the file will take within the map file, while the second one is the actual path to the file to find and embed. In this example, the second lines use a relative path (considering that the text file is in the same directory as the folder with extracted cubemaps), though it can also be absolute. Once the text file is ready, execute the following comand:
  ..\..\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 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).}}
{{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 one to generate an additional '''BSP''' file without overwriting the original).}}
== Renaming a map ==
== 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.
The map's name is used for the directory where built cubemaps are saved into within the file; changing its name will cause the cubemaps not to load alongside the map, and therefore it will act as if there were none. To correct that, either delete and then rebuild the cubemaps, or extract and then repack (embed) them with the cubemaps' directory matching the map's new name.
== See also ==
== See also ==
* [[env_cubemap]]
* [[env_cubemap]]
* [[$envmap]]
* [[$envmap]]
[[Category:Level Design]]
[[Category:Level Design]]

Revision as of 11:06, 15 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_cubemap entities as sampling points for generating these textures, which are then saved into the map file. Once built, cubemaps will be 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 for reflective effects. For technical reasons, this process is not automated and should be done by the user; until then, env_cubemaps will remain unused and the map, depending on the game, will display either generic or "missing" textures on reflections 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 fail 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: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 delete them first as explained here.


LDR

Note.pngNote:This step doesn't 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 currently don't build properly as their textures, despite being generated, aren't saved into the map 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 that game, then move the file back into Half-Life: Source's.


Source Filmmaker

Icon-Bug.pngBug:In Source Filmmaker Source Filmmaker, loading a map whose cubemaps were built in another game will display weird artifacts on reflections due to a sixth cubemap face that it doesn't seem to recognize (it uses only five of them). Rebuilding the cubemaps would fix the issue, but Source Filmmaker currently doesn't properly build cubemaps as their textures are generated blank.  [todo tested in ?]
PlacementTip.pngWorkaround:Move the BSP file into Alien Swarm Alien Swarm's "maps" folder, build the cubemaps in said 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 have access to assets from the mod directories within Source Filmmaker 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 gets 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 file should be 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 map file as this procedure actually deletes all of its embedded textures.

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 a map use extracted cubemaps, create a text file within the BSP file's location that will include paths to the cubemap textures to embed into it with the use of BSPZIP. Here's how such a file should look like:

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.

Two lines (paths) are required per file; the first line represents the directory structure that the file will take within the map file, while the second one is the actual path to the file to find and embed. In this example, the second lines use a relative path (considering that the text file is in the same directory as the folder with extracted cubemaps), though it can also be absolute. Once the text file is ready, execute the following comand:

..\..\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 one to generate an additional BSP file without overwriting the original).

Renaming a map

The map's name is used for the directory where built cubemaps are saved into within the file; changing its name will cause the cubemaps not to load alongside the map, and therefore it will act as if there were none. To correct that, either delete and then rebuild the cubemaps, or extract and then repack (embed) them with the cubemaps' directory matching the map's new name.

See also