$phong
$phong is a material shader parameter for the VertexLitGeneric shader available in all
Source games since
Source 2006.
It is also available on the LightmappedGeneric and WorldVertexTransition shaders in all games since
Counter-Strike: Global Offensive(also in ![]()
). It provides
diffuse reflections at low intensity and
specular highlights at apex intensity, masked by a texture which control per-texel its intensity. For a full explanation, see Phong materials.
Syntax
$phong <bool>
- Todo: Other games that don't require all phong parameters present (likely Portal 2 and up)
VertexLitGeneric
{
$phong 1
$bumpmap [texture]
$phongexponent 5 // either/or
$phongexponenttexture [texture] // either/or
$phongboost 1.0
$phongfresnelranges "[0 0.5 1]"
}Parameters
Masking
- Using $selfillumfresnel without $normalmapalphaenvmapmask will mask the $envmap using the $basetexture's alpha channel.
- Using $selfillumfresnel with $normalmapalphaenvmapmask will multiply the $envmap by
0.0f. Effectively disabling the effect! - When not using $selfillumfresnel. The mask used for $envmap will be the $basetexture's alpha channel unless $normalmapalphaenvmapmask is also used.
- If $normalmapalphaenvmapmask is used, the $bumpmap's alpha channel will be used for Phong masking. Using either
$basemapalphaphongmaskor$basemapluminancephongmaskwill override it.
$basemapalphaphongmask <boolean> (in all games since
) | Shader(s): VertexLitGeneric
$bumpmap's alpha channel.
$phong be masked by both $basemapalphaphongmask alpha channel and $normalmapalphaenvmapmask alpha channel.$basemapluminancephongmask <boolean> (in all games since
) | Shader(s): VertexLitGeneric
$basetexture.
$phongexponent2is forWorldVertexTransition's second material in
CS:GO engine branch.
$phongexponenttexture <texture> | Shader(s): VertexLitGeneric
- Red channel: Exponent mask (size of highlight, 0-255, where a value of 0 is a large highlight, 255 small.)
- Green channel: Albedo tint mask (only if
$phongalbedotint 1, 0-255, where a value of 0 is no tint, 255 full tint.) - Blue channel: Nothing.
- Alpha channel: $rimlight mask (only if
$rimmask 1.)
Note:LightmappedGenericandWorldVertexTransitiondo not have support for$phongexponenttexture. You must use$phongexponentinstead.
$phongexponentfactor <float> (only in ![]()
) | Shader(s): VertexLitGeneric
$phongexponenttexture by this amount. "0.0". However, a more reasonable default value would be "149.0"$invertphongmask <boolean> (in all games since
) | Shader(s): VertexLitGeneric
$forcephong <boolean> (in all games since
) | Shader(s): VertexLitGeneric
mat_phong is disabled.$diffuseexp <float> (only in ![]()
) | Shader(s): VertexLitGeneric, Infected
$shinyblood <integer> (only in ![]()
) | Shader(s): VertexLitGeneric, Infected
$shinybloodexponent <integer> (only in ![]()
) | Shader(s): VertexLitGeneric, Infected
Brightness
$phongboost <float> | Shader(s): VertexLitGeneric, LightmappedGeneric((only in
))
$phongfresnelranges <matrix> | Shader(s): VertexLitGeneric, LightmappedGeneric((only in
))
"[0 0.5 1]".
Note:$envmapis also affected by these fresnel ranges if both it and Phong are enabled in a material.
Note: drives the x component of a phongwarptexture if specified.
$phongdisablehalflambert <boolean> (in all games since
) (also in
,
) | Shader(s): VertexLitGeneric
$halflambert being disabled.$lightwarptexture found here.Colors
$phongalbedotint <boolean> (in all games since
) | Shader(s): VertexLitGeneric
$basetexture. The amount of tint is defined by the green channel of $phongexponenttexture. A $phongexponenttexture must be specified in order for $phongalbedotint to work.
Warning:$phongalbedotintcannot be used with$phongtint. The latter will disable the effect.
Note:$phongalbedotintworks by multiplying the$basetextureover the reflection, without darkening the albedo. The reflection will get dimmer as a result, so account for this in the phong mask or with$phongboost.
Note:$phongalbedotintwill tint highlights by the original color of the$basetextureeven when the material is tinted by$color2orrendercolor.
$phongalbedoboost <float> (in all games since
) (also in
) | Shader(s): VertexLitGeneric
$phongtint <RGB matrix> (in all games since
) | Shader(s): VertexLitGeneric
Warning:This will override $phongalbedotintif both are used.
Note: Also tints $rimlight
$phongwarptexture <texture> (in all games since
) | Shader(s): VertexLitGeneric
- The highlight is multiplied with a texture. The coordinates of the sampled pixel are as follows:
- x: 1 - (distance to the center of the highlight)
- y: 1 - (fresnel component as computed by Phong Fresnel ranges)
Note:Disables the initial phongfresnelranges masking
Bug:Does not work in Left 4 Dead 2. [todo tested in ?]
Brush Shader Parameters
WorldVertexTransition in $phongmaskcontrastbrightness and $phongmaskcontrastbrightness2 <vector2> | Shader(s): LightmappedGeneric, WorldVertexTransition
$phongmaskcontrastbrightness2is forWorldVertexTransition's second material.- Todo: Find out the range of both values.
$phongamount and $phongamount2 <vector4> | Shader(s): LightmappedGeneric, WorldVertexTransition
$phongamount2is forWorldVertexTransition's second material.
$phongbasetint and $phongbasetint2 <float> | Shader(s): LightmappedGeneric, WorldVertexTransition
$basetexture and/or $basetexture2 to tint the color of the Phong highlight.
The Original VMT: tile/hr_t/inferno/tile_a.vmt From Counter-Strike: Global Offensive
"lightmappedgeneric"
{
"$basetexture" "tile/hr_t/inferno/tile_a"
"$bumpmap" "tile/hr_t/inferno/tile_a_normals"
"$surfaceprop" "tile"
"$normalmapalphaenvmapmask" "1"
"$envmap" "env_cubemap"
"$envmaptint" "[.6 .6 .6]"
"$detail" "detail/plaster_detail_01"
"$detailscale" "[5 5]"
"$detailblendfactor" ".4"
"$envmaplightscale" "1"
"$phong" "1"
"$phongexponent" "80.0"
"$phongmaskcontrastbrightness" "[2 .7]"
"$phongamount" "[1 1 1 1]"
}
Console Commands
| Cvar/Command | Parameters or default value | Descriptor | Effect |
|---|---|---|---|
| mat_phong | 1 | bool | Disable or enable phong shading. |
Notes
LightmappedGeneric and WorldVertexTransition is only available in LightmappedGeneric is also available in $phongdisablehalflambert(in all games since See also
- Phong materials
- $envmap (environment map)
- $lightwarptexture
- $rimlight
External links
A comprehensive YouTube video on how phong materials work in Source
GMOD YouTube video showing how to apply Phong on LightmappedGeneric textures (Brushes)- $Phong on brushes*: The Hacky Way - A TF2maps.net guide on how to fake $Phong on brushes for games prior to CS:GO. Can also be used to fake phong on static props which are lit per-vertex, without falling back to lower-quality point lighting on the main prop
- $Phong on brushes*: The Hacky Way (gamebanana)
- SubstancePainter Source Engine Complex Phong Shader