This article's documentation is for anything that uses the Source engine. Click here for more information.

$envmapmask: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (The wording of the spec in the alpha dident make it clear that the user had to invert the alpha to what there used to using. this wording is abit more clear as to the $basealphaenvmapmask)
No edit summary
 
(83 intermediate revisions by 37 users not shown)
Line 1: Line 1:
{{LanguageBar}}
{{toc-right}}
{{toc-right}}


'''<code>$envmapmask</code>''' defines a specular mask, which affects how strongly each pixel of a material reflects light from the [[$envmap]]. The mask should be a greyscale image in which entirely reflective areas are black and entirely matte areas are white.
[[File:Scanner mask.jpg|thumb|250px|[[npc_cscanner]]'s mask.]]


{{warning|<code>$envmapmask</code> will not work in materials using <code>[[$bumpmap]]</code>. See [[#Alternative_methods]].}}
{{this is a|shader parameter|name=$envmapmask}} It defines a '''specular mask''' which affects how strongly each pixel of a material reflects light from the {{ent|$envmap}}. The mask should be a grayscale image in which entirely reflective areas are white and entirely matte areas are black. For diffuse type specularity which does not rely on <code>$envmap</code>, see {{ent|$phong}}.
{{bug|hidetested=1|In {{src07|2}} games, using an <code>$envmapmask</code> which is not stored in a subfolder will cause the texture to fail loading in-game.}}
{{warning|<code>$envmapmask</code> will not work with materials using {{ent|$bumpmap}}/ in most situations; see [[#Alternative_methods]].
{{note|Exceptions:
* '''[[LightmappedReflective]]''' (uses {{ent|$normalmap}})
* {{mapbase|only}} '''[[VertexLitGeneric]]'''
* {{csgo|only}}'''[[LightmappedGeneric]]'''
}} }}
{{warning|<code>$envmapmask</code> will not work with materials using {{ent|$phong}}, at all. By default it will use the $basetexture's alpha channel for masking the envmap.}}
{{note|While specular masks are traditionally greyscale, they can be colored. In such an instance, the color data will act as a per-texel $envmaptint.}}


==VMT syntax example==
==VMT syntax example==
Line 13: Line 24:
  [[$envmap]] env_cubemap
  [[$envmap]] env_cubemap
  '''$envmapmask "props/tvscreen_test"'''
  '''$envmapmask "props/tvscreen_test"'''
$envmapmasktransform "center .5 .5 scale .25 .25 rotate 0 translate 0 0" ''//dx9 only''
$envmapmaskscale .25 ''// dx8 only''
$envmapmaskframe 1
$selfillum_envmapmask_alpha 1 ''//dx9 only''
  }
  }


==Additional parameters==
==Additional parameters==


[[Image:Scanner mask.jpg|thumb|[[npc_cscanner]]'s mask.]]
{{MatParamDef|$envmapmasktransform|matrix|
: Transforms the specular mask texture.
{{bug|Does not work on {{ent|VertexLitGeneric}}.}}
{{VMT UVtransform}}|dx9=1}}
{{MatParamDef|$envmapmaskscale|float|Scales the specular mask by the given value. See also <code>$envmapmasktransform</code>, above.|dx8=1}}
{{MatParamDef|$envmapmaskframe|int|The frame to start an animated specular mask on.}}
====CS:GO WorldVertexTransition Parameters====
{{MatParamDef|$envmapmask2|texture|Specular mask for {{ent|WorldVertexTransition}}'s second layer.|only={{csgo}}|shaders=WorldVertexTransition}}
{{MatParamDef|$envmapmasktransform2|matrix|Texture transformation for <code>$envmapmask2</code>.|only={{csgo}}|shaders=WorldVertexTransition}}
{{MatParamDef|$envmapframe2|int|The frame to start an animated <code>$envmapmask2</code> on.|only={{csgo}}|shaders=WorldVertexTransition}}


; <code>$envmapmasktransform <matrix></code>
==Alternative methods==
: Adjusts [[UV map]]ping of the specular mask.
: DirectX 8 and below use <code>$envmapmaskscale</code> instead.


{{VMT UVtransform}}
Rather than creating a whole new texture for a specular mask, you can embed one into the [[alpha channel]] of the {{ent|$basetexture}} or {{code|$bumpmap}}. Model materials with {{code|$bumpmap}} '''must''' do this. Unfortunately, it ''won't'' reduce memory usage.


; <code>$envmapmaskscale <[[float]]></code>
If you do use these commands, transformations and other such parameters applied to {{code|$basetexture / $bumpmap}} will also apply to the specular mask.
: Scales the specular mask by the given value.
: See also <code>$envmapmasktransform</code>, above.
: Requires DirectX 8.


; <code>$envmapmaskframe <[[integer]]></code>
{{MatParamDef|$basealphaenvmapmask|bool
: The frame of an animated texture to use as the mask.
| text = Use the alpha channel of the {{code|$basetexture}} as the specular mask.


; <code>$selfillum_envmapmask_alpha <[[bool]]></code>
{{Note|
: Derives [[self-illumination]] values from the [[alpha channel]] of the specular mask.
* Alpha channels embedded in {{code|$basetexture}} work in reverse. Transparent areas are reflective, opaque areas are matte. This is because, say, a window texture's alpha mask would be mostly black to allow for transparency -- yet that black part of the mask would also be the most reflective part. To avoid having to duplicate a texture file simply to invert the alpha mask, you can use this material parameter instead.
: Requires DirectX 9.
* The alpha channel '''''is not''''' inverted in {{src07|2}} ''and'' {{csgo|2}} for models, but the alpha channel '''''is''''' inverted for brushes!
: See also <code>[[$selfillum]]</code>.
:* In {{src13}}, the alpha channel is only inverted for models if {{cmd|$phong}} is disabled!
* {{l4d2}} auto enables if '''$envmap''' is present. Opaque areas are reflective while transparent are matte. Set as [[bool|true]] to invert {{code|$basetexture}} alpha channel behaviour. This allow {{code|[[$bumpmap]]}} have a dedicated {{code|[[$phong]]}} mask, when material transparency is not needed.}}


==Alternative methods==
{{Bug|<ul>
<li> In CSGO, this parameter breaks materials using {{ent|$translucent}}. Use {{code|$envmapmask}} or {{code|$normalmapalphaenvmapmask}} instead.<br>
<li> In all of: {{gmod}}{{src13}}{{tf2}}{{as}}{{csgo}} on {{ent|VertexLitGeneric}} ('''Without''' {{ent|$phong}}), {{ent|WorldVertexTransition}} and {{ent|LightmappedGeneric}}, <code>$basealphaenvmapmask</code> cannot be used with {{ent|$bumpmap}}.<br>
<li> In all of: {{gmod}}{{src13}}{{tf2}}{{as}}{{csgo}} on {{ent|LightmappedGeneric}} and {{ent|WorldVertexTransition}}, <code>$basealphaenvmapmask</code> cannot be used with {{ent|$selfillum}}, {{ent|$seamless_detail}} or {{ent|$distancealpha}}.<br>
<li> In {{csgo}}, on {{ent|LightmappedGeneric}} and {{ent|WorldVertexTransition}}, <code>$basealphaenvmapmask</code> cannot be used with [[$detail#Parameters and Effects|$detailblendmode]] "9" or {{ent|$envmapanisotropy}}.<br>
<li> In {{csgo}}, on {{ent|Lightmapped_4WayBlend}}, <code>$basealphaenvmapmask</code> cannot be used with {{ent|$selfillum}}.
<li> This cannot be used with {{ent|$bumpmap}} on {{ent|LightmappedGeneric}}
</ul>}}
 
}}
 
{{MatParamDef|$normalmapalphaenvmapmask|bool
| text = Use the alpha channel of the {{code|$bumpmap}} or {{code|$normalmap}} as the specular mask.
 
{{Warning|Using this in combination with {{code|[[$phong|$basemapalphaphongmask]]}} or {{code|[[$phong|$basemapluminancephongmask]]}} will set the mask used for the {{ent|$envmap}} to be those instead. <br>
'''There are additional caveats''' when using {{ent|$phong}}. See its entry for more information about possible issues.
{{Bug|
* In all of: {{gmod}}{{src13}}{{tf2}}{{as}}{{csgo}} on {{ent|VertexLitGeneric}} ('''Without''' {{ent|$phong}}), <code>$normalmapalphaenvmapmask</code> cannot be used with [[Glowing_Textures#.24selfillum|$selfillumfresnel]].<br>
: {{note| Using <code>$normalmapalphaenvmapmask</code> with {{ent|$phong}} and [[Glowing_Textures#.24selfillum|$selfillumfresnel]] has special caveats that should be considered. Check {{ent|$phong}} for  for more information.}}
* In {{csgo}}, on {{ent|LightmappedGeneric}} and {{ent|WorldVertexTransition}}, {{code|[[$normalmapalphaenvmapmask]]}} cannot be used with [[$detail#Parameters and Effects|$detailblendmode]] "9" or {{ent|$envmapanisotropy}}.}}
}}
}}
 
{{MatParamDef|$selfillum_envmapmask_alpha|float
| text = Use the alpha channel of the {{code|$envmapmask}} as the {{ent|$selfillum}} mask instead of {{code|$basetexture}}'s alpha.<br>
: {{Bug|This Parameter replaces {{code|$selfillum}}. If both are used it will result in an error. The material will not render.}}
: {{Warning|Only on {{ent|VertexLitGeneric}} - Note that <code>$envmapmask</code> does not work '''with''' {{ent|$bumpmap}} or {{ent|$phong}} on VertexLitGeneric.}}
{{todo|This is not an alternative method to <code>$envmapmask</code> and in fact that parameter is required to use this. <code>Move it to Additional Parameters</code> and pray links on other pages don't break.}}
}}
 
{{MatParamDef|$envmapmaskintintmasktexture|bool|shaders=VertexLitGeneric
| text = Use the red channel of the {{ent|$tintmasktexture}} as the specular mask.|only={{csgo}}
}}


Rather than creating a whole new texture just for a specular mask, you can use the alpha channel of either the <code>[[$basetexture]]</code> or <code>[[$bumpmap]]</code>. Note that this unfortunately ''won't'' reduce the overall amount of data on-disc or in-memory.
==Merging Specular Level into Normal Alpha in 3ds Max==


If you do use these commands, transformations and other such parameters applied to the base texture/bump map will also apply to the specular mask.
To merge a Specular Level map into the Normal Map alpha, you can create a Composite Map node with the normal map in Layer 1 and the specular map in Mask 1. Then right-click the composite map, click Render Map and save this new image to file (remembering to keep the Gamma at 1.0 and using 32 bits per pixel in the save options).


; <code>$basealphaenvmapmask <bool></code>
These steps are automated in the [http://dev.wallworm.com/topic/34/alpha_spec.html Alpha Spec] tool in Wall Worm 2.72+.
: Use the alpha channel of <code>[[$basetexture]]</code> as the specular mask.
:''When putting your specular map in the alpha channel you will have to invert it.
:or else it will work the wrong way round.''
:'''black = more reflective, white = duller.'''
; <code>$normalmapalphaenvmapmask <bool></code>
: Use the alpha channel of <code>[[$bumpmap]]</code> as the specular mask.  
: ''This must be used if the material has a bump map.''


==See Also==
==See also==
* [[$envmap]]
* [[$basetexture]]
* [[$envmap]] (environment map)
* [[$phong]] (diffuse reflection)
* [[$phong]] (diffuse reflection)
 
* [[$selfillum ]]
[[Category:List of Shader Parameters|E]]
[[Category:Shader parameters|e]]
[[Category:VMT Reflections]]
[[Category:VMT Reflections]]
[[Category:VMT Texture Reference]]

Latest revision as of 09:47, 24 August 2025

English (en)Français (fr)Русский (ru)中文 (zh)Translate (Translate)
npc_cscanner's mask.

$envmapmask is a material shader parameter available in all Source Source games. It defines a specular mask which affects how strongly each pixel of a material reflects light from the $envmap. The mask should be a grayscale image in which entirely reflective areas are white and entirely matte areas are black. For diffuse type specularity which does not rely on $envmap, see $phong.

Icon-Bug.pngBug:In Source 2007 Source 2007 games, using an $envmapmask which is not stored in a subfolder will cause the texture to fail loading in-game.
Warning.pngWarning:$envmapmask will not work with materials using $bumpmap/ in most situations; see #Alternative_methods.
Note.pngNote:Exceptions:
Warning.pngWarning:$envmapmask will not work with materials using $phong, at all. By default it will use the $basetexture's alpha channel for masking the envmap.
Note.pngNote:While specular masks are traditionally greyscale, they can be colored. In such an instance, the color data will act as a per-texel $envmaptint.

VMT syntax example

$envmapmask <texture>
VertexLitGeneric
{
	$envmap			env_cubemap
	$envmapmask		"props/tvscreen_test"
}

Additional parameters

Transforms the specular mask texture.
Icon-Bug.pngBug:Does not work on VertexLitGeneric.  [todo tested in ?]
The default position is center .5 .5 scale 1 1 rotate 0 translate 0 0.
  1. center defines the point of rotation. Only useful if rotate is being used.
  2. scale fits the texture into the material the given number of times. 2 1 is a 50% scale in the horizontal X axis while the vertical Y axis is still at original scale.
  3. rotate rotates the texture counter-clockwise in degrees. Accepts any number, including negatives.
  4. translate shifts the texture by the given numbers. .5 will shift it half-way. 1 will shift it once completely over, which is the same as not moving it at all.
Note.pngNote:All values must be included!
Icon-Bug.pngBug:Scaling the texture may cause odd issues where the Texture Lock tool in Hammer will not actually lock the texture in place.  [todo tested in ?]
Icon-Bug.pngBug:Rotating textures applied on brushes will rotate around the map origin (confirm: Orangebox engine only?). A fix for this is to change the center position in the VMT to the brush's origin.  [todo tested in ?]
Scales the specular mask by the given value. See also $envmapmasktransform, above.
The frame to start an animated specular mask on.

CS:GO WorldVertexTransition Parameters

$envmapmask2 <texture> (only in Counter-Strike: Global Offensive)
Shader(s): WorldVertexTransition
Specular mask for WorldVertexTransition's second layer.
Shader(s): WorldVertexTransition
Texture transformation for $envmapmask2.
$envmapframe2 <integer> (only in Counter-Strike: Global Offensive)
Shader(s): WorldVertexTransition
The frame to start an animated $envmapmask2 on.

Alternative methods

Rather than creating a whole new texture for a specular mask, you can embed one into the alpha channel of the $basetexture or $bumpmap. Model materials with $bumpmap must do this. Unfortunately, it won't reduce memory usage.

If you do use these commands, transformations and other such parameters applied to $basetexture / $bumpmap will also apply to the specular mask.

Use the alpha channel of the $basetexture as the specular mask.
Note.pngNote:
  • Alpha channels embedded in $basetexture work in reverse. Transparent areas are reflective, opaque areas are matte. This is because, say, a window texture's alpha mask would be mostly black to allow for transparency -- yet that black part of the mask would also be the most reflective part. To avoid having to duplicate a texture file simply to invert the alpha mask, you can use this material parameter instead.
  • The alpha channel is not inverted in Source 2007 Source 2007 and Counter-Strike: Global Offensive Counter-Strike: Global Offensive for models, but the alpha channel is inverted for brushes!
  • In Source 2013, the alpha channel is only inverted for models if $phong is disabled!
  • Left 4 Dead 2 auto enables if $envmap is present. Opaque areas are reflective while transparent are matte. Set as true to invert $basetexture alpha channel behaviour. This allow $bumpmap have a dedicated $phong mask, when material transparency is not needed.
Icon-Bug.pngBug:  [todo tested in ?]
Use the alpha channel of the $bumpmap or $normalmap as the specular mask.
Warning.pngWarning:Using this in combination with $basemapalphaphongmask or $basemapluminancephongmask will set the mask used for the $envmap to be those instead.

There are additional caveats when using $phong. See its entry for more information about possible issues.

Icon-Bug.pngBug:
Note.pngNote: Using $normalmapalphaenvmapmask with $phong and $selfillumfresnel has special caveats that should be considered. Check $phong for for more information.
Use the alpha channel of the $envmapmask as the $selfillum mask instead of $basetexture's alpha.
Icon-Bug.pngBug:This Parameter replaces $selfillum. If both are used it will result in an error. The material will not render.  [todo tested in ?]
Warning.pngWarning:Only on VertexLitGeneric - Note that $envmapmask does not work with $bumpmap or $phong on VertexLitGeneric.
Todo: This is not an alternative method to $envmapmask and in fact that parameter is required to use this. Move it to Additional Parameters and pray links on other pages don't break.
Shader(s): VertexLitGeneric
Use the red channel of the $tintmasktexture as the specular mask.

Merging Specular Level into Normal Alpha in 3ds Max

To merge a Specular Level map into the Normal Map alpha, you can create a Composite Map node with the normal map in Layer 1 and the specular map in Mask 1. Then right-click the composite map, click Render Map and save this new image to file (remembering to keep the Gamma at 1.0 and using 32 bits per pixel in the save options).

These steps are automated in the Alpha Spec tool in Wall Worm 2.72+.

See also