Difference between revisions of "$phong"

From Valve Developer Community
Jump to: navigation, search
(Correction of details about phong masks and bumpmaps)
m (Minor fix)
 
(21 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
[[File:Alyx phong closeup.jpg|thumb|200px|Phong shading provides Alyx's skin, hairband and lip highlights.]]
 
[[File:Alyx phong closeup.jpg|thumb|200px|Phong shading provides Alyx's skin, hairband and lip highlights.]]
  
The '''<code>$phong</code>''' [[VMT]] command provides diffuse reflections. In most engine branches it is only available with <code>[[VertexLitGeneric]]</code>; {{csgo}} '''[[Counter-Strike: Global Offensive]]''' (as of early 2015) allows it to a limited extent on <code>[[LightmappedGeneric]]</code>. For a full explanation, see [[Phong materials]].
+
{{Shaderparam|$phong|since=Source 2006|shader1=VertexLitGeneric|shader2=LightmappedGeneric|shader3=WorldVertexTransition}} It provides diffuse reflections, masked by a texture to control its intensity per-texel. For a full explanation, see [[Phong materials]].
 
+
{{Note|Phong shading for <code>LightmappedGeneric</code> and <code>WorldVertexTransition</code> is only available in {{csgo}}. It requires the material to be lit by a {{ent|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.}}
==VMT syntax==
+
==Syntax==
  
 
  $phong <[[bool]]>
 
  $phong <[[bool]]>
  
The Phong shader ''should'' use the default values for any configuration parameters that you omit from your material. However it appears that this doesn't happen. Therefore all of the below parameters are required, even if they stay on their default values.
+
{{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}}.}}
 
+
:{{todo|Other games that don't require all phong parameters present (likely Portal 2 and up)}}
 
<syntaxhighlight lang=php>
 
<syntaxhighlight lang=php>
 
VertexLitGeneric
 
VertexLitGeneric
Line 26: Line 26:
 
=== Masking ===
 
=== Masking ===
  
; <code>$bumpmap <[[texture]]></code>
+
{{MatParam|$bumpmap|texture|There must be a Phong mask. The [[alpha channel]] of a [[$bumpmap|bump map]] acts as a Phong mask by default.}}
: There must be a Phong mask. The [[alpha channel]] of a [[$bumpmap|bump map]] acts as a Phong mask by default.
+
{{MatParam|$basemapalphaphongmask|bool|Use {{ent|$basetexture}}'s [[alpha channel]] as the Phong mask instead of <code>$bumpmap</code>'s. The Phong will not be influenced by the bump map, however.|since={{src07}}|shaders=VertexLitGeneric}}
;<code>$BasemapAlphaPhongMask <bool></code>
+
{{MatParam|$basemapluminancephongmask|bool|Mask phong intensity based on the brightness of the <code>$basetexture</code>.|since={{l4d}}|shaders=VertexLitGeneric}}
: Uses <code>[[$basetexture]]</code>'s [[alpha channel]] as the Phong mask instead of <code>$bumpmap</code>'s. The phong will not be influenced by the bumpmap, however.
+
{{MatParam|$phongexponent|and=$phongexponent2|int|A global [[Phong materials#Phong mask and exponent texture|exponent]] value. Overrides an exponent mask if present.
; {{L4D add|<code>$BasemapLuminancePhongMask <[[bool]]></code>}}
+
: <code>$phongexponent2</code> is for <code>WorldVertexTransition</code>'s second material in {{csgo}}.}}
: Phong intensity is based on the brightness of <code>$basetexture</code>.
+
{{MatParam|$phongexponenttexture|texture|A per-texel exponent map. In an exponent map:
; <code>$PhongExponent <[[int]]></code>
+
:* '''Red channel:''' Exponent mask (size of highlight, 0-255, where a value of 0 is a large highlight, 255 small.)
: The numeric value overrides an exponent mask if present.
+
:* '''Green channel:''' Albedo tint mask (only if <code>$phongalbedotint 1</code>, 0-255, where a value of 0 is no tint, 255 full tint.)
; <code>$PhongExponentTexture <texture></code>  
+
:* '''Blue channel:''' Nothing.
: A global [[Phong materials#Phong mask and exponent texture|exponent]] value, or a per-texel exponent texture map. In an exponent map:
+
:* '''Alpha channel:''' {{ent|$rimlight}} mask (only if <code>$rimmask 1</code>.)
:* '''Red channel:''' Exponent (size of highlight, 0-255, where a value of 0 is a large highlight, 255 small.)
+
:{{Note|<code>LightmappedGeneric</code> and <code>WorldVertexTransition</code> do not have support for <code>$phongexponenttexture</code>. You must use <code>$phongexponent</code> instead.}}|shaders=VertexLitGeneric}}
:* '''Green channel:''' Albedo tint (if <code>$phongalbedotint 1</code>, higher is more tint)
+
{{MatParam|$phongexponentfactor|int|Multiply the exponent texture by this amount.|only={{src13mp}}|shaders=VertexLitGeneric}}
:* '''Blue channel:''' Nothing
+
{{MatParam|$invertphongmask|bool|Invert the value of the phong mask. {{todo|What types of mask does this work on?}}|since={{src07}}|shaders=VertexLitGeneric}}
:* '''Alpha channel:''' <code>[[$rimlight]]</code> mask
+
{{MatParam|$forcephong|bool|Force phong shading on phong materials even at low GPU levels. This requires the convar <code>mat_phong</code> to be set to 1, otherwise it won't work.{{confirm}}|since={{l4d}}|shaders=VertexLitGeneric}}
; <code>$InvertPhongMask <bool></code>
+
{{MatParam|$diffuseexp|float|{{todo|Does this have something to do with the $phongexponent, $phongexponenttexture or both?}}|only={{L4ds}}}}
: Appears to invert the value of the phong mask, as the name suggests. {{todo|1=What types of mask does this work on?}}
+
{{MatParam|$shinyblood|int|only={{L4ds}}}}
; <code>$PhongExponentFactor <[[int]]></code>
+
{{MatParam|$shinybloodexponent|int|{{todo|1=See ''[https://steamcdn-a.akamaihd.net/apps/valve/2010/GDC10_ShaderTechniquesL4D2.pdf#page=33 Shading a Bigger, Better Sequel: Techniques in Left 4 Dead 2]''.}}|only={{L4ds}}}}
: This number will be used to multiply the exponent texture.
 
; {{L4D add|<code>$shinyblood <[[int]]></code>}}
 
; {{L4D add|<code>$shinybloodexponent <int></code>}}
 
: {{todo|1=See ''[http://www.valvesoftware.com/publications/2010/GDC10_ShaderTechniquesL4D2.pdf#page=33 Shading a Bigger, Better Sequel: Techniques in Left 4 Dead 2]''.}}
 
; <code>$allowdiffusemodulation <int></code>
 
: {{todo}}
 
; <code>$DiffuseExp</code>
 
: {{todo|Does this have something to do with the ''$phongexponent'', ''$phongexponenttexture or both?}}
 
  
 
=== Brightness ===
 
=== Brightness ===
  
; <code>$phongboost <[[int]]></code>
+
{{MatParam|$phongboost|float|Phong brightness factor. Larger values create a more intense highlight, useful for surfaces like metal and glass.|shaders=VertexLitGeneric}}
: Phong brightness factor. Larger values create a more intense highlight, useful for surfaces like metal and glass.
+
{{MatParam|$phongfresnelranges|matrix|See [[Phong materials#Phong Fresnel ranges|Phong Fresnel ranges]]. Default is <code>"[0 0.5 1]"</code>.
; <code>$PhongFresnelRanges <matrix></code>
+
:{{note|<code>$envmap</code> is also affected by these fresnel ranges if both it and Phong are enabled in a material.}}|shaders=VertexLitGeneric}}
: See [[Phong materials#Phong Fresnel ranges|Phong Fresnel ranges]]. Default is <code>"[0 0.5 1]"</code>.
+
{{MatParam|$phongdisablehalflambert|bool|Disables forced [[$halflambert|half-lambertian]] shading on Phong materials.|since={{as}}|also={{Mapbase}}|shaders=VertexLitGeneric}}
; <code>$PhongDisableHalfLambert <bool></code> {{P2 add}}
 
: Used in [[Portal 2]] on the Personality Cores such as Wheatley, disables functionality of $halflambert. MAY need <code>$halflambert 0</code>!
 
;<code>$AmbientOcclusionTexture <texture></code>
 
: A "dirtmap". Mentioned in the SDK samples and seen in the VMT for Alyx's face. [[$ambientocclusion|Ambient Occlusion]] is generally used for the eyes and face.
 
  
=== Colours ===
+
=== Colors ===
  
; <code>$PhongAlbedoTint <bool></code>
+
{{MatParam|$phongalbedotint|bool|Tints the phong reflection by the color of the <code>$basetexture</code>. The amount of tint is defined by the green channel of <code>$phongexponenttexture</code>. A <code>$phongexponenttexture</code> must be specified in order for <code>$phongalbedotint</code> to work.
: Allows the <code>[[$basetexture]]</code> to affect the colour of the Phong highlight. The amount of tint is defined by the green channel of <code>$phongexponenttexture</code> (see above).
+
: {{Note|<code>$phongalbedotint</code> works by multiplying the <code>$basetexture</code> 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 <code>$phongboost</code>.}}
; <code>$phongtint "[<red [[float]]> <green float> <blue float>]"</code>
+
: {{Note|<code>$phongalbedotint</code> will tint highlights by the original color of the <code>$basetexture</code> even when the material is tinted by <code>$color2</code> or <code>rendercolor.</code>}}|since={{src07}}|shaders=VertexLitGeneric}}
: Modifies the colour of the phong reflection. The channels are interpreted relative to each other (so "[0 0 0]" and "[1 1 1]" are the same).
+
{{MatParam|$phongalbedoboost|float|Phong albedo overbrightening factor. Ranges 0-255. {{todo|Test and add a better description.}}|since={{csgo}}|shaders=VertexLitGeneric}}
; <code>$PhongWarpTexture <texture></code> {{EP2 add}}
+
[[File:Phongwarp example.png|thumb|200px|The Hunter without and with its $phongwarptexture, showing how it affects the Phong reflection.]]
: {{todo|Used to create an iridescence effect, as seen on [[npc_hunter]]s.}}
+
{{MatParam|$phongtint|RGB matrix|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|This will override <code>$phongalbedotint</code> if both are used.}}
 +
: {{bug|This does not work with <code>$basemapalphaphongmask.</code>}}|since={{src07}}|shaders=VertexLitGeneric}}
 +
{{MatParam|$phongwarptexture|texture|Used to create an iridescence effect, as seen on Episode Two's [[npc_hunter|Hunters]]. {{Todo|How does $phongwarptexture actually work?}}
 +
: {{note|Does not work in {{l4d2}}, despite the game being released in 2009.}}|since={{src07}}|shaders=VertexLitGeneric}}
  
== Phong shading on brush faces ==
+
=== Brush Shader Parameters ===
  
A May 2015 update to {{csgo}} '''[[Counter-Strike: Global Offensive]]''' added limited support for Phong-based highlights on <code>[[LightmappedGeneric]]</code> materials. Currently it only works when the material is directly lit by an env_cascade_lighting, using the dynamic shadows as a mask (although traditional Phong masking is supported on top of this). It is known to work on displacements as well as <code>[[WorldVertexTransition]]</code> materials, but not water or <code>[[Lightmapped_4WayBlend]]</code>.
+
{{MatParam|$phongmaskcontrastbrightness|and=$phongmaskcontrastbrightness2|vector2|The first value controls the contrast level between light and dark areas in the mask, and the second value controls the overall brightness.
 +
: <code>$phongmaskcontrastbrightness2</code> is for <code>WorldVertexTransition</code>'s second material.
 +
: {{todo|Find out the range of both values.}}|only={{csgo}}|shaders=LightmappedGeneric, WorldVertexTransition}}
 +
{{MatParam|$phongamount|and=$phongamount2|vector4|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.  
 +
: <code>$phongamount2</code> is for <code>WorldVertexTransition</code>'s second material.|only={{csgo}}|shaders=LightmappedGeneric, WorldVertexTransition}}
 +
{{MatParam|$phongbasetint|and=$phongbasetint2|float|Allows the <code>$basetexture</code> and/or <code>$basetexture2</code> to tint the color of the Phong highlight.|only={{csgo}}|shaders=LightmappedGeneric, WorldVertexTransition}}
  
=== New Parameters ===
+
== Console Commands ==
  
; <code>$phongMaskContrastBrightness "[<float> <float>]"</code>
+
{{IO|mat_phong|param=bool|Disable or enable phong shading. Default 1.}}
: Defines the contrast level between light and dark areas in the mask, and the overall brightness, respectively. Added along with support for phong-shaded lightmapped textures. {{todo|Find out the range of both values, and whether or not it can be used on models.}}
 
; <code>$phongAmount "[<red float> <green float> <blue float> <brightness> float]"</code>
 
: Controls the tint and brightness. The fourth value can go beyond 1, but affects the brightness of the whole texture, not just the highlight.
 
  
 
== See also ==
 
== See also ==

Latest revision as of 20:26, 15 November 2020

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.

Syntax

$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)
VertexLitGeneric
{
	$phong 1

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

Parameters

Masking

$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 <Left 4 Dead>)
Force phong shading on phong materials even at low GPU levels. This requires the convar mat_phong to be set to 1, otherwise it won't work.[confirm]
Shaders: VertexLitGeneric
$diffuseexp <float> (only in <Left 4 Dead><Left 4 Dead 2>)
To do: Does this have something to do with the $phongexponent, $phongexponenttexture or both?
$shinyblood <integer> (only in <Left 4 Dead><Left 4 Dead 2>)
$shinybloodexponent <integer> (only in <Left 4 Dead><Left 4 Dead 2>)
To do: See Shading a Bigger, Better Sequel: Techniques in Left 4 Dead 2.

Brightness

$phongboost <float>
Phong brightness factor. Larger values create a more intense highlight, useful for surfaces like metal and glass.
Shaders: VertexLitGeneric
$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
$phongdisablehalflambert <boolean> (in all games since <Alien Swarm>)  (also in <Mapbase>)
Disables forced half-lambertian shading on Phong materials.
Shaders: VertexLitGeneric

Colors

$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. 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?
Note.png Note: 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