π± π, πβ² = π(π, πβ²) π π, πβ² + ΰΆ±
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
INFOMAGR β Advanced Graphics
Jacco Bikker - November 2019 - February 2020
Lecture 6 - Path Tracing Welcome! , = (, ) , - - PowerPoint PPT Presentation
INFOMAGR Advanced Graphics Jacco Bikker - November 2019 - February 2020 Lecture 6 - Path Tracing Welcome! , = (, ) , + , , ,
π± π, πβ² = π(π, πβ²) π π, πβ² + ΰΆ±
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
Jacco Bikker - November 2019 - February 2020
βͺ Introduction βͺ Path Tracing
Advanced Graphics β Path Tracing 3
Previously in Advanced Graphics
The Rendering Equation: ππ π¦, ππ = ππΉ π¦, ππ + ΰΆ±
π»
π
π π¦, ππ, ππ ππ π¦, ππ cos ππ πππ
β¦which models light transport as it happens in the real world, by summing: βͺ Direct illumination: ππΉ(π¦, ππ) βͺ Indirect illumination, or reflected light: Χ¬
π» π π π¦, ππ, ππ ππ π¦, ππ cos ππ πππ
We used quantities flux πΈ (joules per second), radiance π (flux per π2 per sr) and irradiance πΉ (flux per π2).
Advanced Graphics β Path Tracing 4
Previously in Advanced Graphics
Particle transport: As an alternative to discrete flux / radiance / irradiance, we can reason about light transport in terms of particle transport. βͺ Flux then becomes the number of emitted photons; βͺ Radiance the number of photons travelling through a unit area in a unit direction; βͺ Irradiance the number of photons arriving on a unit area. A BRDF tells us how many particles are absorbed, and how outgoing particles are
Advanced Graphics β Path Tracing 5
Previously in Advanced Graphics
Probabilities: We can also reason about the behavior of a single photon. In that case, the BRDF tells us the probability of a photon being absorbed, or leaving in a certain direction.
Advanced Graphics β Path Tracing 6
Previously in Advanced Graphics
BRDFs:
Advanced Graphics β Path Tracing 7
Light Transport
π π‘ β π¦ = ππΉ π‘ β π¦ + ΰΆ±
π΅
π
π π‘ β π¦ β π¦β² π π¦ β π¦β² π» π¦ β π¦β² ππ΅(π¦β²)
ππ π¦, ππ = ππΉ π¦, ππ + ΰΆ±
π»
π
π π¦, ππ, ππ ππ π¦, ππ cos ππ πππ
Radiance Radiance Radiance Irradiance BRDF
Advanced Graphics β Path Tracing 8
Bidirectional Reflectance Distribution Function
BRDF: function describing the relation between radiance emitted in direction ππ and irradiance arriving from direction ππ: π
π ππ, ππ = ππ(ππ)
πΉπ(ππ) = ππ(ππ) ππ ππ cos ΞΈπ = ππ£π’πππππ π πππππππ ππππππππ ππ π πππππππ Or, if spatially variant: π
π π¦, ππ, ππ = ππ(π¦, ππ)
πΉπ(π¦, ππ) = ππ(π¦, ππ) ππ π¦, ππ cos ΞΈπ Properties: βͺ Should be positive: π
π ππ, ππ β₯ 0
βͺ Helmholtz reciprocity should be obeyed: π
π ππ, ππ = π π ππ, ππ
βͺ Energy should be conserved: Χ¬
π» π π ππ, ππ cos ππ πππ β€ 1
Advanced Graphics β Path Tracing 9
Bidirectional Reflectance Distribution Function
The diffuse BRDF is: π
π ππ, ππ = ππππππ
Ο So, for a total irradiance πΉ at surface point π¦, the
ππππππ π
. Why the π? Energy conservation: πΉπ β€ πΉπ Suppose we have a directional light parallel to π, with intensity 1. Then: πΉπ = ππ = 1. Suppose our BRDF =
ππππππ 1
. Then, for albedo = 1 we get: πΉπ = Χ¬
π» ππ π π (ππ , ππ) cos ππ πππ = Χ¬ π» cos ππ πππ
Now: Χ¬
π» cos ππ πππ = π β πΉπ = π πΉπ.
π ππ
Advanced Graphics β Path Tracing 10
Bidirectional Reflectance Distribution Function
Mirror / Perfect specular: Reflects light in a fixed direction. For a given incoming direction ππ, all light is emitted in a single infinitesimal set of directions. The specular BRDF is thus π
π π¦, ππ, ππ = αβ, along reflected vector
0, otherwise. This is not practical, and therefore we will handle the pure specular case (reflection and refraction) separately.
π ππ ππ
Advanced Graphics β Path Tracing 11
Previously in Advanced Graphics
Monte Carlo integration: Complex integrals can be approximated by replacing them by the expected value of a stochastic experiment. βͺ Soft shadows: randomly sample the area of a light source; βͺ Glossy reflections: randomly sample the directions in a cone; βͺ Depth of field: randomly sample the aperture; βͺ Motion blur: randomly sample frame time. In the case of the rendering equation, we are dealing with a recursive integral. Pat ath tr tracing: evaluating th this in integral us using a a ran andom walk.
βͺ Introduction βͺ Path Tracing
Advanced Graphics β Path Tracing 13
Solving the Rendering Equation
Letβs start with direct illumination: For a screen pixel, diffuse surface point π with normal π is directly visible. What is the radiance travelling via π towards the eye? Answer: ππ π, ππ = ΰΆ±
π»
π
π π, ππ, ππ ππ π, ππ cos ππ πππ
p ππ ππ π
Advanced Graphics β Path Tracing 14
Solving the Rendering Equation
Letβs start with direct illumination: For a screen pixel, diffuse surface point π with normal π is directly visible. What is the radiance travelling via π towards the eye? Answer: ππ π, ππ = ΰΆ±
π»
π
π π, ππ, ππ ππ π, ππ cos ππ πππ
p ππ ππ π ππ π, ππ = ΰΆ±
π»
π
π π, ππ, ππ ππ π, ππ cos ππ πππ
= ππππππ π ΰΆ±
π»
ππ π, ππ cos ππ πππ Q: What about distance attenuation? A: A far-away light is found by fewer directions ππ: itβs solid ang angle on the hemisphere is smaller. Q: What about the diffuse surface? A: The BRDF is independent of ππ (it doesnβt appear in the equation), but as ππ approaches the horizon, cos ππ approaches zero.
Advanced Graphics β Path Tracing 15
Direct Illumination
We can solve this integral using Monte-Carlo integration:
βͺ Chose N random directions over the hemisphere for π βͺ Find the first surface in each direction by tracing a ray βͺ Sum the luminance of the encountered surfaces βͺ Divide the sum by N and multiply by 2Ο
ππ π, ππ β 2π π ΰ·
π=1 π
π
π π, ππ, ππ ππ π, ππ cos ππ
p ππ ππ π
Advanced Graphics β Path Tracing 16
Direct Illumination
ππ π, ππ β 2π π ΰ·
π=1 π
π
π π, ππ, ππ ππ π, ππ cos π
Questions: βͺ Why do we multiply by 2π? βͺ What is the radiance ππ(π, ππ) towards π for e.g. a 100W light? βͺ What is the irradiance πΉ at π from this light? p ππ ππ π
We integrate over the hemisphere, which has an area of 2π. Do not confuse this with the 1/ π factor in the BRDF, which doesnβt compensate for the surface of the hemisphere, but the integral of cos π over the hemisphere (π). π is per sr; ππ(π, ππ) is proportional to the solid angle of the light as seen from p, so: ~ (cos ππ π΅ππ)/π 2. Note that the 100W flux is spread
defined per π2.
Advanced Graphics β Path Tracing 17
Direct Illumination
ππ π, ππ = ΰΆ±
π»
π
π π, ππ, ππ ππ π, ππ cos ππ πππ
In many directions, we will not find light sources. We can improve our estimate by sampling the lights separately. ππ π, ππ = ΰ·
π=1 πππβπ’π‘
ΰΆ±
π»
π
π π, ππ, ππ ππ π π, ππ cos ππ πππ
Obviously, sampling the entire hemisphere for each light is not necessary; we can sample the area of the light instead: ππ π, ππ = ΰ·
π=1 πππβπ’π‘
ΰΆ±
π΅
π
π π, ππ, ππ ππ π π, ππ cos ππ πππ
Advanced Graphics β Path Tracing 18
Direct Illumination
ππ π, ππ = ΰ·
π=1 πππβπ’π‘
ΰΆ±
π΅
π
π π, ππ, ππ ππ π π, ππ cos ππ πππ
Using Monte-Carlo: ππ π, ππ β πππβπ’π‘ β 1 π ΰ·
π=1 π
π
π π, ππ, π ππ πΎ π, π π π β π
π΅ππ
πΎ cos ππ cos ππ
β₯ π β π β₯2 where βͺ ππ
πΎ (π, π) is the direct light towards p from random point π on random light πΎ
βͺ π π β π is the mutual visibility between π and π βͺ π΅ππ
πΎ is the area of this light source
βͺ (π΅ππ
πΎ cos ππ)/(β₯ π β π β₯2) is the area of the light source projected on the
hemisphere, which approximates the solid angle of the light.
Recall:
Advanced Graphics β Path Tracing 19
Direct Illumination
We now have two methods to estimate direct illumination using Monte Carlo integration:
ππ π, ππ β 2π π ΰ·
π=1 π
π
π π, ππ, β¦π ππ π, β¦π cos ππ
ππ π, ππ β πππβπ’π‘ β 1 π ΰ·
π=1 π
π
π π, ππ, π ππ πΎ π, π π π β π
π΅ππ
πΎ cos ππ cos ππ
β₯ π β π β₯2 For π = β, these yield the same result.
Advanced Graphics β Path Tracing 20
Direct Illumination
We now have two methods to estimate direct illumination using Monte Carlo integration:
ππ π, ππ β 2π π ΰ·
π=1 π
π
π π, ππ, β¦π ππ π, β¦π cos ππ
ππ π‘ β π β πππβπ’π‘ β 1 π ΰ·
π=1 π
π
π π‘ β π β π ππ πΎ π β π π π β π
π΅ππ
πΎ cos ππ cos ππ
β₯ π β π β₯2 For π = β, these yield the same result.
Advanced Graphics β Path Tracing 21
Verification
Method 1 in a small C# ray tracing framework:
In: Ray ray, with members O, D, N, t. Already calculated: intersection point I = O + t * D. Vector3 R = RTTools.DiffuseReflection( ray.N ); Ray rayToHemisphere = new Ray( I + R * EPSILON, R, 1e34f ); Scene.Intersect( rayToHemisphere ); if (rayToHemisphere.objIdx == LIGHT) { Vector3 BRDF = material.diffuse * INVPI; float cos_i = Vector3.Dot( R, ray.N ); return 2.0f * PI * BRDF * Scene.lightColor * cos_i; }
ππ π, ππ β 2π π ΰ·
π=1 π
π
π π, ππ, β¦π ππ π, β¦π cos ππ
Advanced Graphics β Path Tracing 22
Verification
Method 2 in a small C# ray tracing framework:
// construct vector to random point on light Vector3 L = Scene.RandomPointOnLight() - I; float dist = L.Length(); L /= dist; float cos_o = Vector3.Dot( -L, lightNormal ); float cos_i = Vector3.Dot( L, ray.N ); if ((cos_o <= 0) || (cos_i <= 0)) return BLACK; // light is not behind surface point, trace shadow ray Ray r = new Ray( I + EPSILON * L, L, dist - 2 * EPSILON ); Scene.Intersect( r ); if (r.objIdx != -1) return Vector3.Zero; // light is visible (V(p,pβ)=1); calculate transport Vector3 BRDF = material.diffuse * INVPI; float solidAngle = (cos_o * Scene.LIGHTAREA) / (dist * dist); return BRDF * lightCount * Scene.lightColor * solidAngle * cos_i;
ππ π, ππ β πππβπ’π‘ β 1 π ΰ·
π=1 π
π
π π, ππ, π ππ πΎ π, π π π β π
π΅ππ
πΎ cos ππ cos ππ
β₯ π β π β₯2
Advanced Graphics β Path Tracing 23
Advanced Graphics β Path Tracing 24
Advanced Graphics β Path Tracing 25
Advanced Graphics β Path Tracing 26
Advanced Graphics β Path Tracing 27
Rendering using Monte Carlo Integration
In the demonstration, we sampled each light using only 1 sample. The (very noisy) result is directly visualized. To get a better estimate, we average the result of several frames (and thus: several samples). Observations:
Advanced Graphics β Path Tracing 28
Indirect Light
Returning to the full rendering equation: We know how to evaluate direct lighting: What remains is indirect light. This is the light that is not emitted by the surface in direction ππ, but reflected.
Advanced Graphics β Path Tracing 29 direct light 1st bounce 2nd bounce
ββ¦ Indirect Light
Letβs expand / reorganize this: ππ π¦, ππ
π¦ = ππΉ π¦, ππ π¦
+ ΰΆ±
π»
ππΉ π§, ππ
π§ π π π¦, ππ π¦, ππ π¦
cos ππ
π¦ πππ π¦
+ ΰΆ±
π»
ΰΆ±
π»
ππΉ π¨, ππ
π π π π§, ππ π, ππ π
cos ππ
π π π π¦, ππ π¦, ππ π¦
cos ππ
π¦ πππ π¦ πππ π
+ ΰΆ±
π»
ΰΆ±
π»
ΰΆ±
π»
β¦ π¦ π§ π π¨
Advanced Graphics β Path Tracing 30
Indirect Light
One particle finding the light via a surface:
I, N = Trace( ray ); R = DiffuseReflection( N ); lightColor = Trace( new Ray( I, R ) ); return dot( R, N ) *
ππππππ π
* lightColor * 2π;
One particle finding the light via two surfaces:
I1, N1 = Trace( ray ); R1 = DiffuseReflection( N1 ); I2, N2 = Trace( new Ray( I1, R1 ) ); R2 = DiffuseReflection( N2 ); lightColor = Trace( new Ray( I2, R2 ) ); return dot( R1, N1 ) *
ππππππ π
* 2π * dot( R2, N2 ) *
ππππππ π
* 2π * lightColor;
π¦ π§ π§ π¨
Advanced Graphics β Path Tracing 31
Path Tracing Algorithm
Color Sample( Ray ray ) { // trace ray I, N, material = Trace( ray ); // terminate if ray left the scene if (ray.NOHIT) return BLACK; // terminate if we hit a light source if (material.isLight) return material.emittance; // continue in random direction R = DiffuseReflection( N ); Ray newRay( I, R ); // update throughput BRDF = material.albedo / PI; Ei = Sample( newRay ) * dot( N, R ); // irradiance return PI * 2.0f * BRDF * Ei; }
π¦ π§ π§ π¨
Advanced Graphics β Path Tracing 32
Advanced Graphics β Path Tracing 33
Advanced Graphics β Path Tracing 34
Advanced Graphics β Path Tracing 35
Advanced Graphics β Path Tracing 36
Particle Transport
The random walk is analogous to particle transport: βͺ a particle leaves the camera βͺ at each surface, energy is absorbed proportional to 1-albedo (βsurface colorβ) βͺ at each surface, the particle picks a new direction βͺ at a light, the path transfers energy to the camera. In the simulation, particles seem to travel backwards. This is valid because of the Helmholtz reciprocity. Notice that longer paths tend to return less energy.
Color Sample( Ray ray ) { // trace ray I, N, material = Trace( ray ); // terminate if ray left the scene if (ray.NOHIT) return BLACK; // terminate if we hit a light source if (material.isLight) return emittance; // continue in random direction R = DiffuseReflection( N ); Ray r( I, R ); // update throughput BRDF = material.albedo / PI; Ei = Sample( r ) * (NβR); return PI * 2.0f * BRDF * Ei; }
Advanced Graphics β Path Tracing 37
Particle Transport - Mirrors
Handling a pure specular surface: A particle that encounters a mirror continues in a deterministic way. Question: βͺ What happens at a red mirror? βͺ What happens if a material is only half reflective?
Color Sample( Ray ray ) { // trace ray I, N, material = Trace( ray ); // terminate if ray left the scene if (ray.NOHIT) return BLACK; // terminate if we hit a light source if (material.isLight) return emittance; // surface interaction if (material.isMirror) { // continue in fixed direction Ray r( I, Reflect( N ) ); return material.albedo * Sample( r ); } // continue in random direction R = DiffuseReflection( N ); BRDF = material.albedo / PI; Ray r( I, R ); // update throughput Ei = Sample( r ) * (NβR); return PI * 2.0f * BRDF * Ei; }
Advanced Graphics β Path Tracing 38
Particle Transport - Glass
Handling dielectrics: Dielectrics reflect and transmit light. In the ray tracer, we handled this using two rays. A particle must chose. The probability of each choice is calculated using the Fresnel equations.
Color Sample( Ray ray ) { // trace ray I, N, material = Trace( ray ); // terminate if ray left the scene if (ray.NOHIT) return BLACK; // terminate if we hit a light source if (material.isLight) return emittance; // surface interaction if (material.isMirror) { // continue in fixed direction Ray r( I, Reflect( N ) ); return material.albedo * Sample( r ); } // continue in random direction R = DiffuseReflection( N ); BRDF = material.albedo / PI; Ray r( I, R ); // update throughput Ei = Sample( r ) * (NβR); return PI * 2.0f * BRDF * Ei; }
Advanced Graphics β Path Tracing 39
Advanced Graphics β Path Tracing 40
βͺ Introduction βͺ Path Tracing
Jacco Bikker - November 2019 - February 2020
next lecture: βGPU Ray Tracing (1)β
Advanced Graphics β Path Tracing 43
Solid Angle
A few words on solid angle: As mentioned in lecture 4, solid angle is measured in steradians. Where radians are the length of an arc on the unit circle subtended by two directions, steradians are the surface
In this lecture, we used:
π΅ cos ΞΈ π 2
, which is only an approximation, except when the shape is a segment of a sphere and cos ΞΈ = 1. For π β« π΅, this approximation is βgood enoughβ.
Advanced Graphics β Path Tracing 44
Additional literature:
Slides for lecture 9 of the Advanced Computer Graphics course of the University of Freiburg, by Matthias Teschner: http://cg.informatik.uni-freiburg.de/course_notes/graphics2_09_pathTracing.pdf Blog: A graphics guyβs note: https://agraphicsguy.wordpress.com Monte Carlo Path Tracing, Path Hanrahan: http://cs.brown.edu/courses/cs224/papers/mc_pathtracing.pdf Path Tracing - Theoretical Foundation, by Vidar Nelson: http://www.vidarnel.com/post/path_tracing Importance Sampling for Production Rendering, SIGGRAPH 2010 course: http://igorsklyar.com/system/documents/papers/4/fiscourse.comp.pdf Please share additional resources on the forum.