$envmap
$envmap  is a   material shader parameter  available in all  Source games.
 Source games. 
It most commonly used to approximate the specular reflections seen on smooth surfaces, such as metals, glass and plastics. This is achieved by mapping the vertex normals of a model to positions on a cubemap - specified by $envmap - and adding the sampled color from the cubemap to the model's surface. Typically, the cubemap is a simple, static "environment map" which has been pre-rendered (although a custom cubemap can be animated).
When $envmap is set to env_cubemap and buildcubemaps has been run on the map, the engine will automatically select the environment map contained in the BSP which is nearest to the model as it moves through the world, providing a very rough approximation of dynamic reflections.
The other form of specularity supported by Source is the Phong type, which provides simpler reflections on both static and dynamic models.
Availability
$envmap is available in all  Source engine based games.
 Source engine based games.
 Note:Most
Note:Most  Half-Life: Source textures use static reflective images (located in
 Half-Life: Source textures use static reflective images (located in 
environment maps folder) instead of env_cubemap by default. So if you have already built cubemaps, most of these textures will still use static reflective images, unless it's .vmt files were edited.Syntax
$envmap env_cubemap
"env_cubemap" is typically used, which tells VBSP to swap in the name of the nearest env_cubemap when the map compiles. However, it is also possible to use a static cubemap image that has been manually created.
 Note:If
Note:If $envmap is used without specifying $basetexture, the specular reflections will be force drawn regardless of anything. Note:Most Cubemap textures will have no reflectivity when used as overlays or decals. It is unclear why this is so[Clarify].
Note:Most Cubemap textures will have no reflectivity when used as overlays or decals. It is unclear why this is so[Clarify]. Note:Cubemap transparency is affected by the $basetexture alpha/transparency map even when using $envmapmask. This causes conflicting problems.
Note:Cubemap transparency is affected by the $basetexture alpha/transparency map even when using $envmapmask. This causes conflicting problems.Creating a custom static cubemap texture
Creating a custom cubemap texture might be required for some circumstances and is used occasionally in some Valve models.
 Bug:Cubemaps flagged as sRGB will only properly load as sRGB when HDR is disabled. Either include an HDR
Bug:Cubemaps flagged as sRGB will only properly load as sRGB when HDR is disabled. Either include an HDR .hdr.vtf equivalent for an sRGB-encoded SDR .vtf cubemap, or encode the SDR cubemap in regular RGB. 
 Confirm:What games can actually load SDR cubemaps in HDR mode?
 Confirm:What games can actually load SDR cubemaps in HDR mode?  handles such fine (printing warnings about missing a proper HDR cubemap in the console), but
 handles such fine (printing warnings about missing a proper HDR cubemap in the console), but  seems not be able to load SDR cubemaps in HDR mode (regardless of sRGB-ness), resulting in the surface glowing white.
 seems not be able to load SDR cubemaps in HDR mode (regardless of sRGB-ness), resulting in the surface glowing white.In VTFEdit
For this to work you will need to have the 6 sides of the cubemap saved as individual textures in the correct orientation for it to appear correctly in the Source Engine. So some faces might need to be rotated either clockwise or counter clockwise. Each face will need to be mirrored horizontally before orientation.
 Note:Pre-
Note:Pre- Alien Swarm games require 7 faces for the cubemap to work. The seventh in this case is a round texture, used as a sphere map for the (broken)
 Alien Swarm games require 7 faces for the cubemap to work. The seventh in this case is a round texture, used as a sphere map for the (broken) $envmapsphere parameter. VTFEdit can generate this face automatically, via the "Advanced" tab when importing.To the right hand side of this page you will find two guide images to aid in properly rotating each side of your environment render.
Save one or both of those guides on your computer and then import your environment render onto it or recreate it in a smaller scale, then rotate your sides as instructed by the images.
Save every side as a separate image file, their names should be the number found on that specific square. This will ensure that the environment texture will be built correctly, as the numbers also represent the import order in VTFEdit.
Once you have all the image sides ready you can just import them all into VTFEdit and select "Environment Map". Texture format is up to you, generally DXT1 will do.
Enable the "Clamp S" and "Clamp T" texture flags.
Then just save it all as a .vtf file and use it in your VMT like so:
"$Envmap" "effects/my_cubemap"
"effects" is the usual folder for environments/cubemaps You may put yours anywhere you like
In VTEX
VTEX will automatically mirror and orient your faces, you need only to provide correctly named textures. Name each file something like envmap001a*.tga, where * is put BK, FT, LF, RT, UP, or DN. If you took a cubemap screenshot in-game, this step will already by done, but to make them work properly with Vtex.exe you must use HDRShop (but before you need to change textures format to BMP, because HDRShop can only work with that kind of format) and then covert them to PFM files format.
Create a text file the same name as your textures (e.g. envmap001a.txt). If building for HDR write in the following, otherwise leave it blank:
pfm 1 // read .pfm file instead of .tga
pfmscale 1 // higher values will result in a brighter sky
nocompress 1 // disable compression (HDR compression is only supported by skyboxes)
Put these files into materialsrc and then just drag-n-drop .txt file into vtex.exe and you should end up with a working cubemap! HDR envmaps will be named like envmap001a.hdr.vtf, and only need to exist to work.
Parameters and Effects
"[1 1 1]", which means 100% intensity.
 Important: On VertexLitGeneric this parameter is being converted from gamma to linear. The input will turn into
Important: On VertexLitGeneric this parameter is being converted from gamma to linear. The input will turn into X^2.2f. For Example, 0.25 is not 25% reflectivity, it's actually ~5%!  Note:You must use quotemarks, as there are space characters within the value.
Note:You must use quotemarks, as there are space characters within the value. Note:You can also define the value as a single float, in which case it should equally apply to all three channels (e. g. $envmaptint 0.5 will equate to $envmaptint "[0.5 0.5 0.5]"). In this case you won't need the quotemarks. However, this method appears to not be 100% reliable.[confirm]
Note:You can also define the value as a single float, in which case it should equally apply to all three channels (e. g. $envmaptint 0.5 will equate to $envmaptint "[0.5 0.5 0.5]"). In this case you won't need the quotemarks. However, this method appears to not be 100% reliable.[confirm] Tip:This command is often used to dim the brightness of a specular reflection without the overhead of an
Tip:This command is often used to dim the brightness of a specular reflection without the overhead of an $envmapmask.
 Note:Will not work when Phong is enabled. Note:Will not work when Phong is enabled.
 Tip:Use higher contrasts to diminish relatively darker areas and increase "hot spots". Tip:Use higher contrasts to diminish relatively darker areas and increase "hot spots".
"[r g b]"
 Note:In the Shadercode for Note:In the Shadercode for Source 2013 and Source 2013 and Alien Swarm the parameter is defined as a float parameter. However it will be used as a vec3 and the Shader expects and uses it as such. Alien Swarm the parameter is defined as a float parameter. However it will be used as a vec3 and the Shader expects and uses it as such.
 Note:Will not work when Phong is enabled on models. Note:Will not work when Phong is enabled on models.
 Bug: Bug: Works only on models.   [todo tested in ?] Works only on models.   [todo tested in ?]
 Note:Superseded in Note:Superseded in by by- $envmapmask2.
 )
)
	- 80(DirectX 8)
- 81(DirectX 8.1)
- 90(DirectX 9)
- 95(DirectX 9 with Shader Model 3)
 
Water. The effect becomes multiplied with values higher than 1.
 Bug:Value behaves inverted in
Bug:Value behaves inverted in  , 0 applies the full effect, while 1 is none.  [todo tested in ?]
, 0 applies the full effect, while 1 is none.  [todo tested in ?]
VertexLitGeneric materials using $envmapfresnel without phong. By default "[0 1 2]", making surfaces facing the viewer less reflective than surfaces facing sideways.
 Note:The fresnel values for this parameter are not the same as those for Note:The fresnel values for this parameter are not the same as those for- $phongfresnelranges.Instead, the first value is the minimum amount of fresnel, the second value is the maximum, and the final value is exponent.
 , vertex lighting is used for the tinting instead of a lightmap.
, vertex lighting is used for the tinting instead of a lightmap. Note:Values above 1 for this parameter are technically permitted, but start inverting the effect.
Note:Values above 1 for this parameter are technically permitted, but start inverting the effect. Bug:Cannot be used with $envmapmask. $normalmapalphaenvmapmask must be used instead.  (tested in: gmod)
Bug:Cannot be used with $envmapmask. $normalmapalphaenvmapmask must be used instead.  (tested in: gmod)
For this it uses the alpha channel of the $bumpmap.
It linearly interpolates between a normal reflection vector and an anisotropic one.
 Bug:Does not work with $normalmapalphaenvmapmask  [todo tested in ?]
Bug:Does not work with $normalmapalphaenvmapmask  [todo tested in ?] Bug:Does not work with $basealphaenvmapmask except Lightmapped_4WayBlend  [todo tested in ?]
Bug:Does not work with $basealphaenvmapmask except Lightmapped_4WayBlend  [todo tested in ?] Note:Requires a $bumpmap to be present.
Note:Requires a $bumpmap to be present.
Console commands
| Cvar/Command | Parameters or default value | Descriptor | Effect | 
|---|---|---|---|
| buildcubemaps | Generates cubemaps for use in materials. If this isn't run, objects will reflect the skybox, or using default cubemaps, or have an invalid reflection, such as missing textures, looks extremely bright (with HDR on) or completely black.  Note:To properly build cubemaps, see the instructions on Cubemaps - Building cubemaps section. | ||
| envmap | Generates an environment map at the player's position and dumps it in cubemap_screenshots/, in six separate PFM files (or, if running without HDR, TGA files). 
 | ||
| mat_envmaptgasize | int | Sets the resolution for the files created with envmap. Default value: 32 | |
| mat_fastspecular | bool | Quickly disable or enable specular rendering without reloading materials. This does not affect performance, only appearance. mat_specularmust be used for proper performance testing.
 | |
| mat_specular | bool | Disable or enable specular reflections, unloading or loading the specular materials from memory. Default 1.  Note:This console variable is flagged as "launcher"-only in Left 4 Dead and Left 4 Dead 2, so use the following command instead:   sm_cvar building_cubemaps <0 or 1>command (with SourceMod installed) or  script Convars.SetValue("mat_specular", "<0 or 1>")(using VScript). | |
| r_showenvcubemap | bool | Debug command to display cubemaps on all dynamic objects at full intensity. It was used to create the image at the start of this article. | 
See also
- $envmapmask (specular mask)
- $phong (for diffuse reflection)
- Cubemap











































