$phong: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Added phongwarp example image, added note that $phongtint overrides $phongalbedotint, misc changes)
(Rewritten, changed to use Shaderparam and MatParam templates)
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>''' [[material]] parameter provides diffuse reflections. In most engine branches it is only available on <code>[[VertexLitGeneric]]</code>; {{csgo}} '''[[Counter-Strike: Global Offensive]]''' (as of early 2015) allows it to a limited extent on <code>[[LightmappedGeneric]]</code> and <code>[[WorldVertexTransition]].</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==
==VMT syntax==


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|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.}}
;<code>$basemapalphaphongmask <bool></code>
{{MatParam|$basemapluminancephongmask|bool|Phong intensity is based on the brightness of <code>$basetexture</code>.|since=L4D}}
: 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|int|The numeric value overrides an exponent mask if present.}}
; {{L4D add|<code>$basemapluminancephongmask <[[bool]]></code>}}
{{MatParam|$phongexponenttexture|texture|A global [[Phong materials#Phong mask and exponent texture|exponent]] value, or a per-texel exponent texture map. In an exponent map:
: Phong intensity is based on the brightness of <code>$basetexture</code>.
; <code>$phongexponent <[[int]]></code>
: The numeric value overrides an exponent mask if present.
; <code>$phongexponenttexture <texture></code>
: A global [[Phong materials#Phong mask and exponent texture|exponent]] value, or a per-texel exponent texture map. In an exponent map:
:* '''Red channel:''' Exponent (size of highlight, 0-255, where a value of 0 is a large highlight, 255 small.)
:* '''Red channel:''' Exponent (size of highlight, 0-255, where a value of 0 is a large highlight, 255 small.)
:* '''Green channel:''' Albedo tint (if <code>$phongalbedotint 1</code>, higher is more tint)
:* '''Green channel:''' Albedo tint (if <code>$phongalbedotint 1</code>, higher is more tint)
:* '''Blue channel:''' Nothing
:* '''Blue channel:''' Nothing
:* '''Alpha channel:''' <code>[[$rimlight]]</code> mask
:* '''Alpha channel:''' <code>[[$rimlight]]</code> mask.}}
; <code>$invertphongmask <bool></code>
{{MatParam|$invertphongmask|bool|Appears to invert the value of the phong mask, as the name suggests. {{todo|What types of mask does this work on?}}}}
: Appears to invert the value of the phong mask, as the name suggests. {{todo|1=What types of mask does this work on?}}
{{MatParam|$phongexponentfactor|int|This number will be used to multiply the exponent texture. {{todo|Is this available in every engine branch?}}}}
; <code>$phongexponentfactor <[[int]]></code>
{{MatParam|$shinyblood|int|only=L4ds}}
: This number will be used to multiply the exponent texture.
{{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}}
; {{L4D add|<code>$shinyblood <[[int]]></code>}}
{{MatParam|$diffuseexp|float|{{todo|Does this have something to do with the <code>$phongexponent</code>, <code>$phongexponenttexture</code> or both? Confirm engine branches, likely Left 4 Dead series only.}}}}
; {{L4D add|<code>$shinybloodexponent <int></code>}}
: {{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]''.}}
; <code>$diffuseexp</code>
: {{todo|Does this have something to do with the <code>$phongexponent</code>, <code>$phongexponenttexture</code> or both? Confirm engine branches.}}


=== Brightness ===
=== Brightness ===


; <code>$phongboost <[[float]]></code>
{{MatParam|$phongboost|float|Phong brightness factor. Larger values create a more intense highlight, useful for surfaces like metal and glass.}}
: 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>
{{MatParam|$phongDisableHalfLambert|bool|Used in [[Portal 2]] on the Personality Cores such as Wheatley, disables functionality of $halflambert. MAY need <code>$halflambert 0</code>!|since=AS}}
: See [[Phong materials#Phong Fresnel ranges|Phong Fresnel ranges]]. Default is <code>"[0 0.5 1]"</code>.
{{MatParam|$ambientocclusiontexture|texture|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. {{Todo|Does this actually do anything?}}}}
; <code>$phongDisableHalfLambert <bool></code> {{AS 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. {{Todo|Does this actually do anything?}}


=== Colours ===
=== Colours ===


; <code>$phongalbedotint <bool></code>
{{MatParam|$phongalbedotint|bool|Allows the <code>[[$basetexture]]</code> to affect the color of the Phong highlight. The amount of tint is defined by the green channel of <code>$phongexponenttexture</code> (see above).
: Allows the <code>[[$basetexture]]</code> to affect the color of the Phong highlight. The amount of tint is defined by the green channel of <code>$phongexponenttexture</code> (see above).
: {{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>}}}}
: {{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>}}
{{MatParam|$phongalbedoboost|float|Phong albedo overbrightening factor. Ranges 0-255. {{todo|Test and add a better description.}}}}
; <code>$phongalbedoboost <float></code> {{CSGO add}}
[[File:Phongwarp example.png|thumb|200px|The Hunter with and without its $phongwarptexture, showing how it ]]
: Phong albedo overbrightening factor. Ranges 0-255. {{todo|Test and add a better description.}}
{{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).
; <code>$phongtint "[<red [[float]]> <green float> <blue float>]"</code>
: 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).
[[File:Phongwarp example.png|thumb|200px|]]
: {{Note|This will override <code>$phongalbedotint</code> if both are used.}}
: {{Note|This will override <code>$phongalbedotint</code> if both are used.}}
: {{bug|This does not work with <code>$basemapalphaphongmask.</code>}}
: {{bug|This does not work with <code>$basemapalphaphongmask.</code>}}}}
; <code>$phongwarptexture <texture></code> {{EP2 add}}
{{MatParam|$phongwarptexture|texture|Used to create an iridescence effect, as seen on Episode Two's [[npc_hunter|Hunters]]. {{Todo|How does $phongwarptexture actually work?}}
: 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=EP2}}
: {{note|Does not work in {{l4d2}}, despite the game being released in 2009.}}
 
== Phong shading on brush faces ==
 
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 on water or <code>[[Lightmapped_4WayBlend]]</code>.


=== New Parameters ===
=== Brush Shader Parameters ===


; <code>$phongMaskContrastBrightness "[<float> <float>]"</code>
{{MatParam|$phongmaskcontrastbrightness|vector2|<code>LightmappedGeneric</code> and <code>WorldVertexTransition</code> only. The first value controls the contrast level between light and dark areas in the mask, and the second value controls the overall brightness.  
: 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.}}
: {{todo|Find out the range of both values, and whether or not <code>VertexLitGeneric</code> can support this parameter.}}|since=CSGO}}
; <code>$phongAmount "[<red float> <green float> <blue float> <brightness> float]"</code>
{{MatParam|$phongamount|vector4|<code>LightmappedGeneric</code> and <code>WorldVertexTransition</code> only. 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.|since=CSGO}}
: 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 ==

Revision as of 10:52, 17 July 2019

Phong shading provides Alyx's skin, hairband and lip highlights.

Template:Shaderparam It provides diffuse reflections, masked by a texture to control its intensity per-texel. For a full explanation, see Phong materials.

Note.pngNote: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.

VMT syntax

$phong <bool>
Note.pngNote:All parameters must be specified otherwise the phong shader 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)
VertexLitGeneric
{
	$phong 1

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

Parameters

Masking

$bumpmap $basemapalphaphongmask $basemapluminancephongmask $phongexponent $phongexponenttexture $invertphongmask $phongexponentfactor $shinyblood $shinybloodexponent $diffuseexp

Brightness

$phongboost $phongfresnelranges $phongDisableHalfLambert $ambientocclusiontexture

Colours

$phongalbedotint $phongalbedoboost

The Hunter with and without its $phongwarptexture, showing how it

$phongtint $phongwarptexture

Brush Shader Parameters

$phongmaskcontrastbrightness $phongamount

See also