From Valve Developer Community
Revision as of 14:28, 28 April 2021 by Deprecated (talk | contribs) (Updated $forcephong with correct information, updated Left 4 Dead parameters with shader strings)
Jump to: navigation, search
Phong shading provides Alyx's skin, hairband and lip highlights.

$phong is a material shader parameter available in all Source games since <Source><Source> Source 2006 for VertexLitGeneric, LightmappedGeneric, WorldVertexTransition. It provides diffuse reflections, masked by a texture to control its intensity per-texel. For a full explanation, see Phong materials.

Note.png Note: Phong shading for LightmappedGeneric and WorldVertexTransition is only available in Counter-Strike: Global Offensive. It requires the material to be lit by a env_cascade_light entity to work properly, and uses the dynamic shadows generated by it as a mask on top of the traditional phong masking.
Note.png Note: Phong shading for LightmappedGeneric is also available in <Mapbase>.


$phong <bool>
Note.png Note: All parameters in the following example must be specified in the material, otherwise Phong shading won't show up at all, except in <Insurgency>.
To do: Other games that don't require all phong parameters present (likely Portal 2 and up)
	$phong 1

	$bumpmap				[texture]
	$phongexponent			5			// either/or
	$phongexponenttexture	[texture]	// either/or
	$phongboost				1.0
	$phongfresnelranges		"[0 0.5 1]"



$bumpmap <texture>
There must be a Phong mask. The alpha channel of a bump map acts as a Phong mask by default.
$basemapalphaphongmask <boolean> (in all games since <Source><Source>)
Use $basetexture's alpha channel as the Phong mask instead of $bumpmap's. The Phong will not be influenced by the bump map, however.
Shaders: VertexLitGeneric
$basemapluminancephongmask <boolean> (in all games since Left 4 Dead)
Mask phong intensity based on the brightness of the $basetexture.
Shaders: VertexLitGeneric
$phongexponent and $phongexponent2 <integer>
A global exponent value. Overrides an exponent mask if present.
$phongexponent2 is for WorldVertexTransition's second material in Counter-Strike: Global Offensive.
$phongexponenttexture <texture>
A per-texel exponent map. In an exponent map:
  • 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.png Note: LightmappedGeneric and WorldVertexTransition do not have support for $phongexponenttexture. You must use $phongexponent instead.
Shaders: VertexLitGeneric
$phongexponentfactor <integer> (only in <Source><Source><Source>)
Multiply the exponent texture by this amount.
Shaders: VertexLitGeneric
$invertphongmask <boolean> (in all games since <Source><Source>)
Invert the value of the phong mask. To do: What types of mask does this work on?
Shaders: VertexLitGeneric
$forcephong <boolean> (in all games since [Portal 2])
Force phong shading on phong-using materials even at low GPU levels when mat_phong is disabled.
Shaders: VertexLitGeneric
$diffuseexp <float> (only in Left 4 Dead <Left 4 Dead 2>)
Diffuse exponent used for dynamic lights only.
$shinyblood <integer> (only in Left 4 Dead <Left 4 Dead 2>)
Derive phong mask from areas that are more red than others. Only when variation is disabled.
$shinybloodexponent <integer> (only in Left 4 Dead <Left 4 Dead 2>)
Exponent for the above.


$phongboost <float>
Phong brightness factor. Larger values create a more intense highlight, useful for surfaces like metal and glass.
Shaders: VertexLitGeneric, LightmappedGeneric(<Mapbase>)
$phongfresnelranges <matrix>
See Phong Fresnel ranges. Default is "[0 0.5 1]".
Note.png Note: $envmap is also affected by these fresnel ranges if both it and Phong are enabled in a material.
Shaders: VertexLitGeneric, LightmappedGeneric(<Mapbase>)
$phongdisablehalflambert <boolean> (in all games since <Alien Swarm>)  (also in <Mapbase>)
Disables forced half-lambertian shading on Phong materials.
Shaders: VertexLitGeneric


$phongalbedotint <boolean> (in all games since <Source><Source>)
Tints the phong reflection by the color of the $basetexture. The amount of tint is defined by the green channel of $phongexponenttexture. A $phongexponenttexture must be specified in order for $phongalbedotint to work.
Note.png Note: $phongalbedotint works by multiplying the $basetexture over 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.png Note: $phongalbedotint will tint highlights by the original color of the $basetexture even when the material is tinted by $color2 or rendercolor.
Shaders: VertexLitGeneric
$phongalbedoboost <float> (in all games since Counter-Strike: Global Offensive)
Phong albedo overbrightening factor. Ranges 0-255.
Note.png Note: Tint color is PhongAlbedoBoost * baseColor, mixed with the phong color by the albedo tint mask in $phongexponenttexutre.
To do: Test and add a better description.
Shaders: VertexLitGeneric
The Hunter without and with its $phongwarptexture, showing how it affects the Phong reflection.
$phongtint <RGB matrix> (in all games since <Source><Source>)
Color tint of the phong reflection. The channels are interpreted relative to each other (so "[0 0 0]" and "[1 1 1]" are the same).
Warning.png Warning: This will override $phongalbedotint if both are used.
Bug.png Bug: This does not work with $basemapalphaphongmask.
Shaders: VertexLitGeneric
$phongwarptexture <texture> (in all games since <Source><Source>)
Used to create an iridescence effect, as seen on Episode Two's Hunters. To do: How does $phongwarptexture actually work?
Bug.png Bug: Does not work in <Left 4 Dead 2>, despite the game being released in 2009.
Shaders: VertexLitGeneric

Brush Shader Parameters

$phongmaskcontrastbrightness and $phongmaskcontrastbrightness2 <vector2> (only in Counter-Strike: Global Offensive)
The first value controls the contrast level between light and dark areas in the mask, and the second value controls the overall brightness.
$phongmaskcontrastbrightness2 is for WorldVertexTransition's second material.
To do: Find out the range of both values.
Shaders: LightmappedGeneric, WorldVertexTransition
$phongamount and $phongamount2 <vector4> (only in Counter-Strike: Global Offensive)
The first 3 values control the color tint, and the fourth value controls the brightness. The fourth value can go beyond 1, but affects the brightness of the whole texture, not just the highlight.
$phongamount2 is for WorldVertexTransition's second material.
Shaders: LightmappedGeneric, WorldVertexTransition
$phongbasetint and $phongbasetint2 <float> (only in Counter-Strike: Global Offensive)
Allows the $basetexture and/or $basetexture2 to tint the color of the Phong highlight.
Shaders: LightmappedGeneric, WorldVertexTransition

Console Commands

mat_phong <boolean>
Disable or enable phong shading. Default 1.

See also