$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.
$envmapactually works in the latest Source engine version (v24) of Half-Life: Source if it uses an
env_cubemap. The issue actually comes from the
buildcubemapscommand, since if the cubemaps are built in another game and then the BSP is added into HL:S, they will work fine. Is not clear if in older versions there were more issues but due such problems, Valve used static reflective images for every reflective texture in the game.
The other form of reflection supported by Source is the diffuse Phong type.
"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.
$envmapis used without specifying
$basetexture, the specular reflections will be force drawn regardless of anything.
$basetexturealpha/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.
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.
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 DXT5 will do.
Then just save it all as a .vtf file and use it in your VMT like so:
"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.
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:
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. A texture file that determines per-texel reflection intensity.
"[1 1 1]", which means 100% intensity.
"[r g b]"
- Note: In the Shadercode for 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.
- Note: Will not work when Phong is enabled on models.
- Note: Superseded in by
95(DirectX 9 with Shader Model 3)
Water. The effect becomes multiplied with values higher than 1.
$envmapfresnelwithout 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
$phongfresnelranges.Instead, the first value is the minimum amount of fresnel, the second value is the maximum, and the final value is exponent.
- Bug:Cannot be used with
$phongfresnelrangesmust be used instead.
For this it uses the alpha channel of the
It linearly interpolates between a normal reflection vector and an anisotropic one.
$bumpmapto be present.
- 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.
- Generates an environment map at the player's position and dumps it in cubemap_screenshots/, in five separate PFM files.
- Quickly disable or enable specular rendering without reloading materials. This does not affect performance, only appearance.
mat_specularmust be used for proper performance testing.
- Bug:Doesn't work in some games.
- Note: Despite common misconception, setting this to 0 does not enable a "fancy specular" mode, it simply disables specular rendering entirely.
- Disable or enable specular reflections, unloading or loading the specular materials from memory. Default 1.
- 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.
- $envmapmask (specular mask)
- $phong (for diffuse reflection)