Table of Contents

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

Otherwise, set

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) = ktt / η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:

  1. `setDiffuse()` — sets the diffuse (reflected) component
  2. `setTransparency()` — sets how much light is transmitted
  3. `setSpecular()` — sets the mirror-like reflection for highlights
  4. `setShininess()` — controls the size and sharpness of specular highlights
  5. `setAmbient()` — ambient light scattering in the scene
  6. `setEmissive()` — defines self-emission of light
  7. `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.

References: