Classical Methods in Offline RenderingJerry Cao
Content Team
OverView
๏ฟฝ Basics in Computer Graphics
๏ฟฝ Whitted Ray Tracing
๏ฟฝ Path Tracing
๏ฟฝ Light Tracing
๏ฟฝ Instant Radiosity
๏ฟฝ Bidirectional Path Tracing
Ray Traced Images
Ray Traced Images
Ray Traced Images
Why Ray Tracing?
๏ฟฝ Two well known methods for rendering.๏ฟฝ Rasterization
๏ฟฝ Ray Tracing
๏ฟฝ Why Ray Tracing?๏ฟฝ Unbiased Methods Available
๏ฟฝ Similar to how reality works
๏ฟฝ Much higher quality
Why Ray Tracing?
๏ฟฝ Soft Shadow
๏ฟฝ Color Bleeding
๏ฟฝ Reflection & Refraction
๏ฟฝ Caustics
๏ฟฝ Depth of Field
๏ฟฝ Motion Blur
๏ฟฝ Subsurface Scattering
๏ฟฝ โฆ
How to do Ray Tracing
The very Basics
๏ฟฝ Solid Angle๏ฟฝ An object's solid angle in steradians is equal to the area of the segment of a unit
sphere, centered at the angle's vertex, that the object covers.
The very Basics
๏ฟฝ Flux๏ฟฝ Energy passing through a specific area per unit time
๏ฟฝ Irradiance๏ฟฝ Flux per unit area
๏ฟฝ Radiance๏ฟฝ Flux density per unit area, per solid angle
๏ฟฝ Bidirectional Reflection Density Function (BRDF)๏ฟฝ Gives a formalism for describing the reflection from a surface
๏ฟฝ ๐๐ ๐, ๐ค๐, ๐ค๐ =๐๐ฟ๐ ๐,๐ค๐๐๐ธ ๐,๐ค๐
Rendering Equation
๏ฟฝ Or Light Transport Equation (LTE)
๏ฟฝ๐ฟ๐ ๐,๐ค๐ = ๐ฟ๐ ๐,๐ค๐ + โซ ๐ฟ๐ ๐, ๐ค๐ ๐ ๐,๐ค๐, ๐ค๐ cos๐๐๐๐ค๐
Monte Carlo Integration
๏ฟฝ To Evaluate an Integral๏ฟฝ ๐ผ = โซฮฉ๐(๐ฅ)dx
๏ฟฝ We can use the following estimation
๏ฟฝ ๐น๐ =1๐ฮฃ๐=1๐
๐ ๐ฅ๐๐ ๐ฅ๐
๏ฟฝ Proof
๏ฟฝ
๐ธ ๐น๐ = ๐ธ1๐ฮฃ๐=1๐
๐ ๐ฅ๐๐ ๐ฅ๐
= 1๐ฮฃ๐=1๐ โซฮฉ
๐ ๐ฅ๐๐ ๐ฅ๐
๐ ๐ฅ๐ ๐ ๐ฅ
= โซฮฉ ๐ ๐ฅ ๐๐ฅ= ๐ผ
Why Monte Carlo
๏ฟฝ Estimation goes the same way regardless of how many dimensions there are.
๏ฟฝ Only need to be able to evaluate the function at arbitrary point.
๏ฟฝ Cons:
๏ฟฝ Low Convergence Rate: 1โ๐
Importance Sampling
๏ฟฝ Sample where it matters most
๏ฟฝ An example:
๏ฟฝ ๐ ๐ฅ = { 0.01 ๐ฅ โ 0, 0.011.01 ๐ฅ โ [0.01, 1)
๏ฟฝ Perfect pdf:
๏ฟฝ p ๐ฅ = { 0.01 ๐ฅ โ 0, 0.011.01 ๐ฅ โ [0.01, 1)
๏ฟฝ A terrible pdf:
๏ฟฝ p ๐ฅ = { 99.01 ๐ฅ โ 0, 0.010.01 ๐ฅ โ [0.01, 1)
Multiple Importance Sampling
๏ฟฝ๐น๐๐๐ = ฮฃ๐=1๐1๐๐ฮฃ๐=1๐๐ ๐ค๐ ๐๐,๐
๐ ๐๐,๐๐๐ ๐๐,๐
๏ฟฝ๐๐ should satisfy the following condition
๏ฟฝฮฃ๐=1๐ ๐ค๐ ๐ฅ = 1 ๐๐ ๐ ๐ฅ โ 0๏ฟฝ๐ค๐ ๐ฅ = 0 ๐๐ ๐๐ ๐ฅ = 0
Multiple Importance Sampling
๏ฟฝ Common weight factors:๏ฟฝ Balance Heuristic
๏ฟฝ๐ค๐ ๐ฅ =๐๐๐๐ ๐ฅฮฃ๐๐๐๐๐ ๐ฅ
๏ฟฝ Power Heuristic
๏ฟฝ๐ค๐ ๐ฅ =๐๐๐๐
๐
ฮฃ๐๐๐๐๐๐
Multiple Importance Sampling
๏ฟฝ MIS in direct light sampling
Multiple Importance Sampling
๏ฟฝ MIS in Bidirectional Path Tracing
How to Sample a pdf
๏ฟฝ Rejection Method๏ฟฝ Inefficient
๏ฟฝ Inversion method
๏ฟฝ Compute the CDF ๐ ๐ฅ = โซ0๐ฅ ๐ ๐ก ๐๐ก
๏ฟฝ Compute the inverse of CDF ๐โ1 ๐ฅ
๏ฟฝ Obtain a uniformly distributed random number, ยต
๏ฟฝ Compute ๐ = ๐โ1(๐)
Whitted Ray Tracing
๏ฟฝ Only dirac delta BRDF and light sources are considered.๏ฟฝ Pure Reflective & Refractive
๏ฟฝ Point light & directional light
My GPU Solution
๏ฟฝ CUDA accelerated
๏ฟฝ Some data:๏ฟฝ 87w+ triangles in the dragon
๏ฟฝ 640 x 480 resolution
๏ฟฝ 7-8 fps on a GTX 260
Light Transport Equation
๏ฟฝ๐ฟ๐ ๐, ๐ค๐ = ๐ฟ๐ ๐, ๐ค๐ + โซ ๐ฟ๐ ๐, ๐ค๐ ๐ ๐, ๐ค๐, ๐ค๐ cos๐๐๐๐ค๐
Relation between dA and dw
๏ฟฝ๐๐ค = ๐๐๐ ๐๐2๐๐ด
๏ฟฝ๐๐ด =๐๐๐ ๐๐2๐๐ค
Deeper dive into LTE
โข๐ฟ ๐0,๐ค๐ = ๐ฟ๐ ๐0, ๐ค๐ + โซ ๐ฟ ๐0, ๐ค ๐ ๐0,๐ค, ๐ค๐ cos๐0โ1๐๐ค
= ๐ฟ๐ ๐1 โ ๐0 + โซ ๐ฟ ๐2 โ ๐1 ๐ ๐2 โ ๐1 โ ๐0๐(๐1โ๐2)๐๐๐ ๐1โ2๐๐๐ ๐2โ1
๐2๐๐ด2
= ๐ฟ๐ ๐1 โ ๐0 + โซ ๐ฟ ๐2 โ ๐1 ๐ ๐2 โ ๐1 โ ๐0 ๐บ ๐1 โ ๐2 ๐๐ด2
โข ๐บ ๐1 โ ๐2 =๐(๐1โ๐2)๐๐๐ ๐1โ2๐๐๐ ๐2โ1๐2
Deeper dive into LTE
๏ฟฝ ๐ฟ ๐1 โ ๐0 = ๐ฟ๐ ๐1 โ ๐0 + โซ ๐ฟ ๐2 โ ๐1 ๐ ๐2 โ ๐1 โ ๐0 ๐บ ๐1 โ ๐2 ๐๐ด2
๏ฟฝ In the same way we can expend the red one:
๏ฟฝ ๐ฟ ๐2 โ ๐1 = ๐ฟ๐ ๐2 โ ๐1 + โซ ๐ฟ ๐3 โ ๐2 ๐ ๐3 โ ๐2 โ ๐1 ๐บ ๐2 โ ๐3 ๐๐ด3
๏ฟฝ Dropping the brown part, we have the following equation for direct illumination:
๏ฟฝ ๐ฟ ๐1 โ ๐0 = ๐ฟ๐ ๐1 โ ๐0 + โซ ๐ฟ๐ ๐2 โ ๐1 ๐ ๐2 โ ๐1 โ ๐0 ๐บ ๐1 โ ๐2 ๐๐ด2
Direct(Local) Illumination vs Global Illumination
Deeper dive into LTE
๏ฟฝ
๐ฟ ๐0,๐ค๐ = ๐ฟ๐ ๐1 โ ๐0+ โซ ๐ฟ๐ ๐2 โ ๐1 ๐ ๐2 โ ๐1 โ ๐0 ๐บ ๐1 โ ๐2 ๐๐ด2+ ๐ฟ๐ ๐3 โ ๐2 ๐ ๐3 โ ๐2 โ ๐1 ๐บ ๐2 โ ๐3 ๐ ๐2 โ ๐1 โ ๐0 ๐บ ๐1 โ ๐2 ๐๐ด3๐๐ด2
โฆ+โซโฆโซ๐ฟ๐ ๐๐ โ ๐๐โ1 ๐=2๐=๐ ๐ ๐๐ โ ๐๐โ1 โ ๐๐โ2 ๐บ ๐๐ โ ๐๐โ1 ๐๐ด๐ โฆ๐๐ด2
๏ฟฝ We define the following term:
๏ฟฝ ๐๐(๐1 โ ๐0)=โซโฆโซ๐ฟ๐ ๐๐ โ ๐๐โ1 ๐=2๐=๐ ๐ ๐๐ โ ๐๐โ1 โ ๐๐โ2 ๐บ ๐๐ โ ๐๐โ1 ๐๐ด๐ โฆ๐๐ด2
Deeper dive into LTE
๏ฟฝ ๐ฟ ๐1 โ ๐0 = ๐=1๐=โ๐๐(๐1 โ ๐0)
๏ฟฝ It turns out to be a very simple equation, what it says is relatively straightforward, radiance from P1 to P0 is the combination of:๏ฟฝ Radiance comes from light directly
๏ฟฝ Direct Illumination
๏ฟฝ Light contribution from multiple bounces
Russian Roulette
๏ฟฝ For each Ti after several bounces, we start Russian roulette:
๏ฟฝ ๐๐โฒ = {๐๐๐๐ฅ โ 0, ๐
0 ๐ฅ โ [๐, 1)
๏ฟฝ The average of ๐๐โฒ is exactly the same with ๐๐, which makes the above estimation unbiased.
๏ฟฝ One step further:
๏ฟฝ ๐ฟ ๐1 โ ๐0 = T1 + T2 + T3 + T4 +1๐(๐5 +
1๐(๐6 + โฏ))
Evaluate the integral of LTE
๏ฟฝ Weโll focus on path with specific number of vertices.๏ฟฝ ๐๐(๐1 โ ๐0)=โซโฆโซ๐ฟ๐ ๐๐ โ ๐๐โ1 ๐=2๐=๐ ๐ ๐๐ โ ๐๐โ1 โ ๐๐โ2 ๐บ ๐๐ โ ๐๐โ1 ๐๐ด๐ โฆ๐๐ด2
๏ฟฝ With Monte Carlo method, we only need to evaluate the following equation:
๏ฟฝ ๐๐ ๐1 โ ๐0 =1๐ ๐=1๐
๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐=2๐=๐ ๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐บ ๐๐,๐โ๐๐,๐โ1
๐๐ด ๐๐,0 ๐๐ด ๐๐,1 ๐๐ด ๐๐,2 โฆ๐๐ด(๐๐,๐)
๏ฟฝ The PDFs are different in different methods.
Path Tracing
๏ฟฝ Tracing rays from camera
๏ฟฝ Whitted ray tracing stops if brdf is not a delta one, while path tracing doesnโt
PDF of sampling a path of n+1 vertices
๏ฟฝ Weโll assume ๐ ๐0 and ๐ ๐1 are both 1 for simplicity. That said depth of field is not taken into account so far.
๏ฟฝ Since we generate new vertex by sampling a new ray from current bxdf, we only have the PDF w.r.t solid instead of area.๏ฟฝ Sampling pdf w.r.t area is too much inefficient !
๏ฟฝ ๐๐ด ๐๐ =๐๐๐ ๐๐โ๐โ1
๐2๐๐ค ๐๐โ1 โ ๐๐ =
๐บ ๐๐โ๐๐โ1 ๐๐ค ๐๐โ1โ๐๐๐๐๐ ๐๐โ1โ๐
๏ฟฝ Dropping this term in, we have the following equation:
๏ฟฝ๐๐ ๐1 โ ๐0 =
1๐ ๐=1๐
๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐=2๐=๐ ๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐บ ๐๐,๐โ๐๐,๐โ1
๐๐ด ๐๐,0 ๐๐ด ๐๐,1 ๐๐ด ๐๐,2 โฆ๐๐ด ๐๐,๐
= 1๐ ๐=1๐ ๐ฟ๐ ๐๐,๐ โ ๐๐,๐โ1 ๐=2๐=๐
๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐๐๐ ๐๐,๐โ1โ๐๐๐ค(๐๐,๐โ1โ๐๐,๐)
Tricks
๏ฟฝ ๐๐ ๐1 โ ๐0 can reuse the existing path of ๐๐โ1 ๐1 โ ๐0 , then only one vertex is needed to be sampled to evaluate each T.
๏ฟฝ๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐๐๐ ๐๐,๐โ1โ๐
๐๐ค(๐๐,๐โ1โ๐๐,๐)can be computed incrementally.
๏ฟฝ Use Multiple Importance Sampling to sample both of light source and bsdf, instead of trying to hit light source by chance, or:๏ฟฝ It wonโt work for delta lights.
๏ฟฝ Terrible convergence rate if light source is small
Path Tracing Conclusion
๏ฟฝ Unbiased, easy to implement, Robust๏ฟฝ Convergence rate may be low for certain
scenes, No Caustics
Instant Radiosity
๏ฟฝ Distribute virtual point light in the first stage.
๏ฟฝ Use those virtual point light to evaluate the radiance
PDF of a path in Instant Radiosity
๏ฟฝ Again, we assume ๐ ๐0 and ๐ ๐1 are both 1.
๏ฟฝ ๐๐ด ๐๐ =๐๐๐ ๐๐โ1โ๐
๐2๐๐ค ๐๐ โ ๐๐โ1 =
๐บ ๐๐โ๐๐โ1 ๐๐ค ๐๐โ๐๐โ1๐๐๐ ๐๐โ๐โ1
๏ฟฝ The above equation only works for vertices from 2 to n-1, we already have the pdf w.r.t area of sampling vertex on light sources, since thatโs exactly what we do.
๏ฟฝ Again, dropping it in, we have:
๏ฟฝ
๐๐ ๐1 โ ๐0 =1๐ ๐=1๐
๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐=2๐=๐ ๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐บ ๐๐,๐โ๐๐,๐โ1
๐๐ด ๐๐,0 ๐๐ด ๐๐,1 ๐๐ด ๐๐,2 โฆ๐๐ด(๐๐,๐)
= 1๐ ๐=1๐ (
๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐๐๐ ๐๐,๐โ๐โ1๐๐ค ๐๐,๐โ๐๐,๐โ1 ๐๐ด(๐๐,๐)
๐=4๐=๐๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐๐๐ ๐๐,๐โ1โ๐โ2
๐๐ค(๐๐,๐โ1โ๐๐,๐โ2)
๐ ๐๐,2 โ ๐๐,1 โ ๐๐,0 ๐บ ๐๐,2 โ ๐๐,3 ๐ ๐๐,3 โ ๐๐,2 โ ๐๐,1 )
LTE Evaluation
๏ฟฝ
๐๐ ๐1 โ ๐0 =1๐ ๐=1๐
๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐=2๐=๐ ๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐บ ๐๐,๐โ๐๐,๐โ1
๐๐ด ๐๐,0 ๐๐ด ๐๐,1 ๐๐ด ๐๐,2 โฆ๐๐ด(๐๐,๐)
= 1๐ ๐=1๐ (
๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐๐๐ ๐๐,๐โ๐โ1๐๐ค ๐๐,๐โ๐๐,๐โ1 ๐๐ด(๐๐,๐)
๐=4๐=๐๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐๐๐ ๐๐,๐โ1โ๐โ2
๐๐ค(๐๐,๐โ1โ๐๐,๐โ2)
๐ ๐๐,2 โ ๐๐,1 โ ๐๐,0 ๐บ ๐๐,2 โ ๐๐,3 ๐ ๐๐,3 โ ๐๐,2 โ ๐๐,1 )
๏ฟฝ The green part will be evaluated incrementally in the VPL distribution stage.
๏ฟฝ The red part is done during per pixel radiance evaluation.
Quite different way of converging
Special Case Handling
๏ฟฝ See the hotspot at corners, it is caused by the inverse distance in G term.
๏ฟฝ Clamp the inverse distance to avoid it.๏ฟฝ ๐บ = min ๐บ, ๐บ๐๐๐๐๐ + max(๐บ โ ๐บ๐๐๐๐๐, 0)
๏ฟฝ Evaluate the red part by using other methods, like path tracing.
Instant Radiosity Conclusion
๏ฟฝ Unbiased, easy to implement
๏ฟฝ Relatively slow convergence rate, almost no specular surface reflection
๏ฟฝ Not very practical unless with much enhancement
Light Tracing
๏ฟฝ Trace rays from light source
๏ฟฝ Inefficient most of the time
The reverse of Path Tracing
๏ฟฝ W is importance function.
๏ฟฝ๐๐ ๐,๐ค๐ = ๐๐ ๐,๐ค๐ + โซ๐๐ ๐,๐ค๐ ๐ ๐,๐ค๐, ๐ค๐ cos๐๐๐๐ค๐
More than a Pixel
๏ฟฝ What is stored in a pixel, radiance?
๏ฟฝ๐ผ๐ = โซ๐ด0 โซ๐๐ ๐0, ๐ ๐ฟ๐ ๐1,โ๐ ๐๐๐ ๐ ๐๐0๐๐
= โซโซ๐๐ ๐0 โ ๐1 ๐ฟ๐ ๐1 โ ๐0 ๐บ ๐0 โ ๐1 ๐๐0๐๐1
๏ฟฝ Drop LTE in it, we have the equation for the radiance contribution of a specific length:
๏ฟฝ ๐ผ๐ = โซโฆโซ๐๐ ๐0 โ ๐1 ๐บ ๐0 โ ๐1 ๐ฟ๐ ๐๐ โ ๐๐โ1 ๐=2๐=๐ ๐บ ๐๐,๐ โ ๐๐,๐โ1* ๐ ๐๐,๐ โ ๐๐,๐โ1 โ ๐๐,๐โ2 ๐๐0๐๐1 โฆ๐๐๐
PDF of sampling a path of n+1 vertices
๏ฟฝ ๐๐ด ๐๐ =๐๐๐ ๐๐โ๐+1
๐2๐๐ค ๐๐+1 โ ๐๐ =
๐บ ๐๐โ๐๐+1 ๐๐ค ๐๐+1โ๐๐๐๐๐ ๐๐+1โ๐
๏ฟฝ
๐๐ ๐1 โ ๐0 =1๐ ๐=1๐
๐๐ ๐๐,0โ๐๐,1 ๐บ ๐๐,0โ๐๐,1 ๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐=2๐=๐ ๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐บ ๐๐,๐โ๐๐,๐โ1
๐๐ด ๐๐,0 ๐๐ด ๐๐,1 ๐๐ด ๐๐,2 โฆ๐๐ด ๐๐,๐
= 1๐ ๐=1๐
๐ฟ๐ ๐๐,๐โ๐๐,๐โ1 ๐๐๐ ๐๐,๐โ๐โ1๐๐ด ๐๐,๐ ๐๐ค ๐๐,๐โ๐๐,๐โ1 ๐๐ด(๐๐,0)
๐บ ๐๐,0 โ ๐๐,1 ๐๐ ๐๐,0 โ ๐๐,1
๐(๐๐,0 โ ๐๐,1 โ ๐๐,2) ๐=3๐=๐๐ ๐๐,๐โ๐๐,๐โ1โ๐๐,๐โ2 ๐๐๐ ๐๐,๐โ1โ๐โ2
๐๐ค(๐๐,๐โ1โ๐๐,๐โ2)
Light Tracing vs Path Tracing
Light Tracing Conclusion
๏ฟฝ Easy to implement, good caustics
๏ฟฝ Low convergence rate, especially for larger scene. Almost no specular surfaces.
Light Tracing Conclusion
๏ฟฝ Good at rendering caustics for small scene
๏ฟฝ Terrible convergence rate for outdoor scene
๏ฟฝ Specular or highly glossy surfaces need special treatment
Bidirectional Path Tracing
๏ฟฝ Shooting rays from both sides.
Different Cases in BDPT
All Cases in BDPT
๏ฟฝ Path Tracing Case, no vertex sampled on light source.
๏ฟฝ Light Tracing Case, only one vertex sampled on aperture.
๏ฟฝ Direct Illumination Case, only one vertex sampled on light source
๏ฟฝ Common Case, sub-path from each side contains at least two vertices
A Naรฏve BDPT Implementation
๏ฟฝ Works terrible, delivers no value at all.๏ฟฝ Almost wrong value for specular
surface
๏ฟฝ Caustics are a little bit dimmer
๏ฟฝ A lot of fireflies around corners
With MIS in BDPT
๏ฟฝ Same amount of time
๏ฟฝ Much better result
๏ฟฝ Quite Robust
๏ฟฝ Shows everything!!
Resources for further detail
๏ฟฝ Reference Implementation:๏ฟฝ https://github.com/JerryCao1985/SORT
๏ฟฝ My Tech Blog:๏ฟฝ https://agraphicsguy.wordpress.com/
Q&A