Cook-Torrance Specular Reflection in glTF

This article provides an overview of how the glTF 2.0 specification implements the Cook-Torrance microfacet BRDF (Bidirectional Reflectance Distribution Function) to calculate specular reflection. It breaks down the mathematical formulation defined by the standard, detailing the specific Normal Distribution Function (NDF), Geometric shadowing/masking function, and Fresnel approximation used, as well as how glTF’s standard material inputs feed into these calculations.

The Cook-Torrance Specular Formulation

In glTF 2.0, physically based rendering (PBR) relies on the microfacet Cook-Torrance model to simulate the specular highlight produced by microscopic surface irregularities. The general Cook-Torrance specular BRDF is defined as:

\[f_{\text{specular}} = \frac{D \cdot F \cdot G}{4 (\mathbf{N} \cdot \mathbf{L})(\mathbf{N} \cdot \mathbf{V})}\]

Where:

  • \(\mathbf{N}\) is the surface normal vector.
  • \(\mathbf{L}\) is the unit vector pointing toward the light source.
  • \(\mathbf{V}\) is the unit vector pointing toward the camera/viewer.
  • \(D\) is the Normal Distribution Function.
  • \(F\) is the Fresnel reflection term.
  • \(G\) is the Geometric attenuation or shadowing-masking function.

To optimize computation, real-time renderers and the glTF specification often combine the geometric term and the denominator into a single visibility function, \(V\):

\[V = \frac{G}{4 (\mathbf{N} \cdot \mathbf{L})(\mathbf{N} \cdot \mathbf{V})}\]

Which simplifies the equation to:

\[f_{\text{specular}} = D \cdot F \cdot V\]

1. Normal Distribution Function (\(D\)): Trowbridge-Reitz (GGX)

The Normal Distribution Function determines the concentration and alignment of microfacets relative to the half-vector \(\mathbf{H}\) (where \(\mathbf{H} = \frac{\mathbf{L} + \mathbf{V}}{\|\mathbf{L} + \mathbf{V}\|}\)).

glTF adopts the Trowbridge-Reitz (GGX) distribution:

\[D(\mathbf{N}, \mathbf{H}, \alpha) = \frac{\alpha^2}{\pi \left( (\mathbf{N} \cdot \mathbf{H})^2 (\alpha^2 - 1) + 1 \right)^2}\]

In this formula, \(\alpha\) represents surface roughness mapped linearly from glTF's perceptual roughness parameter (\(\alpha = \text{roughness}^2\)). This formulation produces a highlight with a sharp peak and realistic, long falloff tails.

2. Visibility and Shadowing-Masking Function (\(V\) / \(G\))

The Geometric term accounts for microfacets occluding one another, either blocking light from arriving (shadowing) or blocking light from reaching the viewer (masking).

glTF specifies the Smith joint masking-shadowing function correlated for the GGX distribution. When expressed as the visibility term \(V\), it takes the following form:

\[V = \frac{0.5}{(\mathbf{N} \cdot \mathbf{L}) \sqrt{(\mathbf{N} \cdot \mathbf{V})^2 (1 - \alpha^2) + \alpha^2} + (\mathbf{N} \cdot \mathbf{V}) \sqrt{(\mathbf{N} \cdot \mathbf{L})^2 (1 - \alpha^2) + \alpha^2}}\]

This joint formulation models height-correlated microfacets, ensuring energy conservation and preventing unnatural brightening at grazing angles.

3. Fresnel Reflectance (\(F\)): Schlick's Approximation

The Fresnel term describes the fraction of reflected light versus refracted light depending on the angle of incidence. glTF uses Fresnel-Schlick approximation:

\[F(\mathbf{V}, \mathbf{H}, F_0) = F_0 + (1 - F_0)(1 - (\mathbf{V} \cdot \mathbf{H}))^5\]

Where \(F_0\) represents the specular reflectance at normal incidence (facing directly toward the surface).

Parameter Mapping from glTF Inputs

glTF’s core metallic-roughness workflow dictates the values used by these functions:

  • Roughness: The roughnessFactor and the green channel of the metallicRoughnessTexture define perceptual roughness, which is squared to yield \(\alpha\) for the \(D\) and \(V\) terms.
  • \(F_0\) (Reflectance at Normal Incidence): Computed by interpolating between a fixed dielectric reflectance and the base color:
    • For pure dielectrics (metalness = 0), \(F_0\) defaults to a standard reflectance of 4% (vec3(0.04)).
    • For pure metals (metalness = 1), \(F_0\) is taken directly from the material's baseColorFactor and texture.
    • Intermediate metallic values linearly interpolate between 0.04 and the base color.