Julius Ikkala

Directional reflectance of GGX / Trowbridge-Reitz BRDF

This article derives a fast and quite accurate approximation for the directional reflectance / albedo / split-sum BRDF lookup table of the Trowbridge-Reitz microfacet model, also known as? GGX [1].

The directional reflectance of a BRDF fr(ωo,ωi)f_r(\omega_o, \omega_i) is defined as:

ρ(ωo)=∫Ωfr(ωo,ωi)∣n⋅ωi∣dωi\rho(\omega_o) = \int_\Omega f_r(\omega_o, \omega_i)|n \cdot \omega_i|d\omega_i

Directional reflectance is also called albedo in many sources, which is technically correct, but can be confusing due to how albedo is usually used specifically to refer to the color of diffuse surfaces. The reflectance is often tabulated in a couple of lookup textures, with the horizontal axis being viewing angle cos⁡(θo)\cos(\theta_o) and vertical axis being "roughness" α\sqrt{\alpha}. I've also taken the square root of cos⁡(θo)\cos(\theta_o) here because it produces a significantly better approximation and emphasizes the difficult corner in the visualizations.

A black and white surface graph of a BRDF LUT. A black and white surface graph of a BRDF LUT.
Just interpolating between these two textures is enough to accurately reconstruct ρ(ωo)\rho(\omega_o).

Assumptions

This approximation is only valid when using this microfacet BRDF:

fr(ωo,ωi)=F(ωo,ωm)G2(ωo,ωi)D(ωm)4(ωo⋅n)(ωi⋅n) f_r(\omega_o, \omega_i) = \frac{F(\omega_o, \omega_m)G_2(\omega_o, \omega_i)D(\omega_m)}{4 (\omega_o \cdot n) (\omega_i \cdot n)}

Where:

This is a fairly standard setup, although some opt for the non-height-correlated masking-shadowing function instead.

Approximation

First, let's start by inserting the definition of the fresnel term to the integral. Note that because F(ωo,ωm)F(\omega_o, \omega_m) is also part of the definition of fr(ωo,ωi)f_r(\omega_o, \omega_i), the division can easily be simplified away.

ρ(ωo)=∫ΩF(ωo,ωm)fr(ωo,ωi)F(ωo,ωm)∣n⋅ωi∣dωi=∫Ω(F0+(1−F0)⋅(1.0−ωo⋅ωm)5)fr(ωo,ωi)F(ωo,ωm)∣n⋅ωi∣dωi \begin{align*} \rho(\omega_o) &= \int_\Omega F(\omega_o, \omega_m) \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}|n \cdot \omega_i|d\omega_i\\ &= \int_\Omega (F_0 + (1 - F_0) \cdot (1.0 - \omega_o \cdot \omega_m)^5) \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}|n \cdot \omega_i|d\omega_i \\ \end{align*}

Now, we notice that we can actually split the integral due to how Schlick s Fresnel term is formulated. (If this sounds familiar, this is similar to one step in the split-sum approximation [4], but not the exact same.)

ρ(ωo)=F0∫Ωfr(ωo,ωi)F(ωo,ωm)∣n⋅ωi∣dωi+(1−F0)∫Ω(1.0−ωo⋅ωm)5fr(ωo,ωi)F(ωo,ωm)∣n⋅ωi∣dωi \begin{align*} \rho(\omega_o) =& F_0 \int_\Omega \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}|n \cdot \omega_i|d\omega_i \\ &+ (1 - F_0) \int_\Omega (1.0 - \omega_o \cdot \omega_m)^5 \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}|n \cdot \omega_i|d\omega_i \end{align*}

Let's assign names to the two integrals:

a=∫Ω(1.0−ωo⋅ωm)5fr(ωo,ωi)F(ωo,ωm)∣n⋅ωi∣dωia = \int_\Omega (1.0 - \omega_o \cdot \omega_m)^5 \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}|n \cdot \omega_i|d\omega_i
b=∫Ωfr(ωo,ωi)F(ωo,ωm)∣n⋅ωi∣dωib = \int_\Omega \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}|n \cdot \omega_i|d\omega_i

Therefore, ρ(ωo)=(1−F0)⋅a+F0⋅b=lerp(a,b,F0)\rho(\omega_o) = (1 - F_0) \cdot a + F_0 \cdot b = \mathrm{lerp}(a, b, F_0). Now, all we have to do is find good approximations for aa and bb.

A black and white surface graph of a BRDF LUT. A black and white surface graph of a BRDF LUT.
This is the same figure as above. The left image is aa, the right is bb.

Because the isotropic GGX BRDF is, well, isotropic, we don't have to concern ourselves with ϕo\phi_o (azimuthal angle of view vector) and don't care about the tangent or bitangent. We only care about the altitude angle θo\theta_o, and specifically cos⁡(θo)=n⋅ωo\cos(\theta_o) = n \cdot \omega_o. We'll be using cos⁡(θo)\sqrt{\cos(\theta_o)} a lot, so let's abbreviate it:

β=cos⁡(θo) \beta = \sqrt{\cos(\theta_o)}

ρ(ωo)\rho(\omega_o) has a diagonal ridge near the α=0\alpha = 0, β=0\beta = 0 corner, which is represented by rr:

r=sin⁡(2arctan⁡(β2/α))=2β2αβ4+α2 r = \sin(2\arctan(\beta^2/\alpha)) = \frac{2 \beta^2 \alpha}{\beta^4 + \alpha^2}

We specifically want to avoid sin⁡\sin and arctan⁡\arctan because they are slow to evaluate. Luckily, this identity lets us get away with one reciprocal instead. That ridge only affects near the α=0\alpha = 0, β=0\beta = 0 corner, so we define another factor, ww, to diminish its effect further away:

w=(1−β)⋅(1−α) w = (1 - \beta)\cdot(1 - \alpha)

Next, we'll approximate a value for the aa integral. In addition to the ridge rr, we use a rational function for this. The numerator polynomial is:

Pa=1−2.22452314β+1.22452314β2 P_a = 1 - 2.22452314 \beta + 1.22452314 \beta^2

And the denominator polynomial is:

Qa=1−2.15801349+3.64186555β2+14.18391971α+3.5139459α2−27.04171425βα+56.72939571βα2 \begin{align*} Q_a = 1 &- 2.15801349 + 3.64186555 \beta^2 + 14.18391971 \alpha \\ &+ 3.5139459 \alpha^2 - 27.04171425 \beta \alpha + 56.72939571 \beta \alpha^2 \end{align*}

With the rational function and ridge, we get a pretty good approximation for aa:

a≈PaQa+0.32726712rw2−0.45161784rw3 a \approx \frac{P_a}{Q_a} + 0.32726712 r w^2 - 0.45161784 r w^3
Reference surface graph for a. Fitted surface graph for a.
The left side is the lookup table, while the right side is our new fit, aa. Pretty good, right?

Next, we'll approximate bb. The fit I came up with is a big multivariate polynomial:

b≈1.0−0.72206968βα2−11.21080953β2α2+14.17520803β3α2−3.89135049β4α2−0.1273335βα3+21.45972561β2α3−28.42641268β3α3+7.85826656β4α3+0.60274702βα4−13.04437201β2α4+18.40509904β3α4+−5.77186108β4α4−0.292659rw+0.19974786rw2 \begin{align*} b \approx &1.0 - 0.72206968 \beta \alpha^2 -11.21080953 \beta^2 \alpha^2 + 14.17520803 \beta^3 \alpha^2\\ &-3.89135049 \beta^4 \alpha^2 - 0.1273335 \beta \alpha^3 + 21.45972561 \beta^2 \alpha^3\\ &-28.42641268 \beta^3 \alpha^3 + 7.85826656 \beta^4 \alpha^3 + 0.60274702 \beta \alpha^4 \\ &-13.04437201 \beta^2 \alpha^4 + 18.40509904 \beta^3 \alpha^4 + -5.77186108 \beta^4 \alpha^4 \\ &-0.292659 r w + 0.19974786 r w^2 \end{align*}
Reference surface graph for b. Fitted surface graph for b.
Again, ground truth on the left, fit on the right. This one's even better.

Finally, we have everything we need for ρ(ωo)\rho(\omega_o):

ρ(ωo)=(1−F0)⋅a+F0⋅b \rho(\omega_o) = (1-F_0) \cdot a + F_0 \cdot b

I know this looks like a lot, but most of it boils down to fused multiply-add operations, which are super cheap on GPUs.

Error

Difference to ground truth at F0=0F_0 = 0

At F0=0F_0 = 0:

Difference to ground truth at F0=1F_0 = 1

At F0=1F_0 = 1:

Background

The directional reflectance is used for layering BRDFs [5] as it allows us to determine the amount of energy that can pass into a lower layer without violating the conservation of energy. It is also used in some cheap approximations of multiple scattering [6].

ρ(ωo)\rho(\omega_o) can also be used as a prior for importance sampling. In a material mixing multiple BRDFs, we'll want to prioritize the lobe with higher directional reflectance, as it is more likely to contribute more.

But perhaps most famously, it is used to weigh the intensity of pre-filtered lighting in image-based lighting, using the split-sum approximation [4]. One part of the method is the tabulation of directional reflectance. If one approached this naively, you'd need a 3D LUT, where the axes are n⋅ωon \cdot \omega_o (view angle), α\alpha (roughness), and F0F_0 (derived from index of refraction).

However, they realize that when we're using Schlick's approximation (as nearly everyone is) for the Fresnel term, one can actually separate the integral into two components, factoring out F0F_0:

ρ(ωo)=F0∫Ωfr(ωo,ωi)F(ωo,ωm)(1−(1−ωo⋅ωm)5)∣n⋅ωi∣dωi+∫Ωfr(ωo,ωi)F(ωo,ωm)(1−ωo⋅ωm)5∣n⋅ωi∣dωi \begin{align*} \rho(\omega_o) = F_0 &\int_\Omega \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}(1-(1-\omega_o \cdot \omega_m)^5) |n \cdot \omega_i|d\omega_i \\ + &\int_\Omega \frac{f_r(\omega_o, \omega_i)}{F(\omega_o, \omega_m)}(1-\omega_o \cdot \omega_m)^5 |n \cdot \omega_i|d\omega_i \end{align*}

This equation is exact as long as fr(ωo,ωi)∝F(ωo,ωm)f_r(\omega_o, \omega_i) \propto F(\omega_o, \omega_m). It is very similar to the split we performed in this article. It serves the same purpose of making the integrals independent of F0F_0, and served as inspiration. However, I found the first integral quite difficult to fit analytically, as there is just a bit too much going on:

Image of the first integral in the split-sum approximation.
While the second integral matches our aa, the first one is a bit more complicated and resembles some kind of a saddle function.

A rational function fit for ρ(ωo)\rho(\omega_o) is also provided in a Ray Tracing Gems article [7]. Unless I made an error implementing it, this fit is not that great in my opinion... It is missing a lot of detail to the point of barely resembling ρ(ωo)\rho(\omega_o) and can go above 1.

Copy-pasteable code

HLSL / Slang:

// CC0 / public domain, from https://jji.fi/math/ggx-albedo.html
float ggxDirectionalReflectance(float cosTheta, float alpha, float F0)
{
    float beta = sqrt(cosTheta);
    float beta2 = cosTheta;
    float alpha2 = alpha * alpha;

    float r = beta2 * alpha * rcp(mad(beta2, beta2, alpha2));
    float w = (1.0 - beta) * (1.0 - alpha);
    r *= w;
    float P = max(mad(beta, mad(1.22452314, beta, -2.22452314), 1), 0.0);
    float Q = mad(alpha,
        mad(alpha, mad(56.72939571, beta, 3.5139459), mad(-27.04171425, beta, 14.18391971)),
        mad(beta, mad(3.64186555, beta, -2.15801349), 1.0));
    Q = rcp(Q);

    float a = mad(P, Q, r * w * mad(-0.90323568, w, 0.65453424));
    float b = mad(beta * alpha2,
        mad(beta,
            mad(beta,
                mad(beta,
                    mad(alpha, mad(-5.77186108, alpha, 7.85826656), -3.89135049),
                    mad(alpha, mad(18.40509904, alpha, -28.42641268), 14.17520803)),
                mad(alpha, mad(-13.04437201, alpha, 21.45972561), -11.21080953)),
            mad(alpha, mad(0.60274702, alpha, -0.1273335), -0.72206968)),
        mad(r, mad(0.39949572, w, -0.585318), 1.0));

    return lerp(a, b, F0);
}

For GLSL, swap mad to fma, lerp to mix, and rcp(x) to (1.0/x).

Make sure that the α\alpha you pass is indeed α\alpha and not linear roughness.


  1. Bruce Walter et al. "Microfacet Models for Refraction through Rough Surfaces". 2007. ↩︎ ↩︎

  2. Christophe Schlick. "An Inexpensive BRDF Model for Physically-based Rendering". 1994. ↩︎

  3. Eric Heitz. "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs". 2014. ↩︎

  4. Brian Karis. "Real Shading in Unreal Engine 4". 2013. ↩︎ ↩︎

  5. Csaba Kelemen and László Szirmay-Kalos. "A Microfacet Based Coupled Specular-Matte BRDF Model with Importance Sampling". 2001. ↩︎

  6. Emmanuel Turquin. "Practical multiple scattering compensation for microfacet models". 2019. ↩︎

  7. Antti Hirvonen et al. "Accurate Real-Time Specular Reflections with Radiance Caching". 2019. ↩︎