This is an old revision of the document!
Phong shader
A Phong shader represents a Phong-like reflector. Its bidirectional reflection/transmission distribution functions are as follows:
At a given point x, let cd be the diffuse color (components R, G, B) at that point, α the alpha-component of the diffuse color and ct the transparency color. For each color component, set
cαt = 1 + α (ct - 1)
Let cs be the specular color and n the shininess exponent. Let r be the reflection coefficient as computed by Fresnel equation.
Now if interpolatedTransparency is true, set
- kd = (1 - cαt) cd
- ks = (1 - cαt) cs + r cαt
- kt = (1 - r) cαt
Otherwise, set
- kd = cd
- ks = cs + r cαt
- kt = (1 - r) cαt
The bidirectional reflection distribution function is
BRDF(x, ωi, ωo) = kd / π + ks (n + 2) max(cos β, 0)n / 2π
where β is the angle between ωi and the direction of ideal reflection of ωo. The bidirectional transmission distribution function is
BTDF(x, ωi, ωt) = kt (ηt / ηi)2 δω+ (ωi - T(ωt))
where η stands for the index of refraction, T for the direction of transmission according to Fresnel's formulas, and δω+ is the δ-distribution with respect to projected solid angle ω+.
The Phong shader supports:
- `setDiffuse()` — sets the diffuse (reflected) component
- `setTransparency()` — sets how much light is transmitted
- `setSpecular()` — sets the mirror-like reflection for highlights
- `setShininess()` — controls the size and sharpness of specular highlights
- `setAmbient()` — ambient light scattering in the scene
- `setEmissive()` — defines self-emission of light
- `setInterpolatedTransparency()` — toggles interpolation of transmitted light
Below is an illustration of the effect of specular and shininess:
Note: In modern Phong shader implementations, roughness and glossiness replace specular and shininess.

