Template:Archived page history/$envmap/en: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Better description for $EnvMapAnisotropy)
(Add new supported games for some parameters, move excessively long note in layout into a new section and clean it up, revise icky intro language into something better, minor language/grammar/mechanics revisions elsewhere)
Line 3: Line 3:
{{For|the set of material parameters used to mask specular reflections via textures|[[$envmapmask]]}}
{{For|the set of material parameters used to mask specular reflections via textures|[[$envmapmask]]}}


{{Shaderparam|$envmap}} It creates [[wikipedia:specular reflection|specular reflection]]s, 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 {{ent|env_cubemap}} entity. The reflection is not dynamic.
{{Shaderparam|$envmap}} It most commonly used to approximate the [[wikipedia:specular reflection|specular reflections]] seen on smooth surfaces, such as metals and plastics. This is achieved by mapping the [[Normal|vertex normals]] of a [[3D Model|model]] to positions on a cubemap - specified by <code>$envmap</code> - 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. When <code>$envmap</code> is set to <code>{{ent|env_cubemap}}</code> and {{ent|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.


{{note|<code>$envmap</code> actually works in the latest [[Source]] engine version (v24) of {{game name|hls|name=Half-Life: Source}} if it uses an <code>env_cubemap</code>. The issue actually comes from the {{ent|buildcubemaps}} command, 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 specularity supported by Source is the [[$phong|Phong]] type, which provides simpler reflections on both static '''and''' dynamic models.


The other form of reflection supported by Source is the diffuse [[$phong|Phong]] type.
== Availability ==
'''<code>$envmap</code>''' was introduced in {{src|4}} with {{hl2}} and {{css}}. It is available in all subsequent games.
 
{{warning|{{hls}} The latest Source engine version (v24) of {{hls|3}} does support <code>$envmap</code> if it uses an <code>env_cubemap</code>, but the {{ent|buildcubemaps}} command does ''not'' work properly. 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.}}


== Syntax==
== Syntax==
Line 14: Line 17:
</pre>
</pre>


"env_cubemap" is normally used, as it tells [[VBSP]] to swap in the name of the nearest <code>env_cubemap</code> when the map compiles. However it is also possible to use a static cubemap image that has been manually created.
"env_cubemap" is typically used, which tells [[VBSP]] to swap in the name of the nearest <code>env_cubemap</code> when the map compiles. However, it is also possible to use a static cubemap image that has been manually created.


{{note|If <code>$envmap</code> is used without specifying {{ent|$basetexture}}, the specular reflections will be force drawn regardless of anything.}}
{{note|If <code>$envmap</code> is used without specifying {{ent|$basetexture}}, the specular reflections will be force drawn regardless of anything.}}
Line 107: Line 110:
: {{bug|Cannot be used with {{ent|$bumpmap}}. <code>$phongfresnelranges</code> must be used instead.}}|since={{l4d}}|shaders=VertexLitGeneric}}
: {{bug|Cannot be used with {{ent|$bumpmap}}. <code>$phongfresnelranges</code> must be used instead.}}|since={{l4d}}|shaders=VertexLitGeneric}}
<span  id="$envmaplightscale"></span>
<span  id="$envmaplightscale"></span>
{{MatParam|$envmaplightscale|float|Tint the surface's specular reflection with its lightmap. This matches a surface's reflection with its diffuse lighting and acts as rudimentary reflection occlusion. With a value of 1, a surface will have no reflection if it isn't lit at all. For models in {{csgo}}, 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.}}|since={{as}}|shaders=LightmappedGeneric, Lightmapped_4WayBlend ({{csgo}}), VertexLitGeneric ({{csgo}}), WorldVertexTransition ({{csgo}})}}
{{MatParam|$envmaplightscale|float|Tint the surface's specular reflection with its lightmap. This matches a surface's reflection with its diffuse lighting and acts as rudimentary reflection occlusion. With a value of 1, a surface will have no reflection if it isn't lit at all. For models in {{csgo}}, 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.}}|since={{as}}|also={{gmod}}|shaders=LightmappedGeneric, Lightmapped_4WayBlend ({{csgo}}), VertexLitGeneric ({{csgo}}), WorldVertexTransition ({{csgo}})}}
<span  id="$envmaplightscaleminmax"></span>
<span  id="$envmaplightscaleminmax"></span>
{{MatParam|$envmaplightscaleminmax|vector2|Thresholds for the lightmap reflection tinting effect. Setting the minimum value higher increases the minimum light amount at which the reflection gets nerfed to nothing.|only={{csgo}}|shaders=LightmappedGeneric, Lightmapped_4WayBlend, VertexLitGeneric, WorldVertexTransition}}
{{MatParam|$envmaplightscaleminmax|vector2|Thresholds for the lightmap reflection tinting effect. Setting the minimum value higher increases the minimum light amount at which the reflection gets nerfed to nothing.|only={{csgo}}|also={{gmod}}|shaders=LightmappedGeneric, Lightmapped_4WayBlend, VertexLitGeneric, WorldVertexTransition}}
<span  id="$envmapanisotropy"></span>
<span  id="$envmapanisotropy"></span>
{{MatParam|$envmapanisotropy|bool|Enables anisotropic reflection emulation by warping the reflection downwards.<br>
{{MatParam|$envmapanisotropy|bool|Enables anisotropic reflection emulation by warping the reflection downwards.<br>

Revision as of 14:39, 28 June 2023

Flag-white.pngEnglish (en)
Specular reflections at full intensity.
For the set of material parameters used to mask specular reflections via textures, see $envmapmask.

Template:Shaderparam It most commonly used to approximate the specular reflections seen on smooth surfaces, such as metals 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. 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 was introduced in Source Source with Half-Life 2 and Counter-Strike: Source. It is available in all subsequent games.

Warning.pngWarning:Half-Life: Source The latest Source engine version (v24) of Half-Life: Source does support $envmap if it uses an env_cubemap, but the buildcubemaps command does not work properly. 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.

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

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.pngNote:Pre-Template:Game name 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 $envmapsphere parameter.

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 Blender 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

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.

Todo: 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 $envmaptint $envmapcontrast $envmapsaturation $envmapframe $envmapmode $basetexturenoenvmap $envmapoptional $envmapsphere $noenvmapmip

A vent without and with reflection tinting. The bottom image lists the material parameters used to create the effect.

$fresnelreflection $envmapfresnel

An in-game example of anisotropic reflections, with $envmapanisotropyscale set to 1.

$envmapfresnelminmaxexp $envmaplightscale $envmaplightscaleminmax $envmapanisotropy $envmapanisotropyscale

Console commands

buildcubemaps
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.
envmap
Generates an environment map at the player's position and dumps it in cubemap_screenshots/, in five separate PFM files.
mat_fastspecular <boolean>
Quickly disable or enable specular rendering without reloading materials. This does not affect performance, only appearance. mat_specular must be used for proper performance testing.
Icon-Bug.pngBug:Doesn't work in some games.  [todo tested in ?]
Note.pngNote:Despite common misconception, setting this to 0 does not enable a "fancy specular" mode, it simply disables specular rendering entirely.
mat_specular <boolean>
Disable or enable specular reflections, unloading or loading the specular materials from memory. Default 1.
r_showenvcubemap <boolean>
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