Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Assignment 2Path Tracing and Light Probes
2
Objectives
• Experiment with stochastic path tracing and image-based lighting
• Implement:– Image-based lighting– Path tracing– Importance sampling
3
Image-based Lighting
• The images in assignment 1 were dull
• Only black background• Dark reflections
4
Image-based Lighting
• Exercise 1: Add a light probe
• Realistic background• Nice reflections
5
Light Probes
• Take photo of reflective sphere:
6
Light Probes
• Remap into convenient format• We use probes in angular map format:
7
OpenEXR
• The probes are stored as OpenEXR (.exr) files• High-dynamic range (HDR) format by ILM
– First used in Harry Potter and the Sorcerers Stone, Men in Black II, Signs, Matrix, …
– 16 bit floating point / channel– Pixel values: ~0.000015 - 65000.00
• Low-dynamic range formats (PNG, JPG, etc):– Usually 8 bits/channel: 0-255
8
OpenEXR
• Benefits of HDR– Change exposure without loss of detail– Full range of the human vision– Open format used in the industry
• However– Need tone-mapping (HDR to LDR)– Not yet widely supported, but becoming more
popular (e.g. Photoshop CS)
9
Usage
• Download probes from homepage• Class LightProbe handles the probes
• Get background color from the probe
LightProbe probe(”data/uffizi_probe.exr”);
Scene.setBackground(&probe);
out = mScene->getBackground(direction);
Ray’s direction vector
10
However
• Exercise 1 is not really image-based lighting
• Probe is only used as environment map
• Point lights for lighting
11
More Realism
• We need a Global Illumination (GI) algorithm
• Simple, but slow:Path Tracing
12
Path Tracing
• Send many rays into the scene– Use stratified random sampling– Output is average of samples
• At every intersection, trace random direction– Call sampleUniform(is)
13
Path Tracing
14
Path Tracing
15
Path Tracing
16
Russian Roulette
• Stopping criteria:– Kill ray with certain (absorption) probability: α
– Otherwise, divide output by: (1 - α)
• Use random number in range [0,1] to decide
17
Russian Roulette
• Example– Absorption probability 10% (α = 0.1)– Constant background = 1 (white)– Send N = 1000 rays
• Result– About 100 rays are terminated (set to 0)– About 900 survive and hit background (set to 1)
€
out =1N100 ⋅ 0 + 900 ⋅ 1
(1−α)⎛
⎝ ⎜
⎞
⎠ ⎟ =1
18
Exercise 2
• Implement the following in PathTracer:– Stratified random sampling– Russian roulette– Random sampling over hemisphere
• Debugging– Use few samples (10-100)– Low resolution (128x128 or 256x256)
19
Random Sampling
• Compute a random direction in the hemisphere around the normal (sampleUniform)
20
Random Sampling
• Suggested solution: Rejection sampling• Other possibilities: Spherical coordinates
(see lecture notes)
• Pick random points in the cube from -1 to 1
21
Random Sampling
• Suggested solution: Rejection sampling• Other possibilities: Spherical coordinates
(see lecture notes)
• Pick random points in the cube from -1 to 1
• Discard outsidethe unit sphere
22
Random Sampling
• Normalize to get samples on the sphere
23
Random Sampling
• Keep only points in the hemisphere around the normal:
24
Exercise 2 Result
Resolution 256x256100 samples/pixel ~40 seconds
25
Exercise 3
• Add specular reflections and refractions
• WhittedTracer traced all 3 rays• With PathTracing we only trace 1 ray,
but which one?
out = (1-t)*((1-r)*direct + r*reflected) + t*refracted;
26
Ray Probabilities
• Rewrite to get the individual weights
• Choose type of ray randomly based on their weights. Example:
wd = (1-t)*(1-r)wr = (1-t)*r wd + wr + wt = 1wt = t
wd = 0.50wr = 0.35wt = 0.15
50% probability of random ray35% probability of reflected ray15% probability of refracted ray
float uniform(); // random number in [0,1)
27
Exercise 3 Result
Same setup as before:
Resolution 256x256100 samples/pixel
28
Noise
• Random sampling gives very noisy output:
• Reduce noise:– More samples -> Slow– Better sampling strategy -> Importance Sampling
29
Random Sampling
• The rendering equation:
• Our estimation: N uniform random samples Ψi€
L x →Θ( ) = L(x∫ ← Ψ) fr x,Ψ↔Θ( ) cos Nx ,Ψ( )dωΨ
€
L x→Θ( ) ≈ 1N
L x←Ψi( ) f r x,Ψi ↔Θ( )cos(Nx,Ψi)i∑
trace(…) getBRDF(…)
30
Importance Sampling
• Choose sampling directions Ψi smarter
• Higher probability for samples near normal
€
L x →Θ( ) = L(x∫ ← Ψ) fr x,Ψ↔Θ( ) cos Nx ,Ψ( )dωΨ
€
P Ψi( )∝cos Nx,Ψi( )
31
Importance Sampling
• We must divide by probability of each sample:
• Implement cosine sampling in sampleCosine€
L x→Θ( ) ≈ 1N
L x←Ψi( ) f r x,Ψi ↔Θ( )cos(Nx,Ψi)p Ψi( )i
∑
32
Cosine Sampling
• Describe directions on hemisphere by (θ,φ):• Set z = normal
• Want samples with:
• How?
normal
€
p(θ,φ) =cosθπ
33
Use the CDF
• Compute the cumulative distribution function by integrating over the hemisphere:(details p. 65-66 in Advanced Global Illumination)
• Separable into:€
F θ,φ( ) =1π
p θ,φ( )dθdφ =φ2π
1− cos2θ( )0
θ
∫0
φ
∫
€
Fφ =φ2π
Fθ =1− cos2θ
34
CDF Sampling
• Set the CDF:s to random numbers u1,u2 in [0,1)
• Spherical coordinates (θ,φ) to Cartesian (x,y,z):
€
Fφ = u1Fθ = u2
€
x = cosφ sinθy = sinφ sinθz = cosθ
35
Coordinate Transform
• The sampling direction (x,y,z) is in local coords,transform to world coordinates with z = normal
• Setup orthogonal base vectors:• Transform dir to world space
36
Sampling Probability
• The sampling direction should be computed in:
• Return the probability of the sample in pdf• Change trace() to divide by the probability:
sampleCosine(Intersection is, float& pdf);
out = trace(r) * brdf / (pdf * 2.0f*M_PI);
correction factor
37
Why an extra 2π?
• With random sampling we assumed pdf = 1 (no division), but:
• To get matching output, we must multiply our pdf by 2π
€
1dθdφ = 2πθ = 0
π / 2
∫φ= 0
2π
∫
38
Exercise 4 Result
Resolution 256x256100 samples/pixel
39
Comparison
Random sampling
40
Comparison
Cosine sampling
41
Conclusions
• Cosine-weighted importance sampling:– (Slightly) Less noise than random sampling– Simple and fast
• More advanced importance sampling:– Environment map importance sampling– BRDF importance sampling– Product sampling (Rejection, Resampling, Wavelets)
42
Examples
43
Examples
44