Realistic Image Synthesis - Path Tracing...Solution: Monte Carlo integration β’ In general, with a...
Transcript of Realistic Image Synthesis - Path Tracing...Solution: Monte Carlo integration β’ In general, with a...
Realistic Image Synthesis
- Path Tracing -
Pascal Grittmann
Philipp SlusallekKarol Myszkowski
Gurprit Singh
What are we computing? β The physical phenomenon
Β© Giuseppe Milo (CC-BY)
What are we computing? β The mathematical formulationGiven:A point visible to the camera
Compute:Incident light from all directions, reflected to the camera
What are we computing? β The mathematical formulationGiven:A point visible to the cameraprevious point
Compute:Incident light from all directions, reflected to the camera previous point
Recursive problem!
Reminder: Rendering Equation
πΏπΏππ π₯π₯,ππππ = πΏπΏππ π₯π₯,ππππ + οΏ½Ξ©ππ π₯π₯,ππππ,ππππ πΏπΏππ π₯π₯,ππππ cos ππππ ππππππ
Outgoing radiance from π₯π₯ in direction ππππ
Emitted radiance from π₯π₯ in direction ππππ
Bidirectional scattering distribution function β BSDF (how much light is reflected
from ππππ towards ππππ? )
Incident radiance at π₯π₯from direction ππππ
The mysterious cosine term
Integral over sphere of all directions
Why the cosine term?
β’ Definition of radiance: β’ βflux per unit solid angle per unit
projected areaβ
β’ We are interested in:β’ βflux per unit solid angle per unit
projected areaβ
cos ππππ
ππππππππ
ππππ
ππ
π₯π₯
βππππ
π₯π₯
βππππ
Challenges
β’ Recursive high dimensional β’ Discontinuities (object and shadow boundaries)
Solution: Monte Carlo integration
β’ In general, with a single sample (primary estimator)
οΏ½Ξ©ππ π₯π₯ πππ₯π₯ β
ππ π₯π₯ππ π₯π₯
β’ Applied to rendering:
πΏπΏππ π₯π₯1,ππππ β πΏπΏππ π₯π₯1,ππππ +ππ π₯π₯1,ππππ,ππππ cos ππππ
ππ πππππΏπΏππ π₯π₯2,βππππ
Estimated recursively! High (infinite) dimensionality
π₯π₯1
π₯π₯2
How to sample ππππ?
β’ Ideally proportionally to the full integrandβ’ ππ ππππ β ππ π₯π₯,ππππ,ππππ πΏπΏππ π₯π₯,ππππ cos ππππ
β’ Usually not possible Limit to one or more factorsβ’ Simplest method: cosine
β’ ππ ππππ β cos ππππβ’ Often also possible (approximately, at least): BSDF times cosine
β’ ππ ππππ β ππ π₯π₯,ππππ,ππππ cos ππππ
When to terminate?
β’ In reality, all surfaces reflect lightβ’ We cannot track infinitely long paths, need to terminate recursion at
some pointβ’ Options:
β’ Maximum path length (biased)β’ Russian roulette (unbiased, later)
Russian Roulette and Splitting
Russian roulette
β’ Randomly terminate the path with some probability ππβ’ Unbiasedβ’ Increases variance (i.e., noise in the image)
β’ Given an estimator πΉπΉ, replace by πΉπΉπ π π π :
with probability ππ
with probability (1 β ππ)πΉπΉπ π π π = οΏ½
1πππΉπΉ
0
What criterion to use?
β’ Fixed probabilityβ’ Current path throughputβ’ Efficiency-optimized RR (Veach 97):
β’ Based on statistics of surrounding pixels
β’ βAdjoint driven Russian roulette and splittingβ Vorba et al 201β’ Based on statistics from a pre-pass, combined with splitting
Russian roulette experimentsinput scene path depth < 11 path depth < 101
RR with p=0.3 efficiency optimized p = throughput / 0.01
32.6min
53.2min
28.8min
10.6min
Thiago Ize (University of Utah, currently Solid Angle)http://www.cs.utah.edu/~thiago/cs7650/hw12/
Splitting
β’ Use more samples for the next recursion than the current oneβ’ Often done at the first point (the one visible to the camera)β’ Trade off: anti-aliasing vs variance
No splitting Splitting
Example: Direct illumination
Sampling projected solid angle4 eye rays per pixel100 shadow rays
Sampling light source area4 eye rays per pixel100 shadow rays
Example: Splitting for direct illumination
Stratified random sample locations4 eye rays per pixel
16 shadow ray
Stratified random sample locations64 eye rays per pixel
1 shadow ray
Importance Sampling the BSDF
Simplest method: cosine hemisphere samplingβ’ PDF proportional to the cosine:
β’ ππ ππππ = cos ππππππ
β’ Ideal for diffuse surfaces
β’ Given two uniform samples π’π’1,π’π’2:β’ ππππ = 2πππ’π’1β’ ππππ = cosβ1 π’π’2β’ (Derivation in Assignment 3)
Β© William Sherif
Example: Phong BRDF
β’ Simple glossy BRDFβ’ Multiplies by a cosine lobe around the perfect reflection
ππ π₯π₯,ππππ,ππππ =ππ + 22ππ
cosππ πΌπΌππ
β’ πΌπΌππ is the angle formed by ππππ and ππππβ’ ππππ is the prefect reflection of ππππ πΌπΌππ
ΞΈβππππ
ππππ
ππππππ
Sampling the cosine lobe
β’ Step 1: sample the cosine lobe about π§π§ axis β’ ππ ππβ² = cosππ ππβ² ππ+1
2ππ
β’ Step 2: compute ππππβ’ Reflect ππππ about ππ
β’ Step 3: transform ππβ² to coordinate system where ππππ is the π§π§ axisβ’ Matrix multiplication
πΌπΌππΞΈ
βππππππππ
ππππππ
π§π§
ππβ²
Next Event Estimation
Reduce variance by connecting to points on the light source
Sampling ππππ from the hemisphere
Sampling ππππ as a direction to a point on the light
But it is a point, not a directionβ¦
β’ We sample a direction ππππ by sampling a point π¦π¦ on the lightβ’ With some pdf ππ π¦π¦ defined on the surface area of the lightβ’ But our integral is over the (hemi-) sphereβ’ We need to perform a change of variables
From surface area to hemisphere
β’ Projected unit surface area at the light sourceβ’ cos πππ¦π¦
β’ Compute surface area on unit hemisphereβ’ Similar triangles 1
ππ
β’ 2D 1ππ2
β’ We must also account for the visibility!β’ ππ π₯π₯,π¦π¦
β’ Result: cos πππ¦π¦ππ2
ππ π₯π₯,π¦π¦
π¦π¦
π₯π₯
ππ
ππππππ
How to select the light source
β’ Total powerβ’ Uniformly β’ Estimated unoccluded contributionβ’ Estimated occluded contribution (prepass)β’ Clustering to support many lights
What if a BSDF sample hits the light
β’ Cannot count both: would yield twice the actual value!β’ Could average both and divide by two high varianceβ’ Or: use MIS
Multiple Importance Sampling (MIS)Veach & Guibas 1995
Combining multiple sampling techniques
β’ Sampling the BSDF
β’ Sampling the light surfacep(y)= cosΞΈy/rxy
2
x
y
p(Ο)= cosΞΈx/Ο
x
y
ΞΈx
Both techniques perform well for different effects
Light surface BSDF MIS
Light surface BSDF MIS
How to combine them?
β’ Form an affine combination of the estimators:
οΏ½π‘π‘βππ
οΏ½ππ
πππ‘π‘
π€π€π‘π‘ π₯π₯π‘π‘,ππππ π₯π₯π‘π‘,ππ
πππ‘π‘ πππ‘π‘ π₯π₯π‘π‘,ππ
β’ Theoretically, any weighting functions π€π€π‘π‘ π₯π₯ work, provided:β’ π€π€π‘π‘ π₯π₯ = 0 if πππ‘π‘ π₯π₯ = 0β’ βπ‘π‘ π€π€π‘π‘ π₯π₯ = 1 βπ₯π₯
First, all densities need to be in the same measureβ’ ππ ππ = cos ππ
ππhas unit π π ππβ1 (density on the hemisphere)
β’ ππ π¦π¦ has unit ππβ2 (density on surface area)
β’ Applying the same logic as before, we can transform them:
β’ ππ π¦π¦|ππ = cos ππππ
cos πππ¦π¦ππ2
Balance heuristic
β’ Provably good choice: minimizes upper bound of the variance
π€π€π‘π‘ π₯π₯ =πππ‘π‘πππ‘π‘ π₯π₯
βππ ππππππππ π₯π₯
Power, maximum, and cuttoff heuristics
β’ Can sometimes perform better for low-variance techniquesβ’ Amplify the weights to remove residual noise from βbadβ techniques
β’ Maximum: only consider technique with largest πππ‘π‘πππ‘π‘ π₯π₯β’ Cutoff: Balance, but set πππ‘π‘πππ‘π‘ π₯π₯ to zero if below some threshold
β’ Power heuristic: π€π€π‘π‘ π₯π₯ = πππ‘π‘πππ‘π‘ π₯π₯2
βππ ππππππππ π₯π₯ 2
Comparison β Image of a light source on surfaces with different roughness
more diffusemore specular
Optimal weights
β’ It is possible to derive the optimal set of functions π€π€π‘π‘ π₯π₯β’ Result: linear system involving many integralsβ’ Kondapaneni et al 2019β’ (Our recent SIGGRAPH paper)
Putting it all together
A less basic path tracer
β’ Given a point visible to the cameraβ’ (1) Compute direct illumination
β’ Select light source and point on the lightβ’ Trace a shadow ray for ππ π₯π₯,π¦π¦β’ Sample BSDF and check if a light was intersectedβ’ Compute MIS weights and add estimate
A less basic path tracer
β’ Given a point visible to the cameraβ’ (1) Compute direct illumination
β’ Select light source and point on the lightβ’ Trace a shadow ray for ππ π₯π₯,π¦π¦β’ Sample BSDF and check if a light was intersectedβ’ Compute MIS weights and add estimate
β’ (2) Terminate with Russian roulette
A less basic path tracer
β’ Given a point visible to the cameraβ’ (1) Compute direct illumination
β’ Select light source and point on the lightβ’ Trace a shadow ray for ππ π₯π₯,π¦π¦β’ Sample BSDF and check if a light was intersectedβ’ Compute MIS weights and add estimate
β’ (2) Terminate with Russian rouletteβ’ (3) Continue the path
β’ Could sample a new direction from the BSDF, or re-use the one from (1)
β’ Go back to (1), repeat until RR terminates
Many improvements possible
β’ Splitting (e.g., at first intersection)β’ Combine multiple light sampling strategies (via MIS)β’ Store statistics to approximate πΏπΏππ for importance sampling (βguidingβ,
later)β’ And so onβ¦