$envmapmask: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Undo revision 223963 by Ficool2 (talk) Looking at the shader code the 2013 SDK and searching for strings in several games, it seem that the previous version is the one that's actually used.)
(Changed to use Shaderparam and MatParam templates, misc fixes)
Line 4: Line 4:
{{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 white and entirely matte areas are black. For diffuse type specularity which does not rely on [[$envmap]], see [[$phong]].
{{Shaderparam|$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|In Source 2007 games, using an $envmapmask which is not stored in a subfolder will cause the texture to fail loading in-game.}}
{{bug|In Source 2007 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 in materials using <code>[[$bumpmap]]</code>. See [[#Alternative_methods]].}}
{{warning|<code>$envmapmask</code> will not work in materials using {{ent|$bumpmap}}. See [[#Alternative_methods]].}}


==VMT syntax example==
==VMT syntax example==
Line 22: Line 22:
[[Image:Scanner mask.jpg|thumb|250px|[[npc_cscanner]]'s mask.]]
[[Image:Scanner mask.jpg|thumb|250px|[[npc_cscanner]]'s mask.]]


; <code>$envmapmasktransform <matrix></code>
{{MatParam|$envmapmasktransform|matrix|
: Adjusts [[UV map]]ping of the specular mask.
: Transforms the specular mask texture.
: DirectX 8 and below use <code>$envmapmaskscale</code> instead.
{{VMT UVtransform}}|dx9=1}}
 
{{MatParam|$envmapmaskscale|float|Scales the specular mask by the given value. See also <code>$envmapmasktransform</code>, above.|dx8=1}}
{{VMT UVtransform}}
{{MatParam|$envmapmaskframe|int|The frame to start an animated specular mask on.}}
 
; <code>$envmapmaskscale <[[float]]></code>
: Scales the specular mask by the given value.
: See also <code>$envmapmasktransform</code>, above.
: Requires DirectX 8.
 
; <code>$envmapmaskframe <[[integer]]></code>
: The frame to start an animated specular mask on.


==Alternative methods==
==Alternative methods==


Rather than creating a whole new texture for a specular mask, you can embed one into the [[alpha channel]] of the <code>[[$basetexture]]</code> or <code>[[$bumpmap]]</code>. Model materials with <code>$bumpmap</code> '''must''' do this. Unfortunately, it ''won't'' reduce memory usage.
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</code>. Model materials with <code>$bumpmap</code> '''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.


; <code>$basealphaenvmapmask <[[bool]]></code>
If you do use these commands, transformations and other such parameters applied to <code>$basetexture / $bumpmap</code> will also apply to the specular mask.
: Use the alpha channel of <code>[[$basetexture]]</code> as the specular mask. {{note|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 .VTF file simply to invert the alpha mask, you can use this VMT parameter instead.}}
{{note|The alpha channel '''''isn't''''' inverted in the Source 2007 engine for models, but the alpha channel '''''is''''' inverted for brushes!}}


; <code>$normalmapalphaenvmapmask <bool></code>
{{MatParam|$basealphaenvmapmask|bool|Use the alpha channel of <code>$basetexture</code> as the specular mask. {{note|Alpha channels embedded in <code>$basetexture</code> 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.}}
: Use the alpha channel of <code>[[$bumpmap]]</code> as the specular mask.
: {{note|The alpha channel '''''isn't''''' inverted in the Source 2007 engine for models, but the alpha channel '''''is''''' inverted for brushes!}}}}
{{note|Will not work if [[$phong|$basemapalphaphongmask]] or [[$phong|$basemapluminancephongmask]] are used.}}
{{MatParam|$normalmapalphaenvmapmask|bool|Use the alpha channel of <code>[[$bumpmap]]</code> as the specular mask.
; <code>$selfillum_envmapmask_alpha <float></code>
: {{note|Will not work if <code>[[$phong|$basemapalphaphongmask]]</code> or <code>[[$phong|$basemapluminancephongmask]]</code> are used.}}}}
: Use alpha channel as the [[$selfillum]] mask instead of <code>[[$basetexture]]</code>'s alpha. In this event this command replaces [[$selfillum]] - do not use both.
{{MatParam|$selfillum_envmapmask_alpha|float|Use alpha channel as the {{ent|$selfillum}} mask instead of <code>$basetexture</code>'s alpha. In this event this command replaces <code>$selfillum</code> - do not use both.}}


==Merging Specular Level into Normal Alpha in 3ds Max==
==Merging Specular Level into Normal Alpha in 3ds Max==

Revision as of 09:24, 26 June 2019

Template:Otherlang2

Template:Shaderparam 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 games, using an $envmapmask which is not stored in a subfolder will cause the texture to fail loading in-game.  [todo tested in ?]
Warning.pngWarning:$envmapmask will not work in materials using $bumpmap. See #Alternative_methods.

VMT syntax example

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

Additional parameters

npc_cscanner's mask.

$envmapmasktransform $envmapmaskscale $envmapmaskframe

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.

$basealphaenvmapmask $normalmapalphaenvmapmask $selfillum_envmapmask_alpha

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