From Valve Developer Community
Revision as of 15:08, 10 July 2019 by NvC DmN CH (talk | contribs) (Using $envmap without $basetexture will make the reflections be force drawn.)
Jump to: navigation, search
Specular reflections.

$envmap is a material shader parameter available in all Source games. It creates specular reflections, which are seen on smooth surfaces. It does this by defining an "environment map" (specifically a cubemap) to draw as a reflection; normally that of the nearest env_cubemap entity. The reflection is not dynamic.

Bug.png Bug: $envmap does not work in the latest Source engine version (v24) of <Half-Life: Source> Half-Life: Source if it uses an env_cubemap. This is probably the reason Valve used the same static reflective image for every reflective texture in the game.

The other form of reflection supported by Source is the diffuse phong type.


$envmap env_cubemap

"env_cubemap" is normally used, as it 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.png Note: If $envmap is used without specifying $basetexture, the specular reflections will be force drawn regardless of anything.
Note.png Note: Most Cubemap textures will have no reflectivity when used as overlays or decals. It is unclear why this is so[Clarify].

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.

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.png Note: Some games, including <Team Fortress 2> Team Fortress 2 and <Left 4 Dead 2> Left 4 Dead 2 require 7 faces for the cubemap to work. The seventh in this case is a round texture, used as a sphere map for the $envmapsphere command.

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.

Orientation guide for T-assembled environments. Click to enlarge
Orientation guide for render results. Click to enlarge

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 DXT5 will do.

Cubemap tut1 cra0.jpg

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


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.

To do: What axis does each direction relate to?

Cubemap axis reference 1.jpg

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
pfmscale 1
nocompress 1

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

$envmapmask <texture>
See $envmapmask. A texture file that determines per-texel reflection intensity.
$envmaptint <RGB matrix>
Controls the intensity of the reflection's red, green and blue color channels. Any positive number can be used. Default is "[1 1 1]", which means 100% intensity.
Note.png Note: You must use quotemarks, as there are space characters within the value.
Tip.png Tip: This command is often used to dim the brightness of a specular reflection without the overhead of an $envmapmask.
$envmapcontrast <normal>
Controls the contrast of the reflection. 0 is natural contrast, while 1 is the full squaring of the color (i.e. color*color).
Note.png Note: Will not work when Phong is enabled.
Tip.png Tip: Use higher contrasts to diminish relatively darker areas and increase "hot spots".
$envmapsaturation <normal>
Controls the colour saturation of the reflection. 0 is greyscale, while 1 is natural saturation.
Note.png Note: Will not work when Phong is enabled.
Bug.png Bug: <Counter-Strike: Source> Works only on models.
$envmapframe <integer>
The frame to start an animated cubemap on.
$envmapmode <integer>  <Obsolete>
Deprecated.  Depreciated MATERIAL_VAR_ENVMAPMODE = (1 << 25), // OBSOLETE
$basetexturenoenvmap <boolean>  (DX9+)
$basetexture2noenvmap <boolean>  (DX9+)
Used for materials with two albedos, to make one or the other matte. See also $basetexture and $basetexture2.
$envmapoptional <choices>
Sets the oldest DirectX version that should draw the reflection. Choose from:
  • 80 (DirectX 8)
  • 81 (DirectX 8.1)
  • 90 (DirectX 9)
  • 95 (DirectX 9 with Shader Model 3)
$envmapsphere <boolean>  <Obsolete>
Deprecated.  Determines whether the material's envmap should be a spheremap (deprecated) instead of a cubemap. Set this to 1 to use a spheremap.
$noenvmapmip <boolean>
To do: What does this actually do and what engine branches is it in? Found in <Counter-Strike: Global Offensive> under materials/metal/hr_metal/hr_metal_corrugated_001.vmt
$envmapfresnel <float> (in all games since EP2)  (DX9+)
Adds a Fresnel effect to the reflection. Effect becomes multiplied with values higher than 1.0.
Note.png Note:  VertexLitGeneric only. Use $fresnelreflection for LightmappedGeneric instead.
$envmapfresnelminmaxexp <vector> (in all games since L4D2)
Sets the ranges for the Fresnel effect. By default "[0 1 2]", making surfaces facing the viewer less reflective than surfaces facing sideways.
Note.png Note: The fresnel values here 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.
Bug.png Bug: Cannot be used with $bumpmap. $phongfresnelranges must be used instead.
$fresnelreflection <float> (in all games since EP1)
Adds a Fresnel effect to the reflection. The value controls the Fresnel ranges To do:  How?. 1.0 = mirror, 0.0 = water
Note.png Note: Not available on VertexLitGeneric.
$envmaplightscale <float> (in all games since AS)
Allows the surface's lightmap to tint the reflections. A value between 0 and 1 determines how much the reflection is tinted; values above 1 are permitted but seem to actually start inverting the effect.
Note.png Note: LightmappedGeneric only in <Alien Swarm>[Portal 2]
$envmaplightscaleminmax <vector2> (in all games since CSGO)
How strong the reflection should be. First value is minimum, second value is maximum. To do: Needs testing and a better description. Default seems to be [0 1].
$envmapanisotropy <boolean> (in all games since CSGO)
Enables warping of the reflection, "pushing" the top downward.
Note.png Note: Not available on VertexLitGeneric.
$envmapanisotropyscale <normal> (in all games since CSGO)
The amount the reflection should be warped by.

Console commands

Generates cubemaps for use in materials. If this isn't run, objects will reflect the skybox (OB) or have an invalid reflection, white in Ep1 and pink checkerboards in MP.
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