By "Equation (5.9)" of PBR Book, we
have the reflectance equation LV(ωV)=∫Ωf(ωV,ωi)⋅LL(ωi)⋅(cos(θi))+dω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 Lo(ωo)=∫Ωf(ωo,ωi)⋅Li(ωi)⋅(cos(θi))+dωi≈f(ωo,ωi)⊗EL(p)⊗(cos(θ))+ where the EL(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 Do(ωo)=π1(cosθo)+=π1((0,0,1)⋅ωo)+=π1max(0,z) where ωo=(x,y,z). Evidently, by "Figure 5.13" of PBR
Book, we have ∫ΩDodωo=π1∫Ω(cosθo)+dωo=π1∫Ω1dωo⊥=π1⋅π=1, and thus Do is normalized.
1-2. Integral over the Polygon
We assume that the vertices p1,p2,…,pn of the polygon Po are in the tangent space, normalized, and located in the upper hemisphere. By [Heitz 2017], the clamped
cosine integral over the polygon F(Po)=∫PoDodωo is closed-form F(Po)=2π1ij∑narccos(pi⋅pj)(normalize(pi×pj)⋅(0,0,1)). Note that the winding
order of the vertices implies the direction of the resulting vector pi×pj and thus the facing of the polygon.
Actually, the clamped cosine integral over the polygon F(Po) 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 π. This means that E(Po)=πF(Po).
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ωsin2σπcosωsin2σ+G(ω,σ,γ)−H(ω,σ,γ)G(ω,σ,γ)−H(ω,σ,γ)0ω∈[0,2π−σ]ω∈[2π−σ,2π]ω∈[2π,2π+σ]ω∈[2π+σ,π] where
ω is the elevation
angle and σ is the angular
extent. Evidently, this formulation can precomputed and stored in a 2D LUT which is indexed by cosω
and sinσ.
And by [Stephen 2016], using the linear fit, this formulation can be approximated by F=sin2σsin2σ+1sin2σ+cosω. 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(Po)=2π1ij∑narccos(pi⋅pj)normalize(pi×pj) 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∫02π∫0αcosθsinθdθdϕ=sin2(σ) where σ 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(Po) 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). For the arbitrary original
distributionDo(ωo), the corresponding LTSD (linearly
transformed spherical distribution)D(ω) is defined as D(ω)=Do(ωo)dωdωo. Evidently, we
have ωo=normalize(M−1ω). And the relationship between dωo and dω is closed-form dωdωo=∥M−1w∥3∣M−1∣. The proof of this
closed-form formula is provided in "Appendix A" of [Heitz 2016]. Note that ωo and ω are
vectors which represent the direction, while dωo and dω are solid
angles which represent the area on the sphere surface. By
"Equation (5.6)" of PBR
Book, we have dω=r2(Adωo)cosθ where the A is the
ratio, and the Adωo is the area subtended by the solid angle dω.
2-2. LTC
When the clamped cosineDo(ωo)=π1(cosθo)+ is used as the original distributionDo(ωo), the corresponding LTSD (linearly
transformed spherical distribution)D(ω) is called the LTC (linearly
transformed cosine).
2-3. Shading with Constant Polygonal Lights
When the Ll(ωl) is assumed to be constant Ll, we have Lv(ωv)=∫PBRDF(ωv,ωl)Ll(ωl)∣cosθl∣dωl=Ll∫PBRDF(ωv,ωl)∣cosθl∣dωl.
3. Approximation
3-1. Approximation GGX
By the "Equation (5.9)" of the PBR Book, we have
Lv(ωv)=∫Pf(ωv,ωl)Ll(ωl)(cosθl)+dω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 and the roughness α, 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 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, we have dωdωo=∥M−1w∥3∣M−1∣=(λ1)3λ31=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=⎣⎡10A0B0G0R⎦⎤, 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ω=∫ΩDo(ωo)dωdωodω=∫ΩDo(ωo)dωo=1. Since the clamped cosine
is normalied, the LTCs must be normalized. However, f(ωv,ωl)(cosθl)+ is NOT normalized. And thus the normn(ωv)=∫Ωf(ωv,ωl)(cosθl)+dωl should be introduced to accomplish the approximation. This means that f(ωv,ωl)(cosθl)+≈n(ωv)D(ω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)=∫Ω[F0+(F90−F0)(1.0−ωv⋅ωh)5]DV(ωl,ωv)dωl=F0⋅nR(ωv)+(F90−F0)⋅nG(ωv) where nR(ωv)=∫ΩDV(ωl,ωv)dωl and nG(ωv)=∫Ω(1.0−ωv⋅ωh)5DV(ωl,ωv)dωl. Evidently, nR(ωv) and nG(ω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 ∫PD(ω)dω=∫PoDo(ωo)dωdωodω=∫PoDo(ωo)dωo where Po=M−1P.
Evidently, Po=normalize(M−1P) is more consistent with ωo=normalize(M−1ω). However, even if the M−1P
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(Po) is calculated by [Heitz 2017].
4-2. Shading with Constant Polygonal Lights
By 2. Approximation, we have Ll∫PBRDF(ωv,ωl)∣cosθl∣dωl≈Ll∫PNormBRDFCosine⋅D(ωl)dωl=Ll⋅NormBRDFCosine⋅∫PD(ωl)dω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 Ll⋅NormBRDFCosine⋅∫PD(ωl)dωl=Ll⋅NormBRDFCosine⋅∫PoDo(ωo)dωo=Ll⋅NormBRDFCosine⋅E(Po) where Po=M−1P
and E(Po)=∫PoDo(ωo)dωo=∫Poπ1∣cosθo∣dωo.