$phong: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Added description for how phongwarptexture works and illustration of computed coordinates)
(Added brush phong image, added a note about $phongdisablehalflambert in CSGO)
Line 2: Line 2:


{{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 the sunlight from 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> is also available in {{mapbase}}.}}
{{Note|Phong shading for <code>LightmappedGeneric</code> is also available in {{mapbase}}, but it is implemented differently.}}
==Syntax==
==Syntax==


Line 51: Line 51:
:{{note|<code>$envmap</code> is also affected by these fresnel ranges if both it and Phong are enabled in a material.}}
:{{note|<code>$envmap</code> is 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.}}|shaders=VertexLitGeneric, LightmappedGeneric({{mapbase}})}}
:{{note| drives the x component of a phongwarptexture if specified.}}|shaders=VertexLitGeneric, LightmappedGeneric({{mapbase}})}}
{{MatParam|$phongdisablehalflambert|bool|Disables forced [[$halflambert|half-lambertian]] shading on Phong materials.|since={{as}}|also={{Mapbase}}|shaders=VertexLitGeneric}}
{{MatParam|$phongdisablehalflambert|bool|Disables forced [[$halflambert|half-lambertian]] shading on Phong materials. {{note|This parameter is effectively forced on in {{csgo}} due to <code>$halflambert</code> being disabled.}}|since={{as}}|also={{Mapbase}}|shaders=VertexLitGeneric}}


=== Colors ===
=== Colors ===
Line 69: Line 69:
: The highlight is multiplied with a texture. The coordinates of the sampled pixel are as follows:
: 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)
:x: 1 - (distance to the center of the highlight)
:y: 1 - (fresnel component as computed by [[Phong materials#Phong Fresnel ranges|Phong Fresnel ranges]])
:y: 1 - (fresnel component as computed by [[Phong materials#Phong Fresnel ranges|Phong Fresnel ranges]])
: {{note|Disables the initial phongfresnelranges masking}}
: {{note|Disables the initial phongfresnelranges masking}}
: {{bug|Does not work in {{l4d2}}, despite the game being released in 2009.}}|since={{src07}}|shaders=VertexLitGeneric}}
: {{bug|Does not work in {{l4d2}}, despite the game being released in 2009.}}|since={{src07}}|shaders=VertexLitGeneric}}
[[File:Brush_phong.jpg|thumb|200px|Brush phong in {{csgo}}. Note the complete absence of the reflection in the shaded area.]]


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

Revision as of 23:30, 10 October 2021

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 the sunlight from 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.pngNote:Phong shading for LightmappedGeneric is also available in Mapbase, but it is implemented differently.

Syntax

$phong <bool>
Note.pngNote: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)
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 $phongexponentfactor $invertphongmask $forcephong $diffuseexp $shinyblood $shinybloodexponent

Brightness

$phongboost $phongfresnelranges $phongdisablehalflambert

Colors

$phongalbedotint $phongalbedoboost

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

$phongtint

Breakdown of the $phongwarptexture: computed coordinates, texture and result

$phongwarptexture

Brush phong in Counter-Strike: Global Offensive. Note the complete absence of the reflection in the shaded area.

Brush Shader Parameters

$phongmaskcontrastbrightness $phongamount $phongbasetint

Console Commands

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

See also