PRT
Spherical Harmonics (SH)
Basis Functions: A set of orthonormal functions used to represent other functions via linear combination (like Polynomial series and Fourier series.).
SH is A set of 2D basis functions B i ( ω ) = Y l m ( θ , ϕ ) B_i(\omega) = Y_l^m(\theta,\phi) B i ( ω ) = Y l m ( θ , ϕ ) defined on the sphere . (as an analogue to 1D Fourier series.)
the exact form is complicated:
Y ℓ m ( θ , φ ) = ( − 1 ) m ( 2 ℓ + 1 ) 4 π ( ℓ − ∣ m ∣ ) ! ( ℓ + ∣ m ∣ ) ! P ℓ m ( cos θ ) e i m φ P ℓ m ( x ) = ( 1 − x 2 ) ∣ m ∣ / 2 d ∣ m ∣ d x ∣ m ∣ P ℓ ( x ) P ℓ ( x ) = 1 2 ℓ ℓ ! d ℓ d x ℓ ( x 2 − 1 ) l {\displaystyle Y_{\ell }^{m}(\theta ,\ \varphi )=(-1)^{m}{\sqrt {{(2\ell +1) \over 4\pi }{(\ell -|m|)! \over (\ell +|m|)!}}}\,P_{\ell }^{m}(\cos {\theta })\,e^{im\varphi }\,\!} \\
P_{\ell }^{m}(x)=(1-x^{2})^{{|m|/2}}\ {\frac {d^{{|m|}}}{dx^{{|m|}}}}P_{\ell }(x)\, \\
P_{\ell }(x)={1 \over 2^{\ell }\ell !}{d^{\ell } \over dx^{\ell }}(x^{2}-1)^{l} Y ℓ m ( θ , φ ) = ( − 1 ) m 4 π ( 2 ℓ + 1 ) ( ℓ + ∣ m ∣ )! ( ℓ − ∣ m ∣ )! P ℓ m ( cos θ ) e im φ P ℓ m ( x ) = ( 1 − x 2 ) ∣ m ∣/2 d x ∣ m ∣ d ∣ m ∣ P ℓ ( x ) P ℓ ( x ) = 2 ℓ ℓ ! 1 d x ℓ d ℓ ( x 2 − 1 ) l
For any function f f f defined on the sphere, we can represent it with a linear combination of SHs (usually truncated):
f ( ω ) = ∑ i c i B i ( ω ) f(\omega) = \sum_ic_iB_i(\omega) f ( ω ) = i ∑ c i B i ( ω )
SH property (orthonormal) :
∫ Ω B i ( ω ) B j ( ω ) = 0 , i ≠ j ∫ Ω B i ( ω ) B j ( ω ) = 1 , i = j \int_\Omega B_i(\omega)B_j(\omega) = 0, i\ne j \\
\int_\Omega B_i(\omega)B_j(\omega) = 1, i= j \\ ∫ Ω B i ( ω ) B j ( ω ) = 0 , i = j ∫ Ω B i ( ω ) B j ( ω ) = 1 , i = j
SH property (projection) : the coefficient can be obtained with:
c i = ∫ Ω f ( ω ) B i ( ω ) d ω c_i = \int_\Omega f(\omega)B_i(\omega)d\omega c i = ∫ Ω f ( ω ) B i ( ω ) d ω
9 Parameter Approximation:
Use the first 3 orders of SH (9 parameters) is enough for approximating diffuse BRDF.
Precomputed Radiance Transfer
Basic idea:
Assume the scene is static , so only light conditions can vary.
view the rendering function as lighting and light transport (or bounce, in fact the visibility & BRDF) .
L ( o ) = ∫ Ω L ( i ) ⏟ lighting V ( i ) ρ ( i , o ) max ( 0 , n ⋅ i ) ⏟ light transport d i L(o) = \int_\Omega \underbrace{L(i)}_{\text{lighting}}\underbrace{V(i)\rho(i, o)\max(0, n \cdot i)}_{\text{light transport}}di L ( o ) = ∫ Ω lighting L ( i ) light transport V ( i ) ρ ( i , o ) max ( 0 , n ⋅ i ) d i
approximate lighting with SH.
For the diffuse case, BRDF is constant so ρ ( i , o ) = ρ \rho(i,o) = \rho ρ ( i , o ) = ρ :
L = L ( o ) = ρ ∫ Ω L ( i ) V ( i ) max ( 0 , n ⋅ i ) d i ≈ ρ ∫ Ω ∑ c j B j ( i ) V ( i ) max ( 0 , n ⋅ i ) d i = ρ ∑ c j ∫ Ω B j ( i ) V ( i ) max ( 0 , n ⋅ i ) d i ⏟ T j (pre-compute!) = ρ ∑ c j T j L = L(o) = \rho\int_\Omega {L(i)} V(i)\max(0, n \cdot i) di \\
\approx \rho\int_\Omega \sum c_jB_j(i)V(i)\max(0, n \cdot i) di \\
= \rho\sum c_j\underbrace{\int_\Omega B_j(i)V(i)\max(0, n \cdot i) di}_{T_j \text{ (pre-compute!)}} \\
=\rho\sum c_j T_j L = L ( o ) = ρ ∫ Ω L ( i ) V ( i ) max ( 0 , n ⋅ i ) d i ≈ ρ ∫ Ω ∑ c j B j ( i ) V ( i ) max ( 0 , n ⋅ i ) d i = ρ ∑ c j T j (pre-compute!) ∫ Ω B j ( i ) V ( i ) max ( 0 , n ⋅ i ) d i = ρ ∑ c j T j
We need to save a vector T j T_j T j for each point.
Another way to calculate it (with a more formal rendering function):
L o ( p , o ) = ∫ Ω L i ( p , i ) f r ( p , i , o ) cos θ i V ( p , i ) d i ≈ ∫ Ω ∑ p c p B p ( i ) ∑ q d q B q ( i ) d i = ∑ p ∑ q c q d p ∫ Ω B p ( i ) B q ( i ) d i = ∑ j c j d j L_o(p,o)=\int_\Omega L_i(p,i)f_r(p,i,o)\cos\theta_iV(p,i)di \\
\approx \int_\Omega \sum_pc_pB_p(i)\sum_qd_qB_q(i)di \\
= \sum_p\sum_qc_qd_p\int_\Omega B_p(i)B_q(i)di \\
= \sum_jc_jd_j L o ( p , o ) = ∫ Ω L i ( p , i ) f r ( p , i , o ) cos θ i V ( p , i ) d i ≈ ∫ Ω p ∑ c p B p ( i ) q ∑ d q B q ( i ) d i = p ∑ q ∑ c q d p ∫ Ω B p ( i ) B q ( i ) d i = j ∑ c j d j
For the glossy case, BRDF is not constant and is dependent on ( i , o ) (i,o) ( i , o ) .
L ( o ) = ∫ Ω L ( i ) V ( i ) ρ ( i , o ) max ( 0 , n ⋅ i ) d i ≈ ∑ j c j T j ( o ) ≈ ∑ j c j ∑ k t j , k B k ( o ) L(o) = \int_\Omega {L(i)} V(i)\rho(i,o)\max(0, n \cdot i) di \\
\approx \sum_j c_jT_j(o) \\
\approx \sum_jc_j\sum_kt_{j,k}B_k(o) L ( o ) = ∫ Ω L ( i ) V ( i ) ρ ( i , o ) max ( 0 , n ⋅ i ) d i ≈ j ∑ c j T j ( o ) ≈ j ∑ c j k ∑ t j , k B k ( o )
Now we need to save a matrix for each point.
SH property (rotation) : any rotated SH basis function, can be represented with a linear combination of basis functions of the same level.
So to rotate the lighting, we don't need to re-compute T j T_j T j , but apply the rotation on T j T_j T j .
With PRT, rendering at each point is reduced to a dot product between a vector and another vector (diffuse) or matrix (glossy), and can be easily implemented in real-time.