$phong: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Rewritten, changed to use Shaderparam and MatParam templates)
(Added more parameters, $forcephong, $phongbasetint, $phongbasetint2, $phongmaskcontrastbrightness2, $phongamount2, $phongexponent2, $phongdisablehalflambert doesn't need $halflambert 0, misc fixes)
Line 3: Line 3:
{{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]].
{{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.}}
{{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]]>


{{note|All parameters must be specified otherwise the phong shader won't show up at all, except in {{insurgency}}.}}
{{note|All parameters in the following example must be specified in the material, 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)}}
:{{todo|Other games that don't require all phong parameters present (likely Portal 2 and up)}}
<syntaxhighlight lang=php>
<syntaxhighlight lang=php>
Line 26: Line 26:
=== Masking ===
=== Masking ===


{{MatParam|$bumpmap|texture|There must be a Phong mask. The [[alpha channel]] of a [[$bumpmap|bump map]] acts as a Phong mask by default.}}
{{MatParam|$bumpmap|texture|There must be a Phong mask. The [[alpha channel]] of a <code>[[$bumpmap|bump map]]</code> 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.}}
{{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 bumpmap, however.}}
{{MatParam|$basemapluminancephongmask|bool|Phong intensity is based on the brightness of <code>$basetexture</code>.|since=L4D}}
{{MatParam|$basemapluminancephongmask|bool|Mask phong intensity based on the brightness of the <code>$basetexture</code>.|since=L4D}}
{{MatParam|$phongexponent|int|The numeric value overrides an exponent mask if present.}}
{{MatParam|$phongexponent|int|The numeric value overrides an exponent mask if present.}}
{{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:
{{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:
Line 34: Line 34:
:* '''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:''' {{ent|$rimlight}} mask.
:{{Note|<code>LightmappedGeneric</code> and <code>WorldVertexTransition</code> do not have support for <code>$phongexponenttexture</code>. You must use <code>$phongexponent</code> instead.}}}}
{{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?}}}}
{{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?}}}}
{{MatParam|$phongexponentfactor|int|This number will be used to multiply the exponent texture. {{todo|Is this available in every engine branch?}}}}
{{MatParam|$phongexponentfactor|int|Multiply the exponent texture by this amount. {{todo|Is this available in every engine branch?}}}}
{{MatParam|$forcephong|bool|Force phong to be enabled even at low GPU levels. This requires phong to already be enabled in the material.|since=L4D}}
{{MatParam|$shinyblood|int|only=L4ds}}
{{MatParam|$shinyblood|int|only=L4ds}}
{{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}}
{{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}}
Line 45: Line 47:
{{MatParam|$phongboost|float|Phong brightness factor. Larger values create a more intense highlight, useful for surfaces like metal and glass.}}
{{MatParam|$phongboost|float|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>.}}
{{MatParam|$phongfresnelranges|matrix|See [[Phong materials#Phong Fresnel ranges|Phong Fresnel ranges]]. Default is <code>"[0 0.5 1]"</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}}
{{MatParam|$phongdisablehalflambert|bool|Disables forced [[$halflambert|half-lambertian]] shading on Phong materials.|since=AS}}
{{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?}}}}
{{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?}}}}


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


{{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).
{{MatParam|$phongalbedotint|bool|Allows the <code>$basetexture</code> to tint 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.}}}}
{{MatParam|$phongalbedoboost|float|Phong albedo overbrightening factor. Ranges 0-255. {{todo|Test and add a better description.}}|since=CSGO}}
[[File:Phongwarp example.png|thumb|200px|The Hunter with and without its $phongwarptexture, showing how it ]]
[[File:Phongwarp example.png|thumb|200px|The Hunter without and with its $phongwarptexture, showing how it affects the Phong reflection.]]
{{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).
{{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).
: {{Note|This will override <code>$phongalbedotint</code> if both are used.}}
: {{Warning|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>}}}}
{{MatParam|$phongwarptexture|texture|Used to create an iridescence effect, as seen on Episode Two's [[npc_hunter|Hunters]]. {{Todo|How does $phongwarptexture actually work?}}
{{MatParam|$phongwarptexture|texture|Used to create an iridescence effect, as seen on Episode Two's [[npc_hunter|Hunters]]. {{Todo|How does $phongwarptexture actually work?}}
Line 62: Line 64:
=== Brush Shader Parameters ===
=== Brush Shader Parameters ===


{{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.  
{{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.
: {{todo|Find out the range of both values, and whether or not <code>VertexLitGeneric</code> can support this parameter.}}|since=CSGO}}
: {{todo|Find out the range of both values, and whether or not <code>VertexLitGeneric</code> can support this parameter.}}|since=CSGO}}
{{MatParam|$phongmaskcontrastbrightness2|vector2|<code>WorldVertexTransition</code> only, the same as <code>$phongmaskcontrastbrightness</code>, but for use with the second material.|since=CSGO}}
{{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}}
{{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}}
{{MatParam|$phongamount2|vector4|<code>WorldVertexTransition</code> only, the same as <code>$phongamount</code>, but for use with the second material.|since=CSGO}}
{{MatParam|$phongexponent2|int|<code>WorldVertexTransition</code> only, the same as <code>$phongexponent</code>, but for use with the second material.|since=CSGO}}
{{MatParam|$phongbasetint|float|{{todo|What is this?}}|since=CSGO}}
{{MatParam|$phongbasetint2|float|<code>WorldVertexTransition</code> only, the same as <code>$phongbasetint</code>, but for use with the second material.|since=CSGO}}


== See also ==
== See also ==

Revision as of 16:46, 30 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.

Syntax

$phong <bool>
Note.pngNote:All parameters in the following example must be specified in the material, 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 $forcephong $shinyblood $shinybloodexponent $diffuseexp

Brightness

$phongboost $phongfresnelranges $phongdisablehalflambert $ambientocclusiontexture

Colours

$phongalbedotint $phongalbedoboost

The Hunter without and with its $phongwarptexture, showing how it affects the Phong reflection.

$phongtint $phongwarptexture

Brush Shader Parameters

$phongmaskcontrastbrightness $phongmaskcontrastbrightness2 $phongamount $phongamount2 $phongexponent2 $phongbasetint $phongbasetint2

See also