LTC (Linearly Transformed Cosines)

By "Equation (5.9)" of PBR Book, we have the reflectance equation L V ( ω V ) = Ω f ( ω V , ω i ) L L ( ω i ) ( cos ( θ i ) ) + d ω i \displaystyle \operatorname{L_V}(\overrightarrow{\omega_V}) = \int_\Omega \operatorname{f}(\overrightarrow{\omega_V}, \overrightarrow{\omega_i}) \cdot \operatorname{L_L}(\overrightarrow{\omega_i}) \cdot (\cos(\theta_i))^+ \, d\overrightarrow{\omega_i} .

By "Figure 14.13" of PBR Book, the MIS ("13.10.1 Multiple Importance Sampling" of PBR Book) is applied and a large number of incident directions are sampled to calculate the reflectance equation.

Evidently, the MIS is NOT efficient in real time rendering. The area light is usually approximated by the punctual light by the Delta Distribution ("14.2.1 Lights with Singularities" of PBR Book and "14.4.5 Delta Distributions in the Integrand" of PBR Book). This means that the reflectance equation is simplified to L o ( ω o ) = Ω f ( ω o , ω i ) L i ( ω i ) ( cos ( θ i ) ) + d ω i f ( ω o , ω i ) E L ( p ) ( cos ( θ ) ) + \displaystyle \operatorname{L_o}(\omega_o) = \int_\Omega \operatorname{f}(\omega_o, \omega_i) \cdot \operatorname{L_i}(\omega_i) \cdot (\cos(\theta_i))^+ \, d\omega_i \approx \operatorname{f}(\omega_o, \omega_i) \otimes \operatorname{E_L}(p) \otimes (\cos(\theta))^+ where the E L ( p ) \displaystyle \operatorname{E_L}(p) is the irradiance perpendicular to the light direction.

However, by [Lagarde 2014], the material roughness should be modified to hide the infinitesimal specular highlight of the punctual light. This means that the material and lighting can NOT be decoupled. And thus, the area light, which can reduce specular aliasing, is still important in real time rendering.

1. Clamped Cosine Integral

1-1. Clamped Cosine

We assume that the normal direction in the tangent space is (0, 0, 1), which is called the Median Vector in [Heitz 2016]. The clamped cosine is defined as D o ( ω o ) = 1 π ( cos θ o ) + = 1 π ( ( 0 , 0 , 1 ) ω o ) + = 1 π max ( 0 , z ) \displaystyle \operatorname{D_o}(\omega_o) = \frac{1}{\pi} (\cos \theta_o)^+ = \frac{1}{\pi} (\overrightarrow{(0,0,1)} \cdot \overrightarrow{\omega_o})^+ = \frac{1}{\pi} \max(0, z) where ω o = ( x , y , z ) \displaystyle \overrightarrow{\omega_o} = (x, y, z) . Evidently, by "Figure 5.13" of PBR Book, we have Ω D o d ω o = 1 π Ω ( cos θ o ) + d ω o = 1 π Ω 1 d ω o = 1 π π = 1 \displaystyle \int_\Omega \operatorname{D_o} \, d\omega_o = \frac{1}{\pi} \int_\Omega (\cos \theta_o)^+ \, d\omega_o = \frac{1}{\pi} \int_\Omega 1 \, d\omega_o^{\perp} = \frac{1}{\pi} \cdot \pi = 1 , and thus D o \displaystyle \operatorname{D_o} is normalized.

1-2. Integral over the Polygon

We assume that the vertices p 1 , p 2 , , p n \displaystyle \overrightarrow{p_1}, \overrightarrow{p_2}, \ldots, \overrightarrow{p_n} of the polygon P o \displaystyle P_o are in the tangent space, normalized, and located in the upper hemisphere. By [Heitz 2017], the clamped cosine integral over the polygon F ( P o ) = P o D o d ω o \displaystyle \operatorname{F}(P_o) = \int_{P_o} \operatorname{D_o} \, d\omega_o is closed-form F ( P o ) = 1 2 π i j n arccos ( p i p j ) ( normalize ( p i × p j ) ( 0 , 0 , 1 ) ) \displaystyle \operatorname{F}(P_o) = \frac{1}{2\pi} \sum_{i \, j}^n \arccos(\overrightarrow{p_i} \cdot \overrightarrow{p_j}) (\operatorname{normalize}(\overrightarrow{p_i} \times \overrightarrow{p_j}) \cdot \overrightarrow{(0, 0, 1)}) . Note that the winding order of the vertices implies the direction of the resulting vector p i × p j \displaystyle \overrightarrow{p_i} \times \overrightarrow{p_j} and thus the facing of the polygon.
Actually, the clamped cosine integral over the polygon F ( P o ) \displaystyle \operatorname{F}(P_o) is called the form factor. The terms irradiance and form factor may be interchangeably used. But, technically, by [Lagarde 2014], the irradiance should NOT be divided by π \displaystyle \pi . This means that E ( P o ) = π F ( P o ) \displaystyle \operatorname{E}(P_o) = \pi \operatorname{F}(P_o) .

However, the assumption, that the vertices are in the upper hemisphere, forces us to clip the polygon. This introduces divergent branches which should ideally be avoided.

Actually, by [Snyder 1996], the integral over the sphere can be calculated without clipping as F = 1 π { π cos ω sin 2 σ ω [ 0 , π 2 σ ] π cos ω sin 2 σ + G ( ω , σ , γ ) H ( ω , σ , γ ) ω [ π 2 σ , π 2 ] G ( ω , σ , γ ) H ( ω , σ , γ ) ω [ π 2 , π 2 + σ ] 0 ω [ π 2 + σ , π ] \displaystyle F = \frac{1}{\pi} {\begin{cases} {\displaystyle \pi \cos \omega \sin^2 \sigma} &{\displaystyle \omega \isin [0, \frac{\pi}{2} - \sigma]} \\{\displaystyle \pi \cos \omega \sin^2 \sigma + \operatorname{G}(\omega, \sigma, \gamma) - \operatorname{H}(\omega, \sigma, \gamma)} &{\displaystyle \omega \isin [\frac{\pi}{2} - \sigma, \frac{\pi}{2}]} \\{\operatorname{G}(\omega, \sigma, \gamma) - \operatorname{H}(\omega, \sigma, \gamma)} &{\displaystyle \omega \isin [\frac{\pi}{2}, \frac{\pi}{2} + \sigma]} \\{0} &{\omega \isin [\frac{\pi}{2} + \sigma, {\pi}]} \end{cases}} where ω \displaystyle \omega is the elevation angle and σ \displaystyle \sigma is the angular extent. Evidently, this formulation can precomputed and stored in a 2D LUT which is indexed by cos ω \displaystyle \cos \omega and sin σ \displaystyle \sin \sigma . And by [Stephen 2016], using the linear fit, this formulation can be approximated by F = sin 2 σ sin 2 σ + cos ω sin 2 σ + 1 \displaystyle F = \sin^2 \sigma \frac{\sin^2 \sigma + \cos \omega}{\sin^2 \sigma + 1} . Evidently, this approximation can be calculated in real time.
The integral over the sphere is calcualted by the genSphereTab in the WebGL Demo provided by [Stephen 2016], PolygonIrradianceFromVectorFormFactor in Unity3D, and SphereHorizonCosWrap in UE4.

By [Stephen 2016], the vector form factor over the polygon can be calculated as F ( P o ) = 1 2 π i j n arccos ( p i p j ) normalize ( p i × p j ) \displaystyle \overrightarrow{\operatorname{F}}(P_o) = \frac{1}{2\pi} \sum_{i \, j}^n \arccos(\overrightarrow{p_i} \cdot \overrightarrow{p_j}) \operatorname{normalize}(\overrightarrow{p_i} \times \overrightarrow{p_j}) even if the vertices are NOT in the upper hemisphere. The term vector form factor is analogous to the term vector irradiance of which the direction is the direction where a flat surface can receive the highest irradiance.
And the vector form factor over the sphere is the vector of which the direction is towards the center of the sphere and the length is F = 1 π 0 2 π 0 α cos θ sin θ d θ d ϕ = sin 2 ( σ ) \displaystyle F = \frac{1}{\pi} \int_0^{2\pi} \int_0^\alpha \cos \theta \sin \theta \, d \theta d \phi = \sin^2(\sigma) where σ \displaystyle \sigma is the angular extent. Thus, a proxy sphere with the same vector form factor can be introduced. This proxy sphere can be used to calculate the integral over the polygon without clipping according to the formulation by [Snyder 1996].
The clamped cosine integral over the polygon F ( P o ) \displaystyle \operatorname{F}(P_o) is calculated by the LTC_Evaluate in the WebGL Demo provided by [Stephen 2016], EvaluateBSDF_Rect in Unity3D, and RectIrradianceLambert and RectGGXApproxLTC in UE4.

2. LTC

2-1. LTSD

We assume that M is the linear transform matrix, and ω = normalize ( M ω o ) \displaystyle \omega = \operatorname{normalize}(M \omega_o) . For the arbitrary original distribution D o ( ω o ) \displaystyle \operatorname{D_o}(\omega_o) , the corresponding LTSD (linearly transformed spherical distribution) D ( ω ) \displaystyle \operatorname{D}(\omega) is defined as D ( ω ) = D o ( ω o ) d ω o d ω \displaystyle \operatorname{D}(\omega) = \operatorname{D_o}(\omega_o) \frac{d\omega_o}{d\omega} . Evidently, we have ω o = normalize ( M 1 ω ) \displaystyle \omega_o = \operatorname{normalize}(M^{-1} \omega) . And the relationship between d ω o \displaystyle d\omega_o and d ω \displaystyle d\omega is closed-form d ω o d ω = M 1 M 1 w 3 \displaystyle \frac{d\omega_o}{d\omega} = \frac{|M^{-1}|}{{\|M^{-1}w\|}^3} . The proof of this closed-form formula is provided in "Appendix A" of [Heitz 2016]. Note that ω o \displaystyle \omega_o and ω \displaystyle \omega are vectors which represent the direction, while d ω o \displaystyle d\omega_o and d ω \displaystyle d\omega are solid angles which represent the area on the sphere surface. By "Equation (5.6)" of PBR Book, we have d ω = ( A d ω o ) cos θ r 2 \displaystyle d\omega = \frac{(A d\omega_o) \cos\theta}{r^2} where the A is the ratio, and the A d ω o \displaystyle A d\omega_o is the area subtended by the solid angle d ω \displaystyle d\omega .

2-2. LTC

When the clamped cosine D o ( ω o ) = 1 π ( cos θ o ) + \displaystyle \operatorname{D_o}(\omega_o) = \frac{1}{\pi} (\cos \theta_o)^+ is used as the original distribution D o ( ω o ) \displaystyle \operatorname{D_o}(\omega_o) , the corresponding LTSD (linearly transformed spherical distribution) D ( ω ) \displaystyle \operatorname{D}(\omega) is called the LTC (linearly transformed cosine).

2-3. Shading with Constant Polygonal Lights

When the L l ( ω l ) \displaystyle \operatorname{L_l}(\omega_l) is assumed to be constant L l \displaystyle L_l , we have L v ( ω v ) = P BRDF ( ω v , ω l ) L l ( ω l ) cos θ l d ω l = L l P BRDF ( ω v , ω l ) cos θ l d ω l \displaystyle \operatorname{L_v}(\omega_v) = \int_{P} \operatorname{BRDF}(\omega_v, \omega_l) \operatorname{L_l}(\omega_l) |\cos \theta_l| \, d\omega_l = L_l \int_{P} \operatorname{BRDF}(\omega_v, \omega_l) |\cos \theta_l| \, d\omega_l .

3. Approximation

3-1. Approximation GGX

By the "Equation (5.9)" of the PBR Book, we have L v ( ω v ) = P f ( ω v , ω l ) L l ( ω l ) ( cos θ l ) + d ω l \displaystyle \operatorname{L_v}(\omega_v) = \int_{P} \operatorname{f}(\omega_v, \omega_l) \operatorname{L_l}(\omega_l) (\cos \theta_l)^+ \, d\omega_l . And we use non-linear optimization to approximate the BRDF cosine by LTC. The fitting code

3-1. LUT UV

Since the GGX BRDF is isotropic, the distribution can be determined by the outgoing direction ω v \displaystyle \omega_v and the roughness α \displaystyle \alpha , which are used as the UV of the LUTs.

3-2. Tangent Space

Note that the LUTs are precomputed by assuming that the vectors are in the tangent space where the normal direction is assumed to be the Z axis (0, 0, 1), and since the GGX BRDF is isotropic, the outgoing direction ω v \displaystyle \omega_v is assumed to be in the XOZ plane. Thus, the vectors should be transformed to this tangent space before the approximation is applied.

3-3. LUT M

Actually, when M is the scaling transformation M = λ I \displaystyle M = \lambda I , we have d ω o d ω = M 1 M 1 w 3 = 1 λ 3 ( 1 λ ) 3 = 1 \displaystyle \frac{d\omega_o}{d\omega} = \frac{|M^{-1}|}{{\|M^{-1}w\|}^3} = \frac{\frac{1}{{\lambda}^3}}{{(\frac{1}{\lambda})}^3} = 1 , and thus the LTSC is scale invariant. And since GGX BRDF is planar symmetry and isotropic, by [Heitz 2016], the M can be represented by only 4 parameters. The the inverse M 1 = [ 1 0 G 0 B 0 A 0 R ] \displaystyle M^{-1} = \begin{bmatrix} 1 & 0 & G \\ 0 & B & 0 \\ A & 0 & R \end{bmatrix} , which is used when rendering, is stored in the LUT. This LUT is called the ltc_1 in the WebGL Demo provided by [Stephen 2016].

3-4. LUT Norm

By Integration by Substitution, we can comprehend intuitively that Ω D ( ω ) d ω = Ω D o ( ω o ) d ω o d ω d ω = Ω D o ( ω o ) d ω o = 1 \displaystyle \int_{\Omega} \operatorname{D}(\omega) \, d\omega = \int_{\Omega} \operatorname{D_o}(\omega_o) \frac{d\omega_o}{d\omega} d\omega = \int_{\Omega} \operatorname{D_o}(\omega_o) d\omega_o = 1 . Since the clamped cosine is normalied, the LTCs must be normalized. However, f ( ω v , ω l ) ( cos θ l ) + \displaystyle \operatorname{f}(\overrightarrow{\omega_v}, \overrightarrow{\omega_l}) (\cos \theta_l)^+ is NOT normalized. And thus the norm n ( ω v ) = Ω f ( ω v , ω l ) ( cos θ l ) + d ω l \displaystyle \operatorname{n}(\overrightarrow{\omega_v}) = \int_{\Omega} \operatorname{f}(\overrightarrow{\omega_v}, \overrightarrow{\omega_l}) (\cos \theta_l)^+ \, d\omega_l should be introduced to accomplish the approximation. This means that f ( ω v , ω l ) ( cos θ l ) + n ( ω v ) D ( ω l ) \displaystyle \operatorname{f}(\overrightarrow{\omega_v}, \overrightarrow{\omega_l}) (\cos \theta_l)^+ \approx \operatorname{n}(\overrightarrow{\omega_v}) \operatorname{D}(\omega_l) .
Actually, according to "Equation (9.9)" of Real-Time Rendering Fourth Edition, the norm is the HDR (hemispherical directional reflectance). Analogous to the "Equation (9)" of [Karis 2013], the LTC Fresnel Approximation of [Stephen 2016] proposed that the Fresnel term is treated separately, and we have R ( ω v ) = Ω [ F 0 + ( F 90 F 0 ) ( 1.0 ω v ω h ) 5 ] DV ( ω l , ω v ) d ω l = F 0 n R ( ω v ) + ( F 90 F 0 ) n G ( ω v ) \displaystyle \operatorname{R}(\overrightarrow{\omega_v}) = \int_\Omega [F_0 + (F_{90} - F_0) {(1.0 - \overrightarrow{\omega_v} \cdot \overrightarrow{\omega_h})}^5] \operatorname{DV}(\overrightarrow{\omega_l}, \overrightarrow{\omega_v}) \, d \omega_l = F_0 \cdot \operatorname{n_R}(\overrightarrow{\omega_v}) + (F_{90} - F_0) \cdot \operatorname{n_G}(\overrightarrow{\omega_v}) where n R ( ω v ) = Ω DV ( ω l , ω v ) d ω l \displaystyle \operatorname{n_R}(\overrightarrow{\omega_v}) = \int_\Omega \operatorname{DV}(\overrightarrow{\omega_l}, \overrightarrow{\omega_v}) \, d \omega_l and n G ( ω v ) = Ω ( 1.0 ω v ω h ) 5 DV ( ω l , ω v ) d ω l \displaystyle \operatorname{n_G}(\overrightarrow{\omega_v}) = \int_\Omega {(1.0 - \overrightarrow{\omega_v} \cdot \overrightarrow{\omega_h})}^5 \operatorname{DV}(\overrightarrow{\omega_l}, \overrightarrow{\omega_v}) \, d \omega_l . Evidently, n R ( ω v ) \displaystyle \operatorname{n_R}(\overrightarrow{\omega_v}) and n G ( ω v ) \displaystyle \operatorname{n_G}(\overrightarrow{\omega_v}) can be stored in the LUT.
But we can use the same formluation as [Karis 2013], and the same LUT can be used. The LUT of [Stephen 2016] is called the ltc_2 in the WebGL Demo provided by [Heitz 2016] and LTCAmpTexture in UE4. And the LUT of [Karis 2013] is called PreIntegratedGF in UE4 and _PreIntegratedFGD_GGXDisneyDiffuse in Unity3D.

4. Light

4-1. Integration over Polygons

By Integration by Substitution, we can comprehend intuitively that P D ( ω ) d ω = P D o ( ω o ) d ω o d ω d ω = P o D o ( ω o ) d ω o \displaystyle \int_{P} \operatorname{D}(\omega) \, d\omega = \int_{P} \operatorname{D_o}(\omega_o) \frac{d\omega_o}{d\omega} d\omega = \int_{P_o} \operatorname{D_o}(\omega_o) d\omega_o where P o = M 1 P \displaystyle P_o = M^{-1} P . Evidently, P o = normalize ( M 1 P ) \displaystyle P_o = \operatorname{normalize}(M^{-1} P) is more consistent with ω o = normalize ( M 1 ω ) \displaystyle \omega_o = \operatorname{normalize}(M^{-1} \omega) . However, even if the M 1 P \displaystyle M^{-1} P is NOT normalized, the area on the sphere surface subtended by the polygon remains the same. Thus, the normalize operator is NOT necessary here. Actually, the normalize operator will eventually be applied when the irradiance E ( P o ) \displaystyle \operatorname{E}(P_o) is calculated by [Heitz 2017].

4-2. Shading with Constant Polygonal Lights

By 2. Approximation, we have L l P BRDF ( ω v , ω l ) cos θ l d ω l L l P N o r m B R D F C o s i n e D ( ω l ) d ω l = L l N o r m B R D F C o s i n e P D ( ω l ) d ω l L_l \int_{P} \operatorname{BRDF}(\omega_v, \omega_l) |\cos \theta_l| \, d\omega_l \approx L_l \int_{P} \mathrm{NormBRDFCosine} \cdot \operatorname{D}(\omega_l) \, d\omega_l = L_l \cdot \mathrm{NormBRDFCosine} \cdot \int_{P} \operatorname{D}(\omega_l) \, d\omega_l . Note that the polygon P should be transformed to the tangent space before the approximation is applied.
And by 3-1. Integration over Polygons, we have L l N o r m B R D F C o s i n e P D ( ω l ) d ω l = L l N o r m B R D F C o s i n e P o D o ( ω o ) d ω o = L l N o r m B R D F C o s i n e E ( P o ) \displaystyle L_l \cdot \mathrm{NormBRDFCosine} \cdot \int_{P} \operatorname{D}(\omega_l) \, d\omega_l = L_l \cdot \mathrm{NormBRDFCosine} \cdot \int_{P_o} \operatorname{D_o}(\omega_o) \, d\omega_o = L_l \cdot \mathrm{NormBRDFCosine} \cdot \operatorname{E}(P_o) where P o = M 1 P \displaystyle P_o = M^{-1} P and E ( P o ) = P o D o ( ω o ) d ω o = P o 1 π cos θ o d ω o \displaystyle \operatorname{E}(P_o) = \int_{P_o} \operatorname{D_o}(\omega_o) \, d\omega_o = \int_{P_o} \frac{1}{\pi}|\cos \theta_o| \, d\omega_o .

Attenuation

"windowing function" from [Lagarde 2014]

EllipsoidalDistanceAttenuation
BoxDistanceAttenuation

References

[Snyder 1996] John Snyder. "Area Light Sources for Real-Time Graphics." Technical Report 1996
[Karis 2013] Brian Karis. "Real Shading in Unreal Engine 4." SIGGRAPH 2013.
[Lagarde 2014] Sebastian Lagarde, Charles Rousiers. "Moving Frostbite to PBR." SIGGRAPH 2014.
[Heitz 2016] Eric Heitz, Jonathan Dupuy, Stephen Hill, David Neubelt. "Real-Time Polygonal-Light Shading with Linearly Transformed Cosines." SIGGRAPH 2016.
[Stephen 2016] Stephen Hill, Eric Heitz. "Real-Time Area Lighting: a Journey from Research to Production." SIGGRAPH 2016.
[Heitz 2017] Eric Heitz. "Geometric Derivation of the Irradiance of Polygonal Lights." Technical report 2017.