Phong materials

With the release of Half-Life 2: Episode One a number enhancments were made to the way lighting works within the Source engine. The emphasis was on global illumination in order to ground characters in the game worlds and make them seem to be truly present in their environment.
One of these enhancements was the addtion of Phong shading for players with graphic cards using ps_2_b or later pixel shaders - around 40% at the time of release. This new feature gives texture artists the the ability to include Phong terms which can be driven by specular masks and exponent textures. These integrate naturally with the existing lighting and provides greater definition, particularly to key characters such as Alyx Vance.
The Phong shading can also include a Fresnel term in order to heavily favor rim lighting cases as opposed to specular highlights. Under very bright lights, the specular rim highlights are often bright enough to bloom out in a dramatic fashion as a result of HDR post-processing.
A brief introduction to Phong shading
The following short introduction is not necessary knowledge to use the Source Phong shader, but does provide some technical insights as to how the technique works and may be of interest to some readers.
In simple terms, Phong shading is a technique used in 3D graphics to get better resolution of specular reflections. It was developed by Dr. Bui Tuong Phong at the University of Utah in 1973. His original publications combined the interpolation part of technique with his reflection model, the term Phong shading is commonly used to refer to either just the reflection model or to the combination of the reflection model and the interpolation method.
The Phong Reflection Model
The Phong reflection model is basically a simplified method of deciding the shade of a specific point on a 3D surface.
- It doesn't take into account second-order reflections often found in raytraced or diffuse rendering. To compensate an extra ambient lighting term is added to the scene that is rendered.
- It divides the reflection from a surface into three subcomponents - specular reflection, diffuse reflection and ambient reflection.
Phong reflection is an empirical model based on informal observation. Dr. Phong observed that for very shiny surfaces the specular highlight was small and that the intensity fell off rapidly, while for duller surfaces it was larger and fell off more slowly.
Phong Interpolation
Phong shading provides a better approximation to a per-pixel application of an underlying reflection model by assuming a smoothly varying surface normal vector. The Phong interpolation method works particularly well when applied to the Phong reflection model or to any reflection model that has small specular highlights.
In some modern hardware, variants of the interpolation algorithm are called "pixel shading" (this should not be confused with "pixel shaders"). Usually this means that the lighting calculations can be done per-pixel and include other lighting variables such as surface normals from a normap map which are interpolated across the polygon.
Phong in the Source engine
While the above gives a fairly basic explaination of Phong shading as a concept, the effect you seen in Episode One is in fact the result of a number of combined lighting effects working together. An overview of these effects and how they are combined can be seen in the diagram of the episodic shader tree.
With model lighting, Source uses methods which combine spatially varying directional irradiance samples from the radiosity solution with local light sources and environment mapping. On graphics hardware that supports 2.0 pixel shaders and lower, Source computes diffuse illumination from up to two local light sources, either per pixel or per vertex. On newer graphics chips with longer pixel shaders, Source includes specular contributions with Fresnel terms as well as more custom effects.
Phong shading is part of these extended effects and can be seen in the path starting bottom right of the shader tree. Phong exponent, mask and Fresnel terms are combined to give a specular term which is combined with the diffuse solution in the final output.
The rest of this document will focus on the Phong part of the shading tree explaining how the components work and how to create them.
TODO
Like, loads :D