Advanced Pathtracer with MIS
Introduction
The entire pathtracer is based on the following rendering equation that is originally from the paper Kajiya, James T. “The rendering equation.” ACM SIGGRAPH computer graphics. Vol. 20. No. 4. ACM, 1986. and implemented based on book Physically based rendering: From theory to implementation. Multiple techniques are added to enhance the rendering quality.
L r ( x , ω o ) = L e ( x , ω o ) + ∫ Ω f ( x , ω i , ω o ) L d i r ( x , ω i ) ( n ⋅ ω i ) d ω i + ∫ Ω f ( x , ω i , ω o ) L i n d ( x , ω i ) ( n ⋅ ω i ) d ω i L_r(\bm x, \bm \omega_o) = L_e(\bm x, \bm \omega_o) + \int\limits_\Omega f(\bm x, \bm \omega_i, \bm \omega_o) L_{dir}(\bm x, \bm \omega_i) (\bm n \cdot \bm \omega_i)d\bm \omega_i + \int\limits_\Omega f(\bm x, \bm \omega_i, \bm \omega_o) L_{ind}(\bm x, \bm \omega_i)(\bm n \cdot \bm \omega_i)d\bm \omega_i Lr(x,ωo)=Le(x,ωo)+Ω∫f(x,ωi,ωo)Ldir(x,ωi)(n⋅ωi)dωi+Ω∫f(x,ωi,ωo)Lind(x,ωi)(n⋅ωi)dωi
Direct/Indirect Separation (Next Event Estimation)
The direct light part can be estimated as following:
L d ( x , ω o ) = ∫ Ω f ( x , ω i , ω o ) L d i r ( x , ω i ) ( n ⋅ ω i ) d ω i ≈ L e A N ∑ k = 1 N f ( x , ω i ( k ) , ω o ) G ( x , x k ′ ) V ( x , x k ′ ) L_d(\bm x, \bm \omega_o) = \int\limits_\Omega f(\bm x, \bm \omega_i, \bm \omega_o) L_{dir}(\bm x, \bm \omega_i) (\bm n \cdot \bm \omega_i) d\bm \omega_i\approx L_e \frac{A}{N} \sum_{k=1}^{N} f(\bm x, \bm \omega_i(k), \bm \omega_o) G(\bm x, \bm x'_k) V(\bm x, \bm x'_k) Ld(x,ωo)=Ω∫f(x,ωi,ωo)Ldir(x,ωi)(n⋅ωi)dωi≈LeNAk=1∑Nf(x,ωi(k),ωo)G(x,xk′)V(x,xk′)
The indirect light part can be estimated as following:
L I = ∫ Ω f ( x , ω i , ω o ) L i n d ( x , ω i ) ( n ⋅ ω i ) d ω i ≈ 2 π N ∑ k = 1 N f ( x , ω i ( k ) , ω o ) L o ( t ( x , ω i ( k ) ) , − ω i ( k ) ) ( n ⋅ ω i ( k ) ) , L_I = \int\limits_\Omega f(\bm x, \bm \omega_i, \bm \omega_o) L_{ind}(\bm x, \bm \omega_i) (\bm n \cdot \bm \omega_i) d\bm \omega_i\approx \frac{2\pi}{N} \sum_{k=1}^{N} f(\bm x, \bm \omega_i(k), \bm \omega_o) L_o(t(\bm x, \bm \omega_i(k)), -\bm \omega_i(k)) (\bm n \cdot \bm \omega_i(k)), LI=Ω∫f(x,ωi,ωo)Lind(x,ωi)(n⋅ωi)dωi≈N2πk=1∑Nf(x,ωi(k),ωo)Lo(t(x,ωi(k)),−ωi(k))(n⋅ωi(k)),
By separating direct light and indirect light, we can estimate the next event corresponding to the light source for direct, and focus the energies on the hard part in path tracing, which is computing the indirect light or the global illumination.
Russian Roulette
Russian Roulette is a technique the pathtracer used to determine which light path will be terminated before it reaches the light source. This technique is simplified from the paper Arvo, James, and David Kirk. “Particle transport and image synthesis.” ACM SIGGRAPH Computer Graphics 24.4 (1990): 63-66.
Theory
We can select a termination probability 𝑞 to use for each intersection, then account for the lost energy of terminated paths by boosting the energy of the surviving paths. We can do this by increasing the throughputs 𝑇 of each surviving path by a factor of 1 1 − q \frac{1}{1-q} 1−q1. The result is that the expected energy for a large number of paths stays constant regardless of our choice of 𝑞 .
Implementation
We can choose an arbitrary constant termination probability, but a better idea would be to select a continuation probability ( 1−𝑞 ) at each Russian roulette event which is proportional to the path’s current throughput. This way, we terminate most low-throughput paths and retain most high-throughput paths. Thus, the termination probability is calculated as following:
q = 1 − m i n ( m a x ( T r , T g , T b ) , 1 ) q = 1 - min(max(T_r, T_g, T_b), 1) q=1−min(max(Tr,Tg,Tb),1)
Importance Sampling
A Monte Carlo estimator can be used to approximate the integral of some function f ( x ) f(x) f(x) using many samples x k x_k xk . The samples are drawn from some probability density function p d f pdf pdf, which is incorporated into the estimator as shown below. We are free to choose any p d f pdf