INFOMAGR β Advanced Graphics Jacco Bikker - February β April 2016 Welcome! π± π, π β² = π(π, π β² ) π π, π β² + π π, π β² , π β²β² π± π β² , π β²β² ππβ²β² π»
Todayβs Agenda: ο§ Introduction ο§ Path Tracing
Advanced Graphics β Path Tracing 3 Introduction 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 πΉ (joules per second per π 2 ).
Advanced Graphics β Path Tracing 4 Introduction 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 distributed. The distribution depends on the incident and exitant direction.
Advanced Graphics β Path Tracing 5 Introduction 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 Introduction Previously in Advanced Graphics BRDFs: The BRDF describes how incoming light is absorbed or scattered. A physically based BRDF has some important properties: ο§ π π π π , π π β₯ 0 ο§ π π π π , π π = π π π π , π π π π ο§ π» π π π π , π π cos π π ππ π β€ 1 π
Advanced Graphics β Path Tracing 7 Introduction 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. Path tracing: evaluating this integral using a random walk .
Todayβs Agenda: ο§ Introduction ο§ Path Tracing
Advanced Graphics β Path Tracing 9 Path Tracing 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 10 Path Tracing 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π π π π π, π π , π π π π π, π π cos π π π=1 π π π π π p
Advanced Graphics β Path Tracing 11 Path Tracing We integrate over the hemisphere, which Direct Illumination has an area of 2 π . π Do not confuse this with the 1/ π factor π π π, π π β 2π in the BRDF, which doesnβt compensate π π π π, π π , π π π π π, π π cos π for the surface of the hemisphere, but the π=1 integral of cos π over the hemisphere ( π ). Questions: ο§ Why do we multiply by 2π ? ο§ What is the radiance π π (π, π π ) towards π for e.g. a 100W light? ο§ What is the irradiance πΉ arriving at π from this light? ο§ Are we obeying energy conservation? π is per sr; π π (π, π π ) is proportional to the solid angle of π π as seen from π π p , so (cos π π π΅ π π )/π 2 . π π π Note that the 100W flux is spread out over the area; irradiance is defined per π 2 . p
Advanced Graphics β Path Tracing 12 Path Tracing Direct Illumination π π π, π π = π π π, π π , π π π π π, π π cos π π ππ π π» In many directions, we will not find light sources. We can improve our estimate by sampling the lights separately. πππβπ’π‘ Here, C compensates for the fact π π, π π cos π π ππ π that we now sample the area of π π π, π π = π π π, π π , π π π π the light source, instead of the π» π=1 hemisphere. The probability of stumbling onto an unoccluded Obviously, sampling the entire hemisphere for each light light used to be proportional to is not necessary; we can sample the area of the light instead: solid angle; now it is always 1. C is therefore ~ (cos π π π΅ π π )/π 2 . πππβπ’π‘ π π, π π π· cos π π ππ π π π π, π π = π π π, π π , π π π π π΅ π=1
Advanced Graphics β Path Tracing 13 Path Tracing Direct Illumination πππβπ’π‘ π π, π π π· cos π π ππ π π π π, π π = π π π, π π , π π π π π΅ π=1 Using Monte-Carlo: π π β² π΅ π π π cos π π cos π π π π π, π π β πππβπ’π‘ β 1 π π, π β² π π π β² π π β π π π π, π π , πβ² β₯ 2 β₯ π β π=1 where π is the direct light to p from random point π β² on random light ο§ π π π ο§ π΅ π π π is the area of this light source π β² is the mutual visibility between p and pβ. ο§ π π β
Advanced Graphics β Path Tracing 14 Path Tracing Direct Illumination We now have two methods to estimate direct illumination using Monte Carlo integration: 1. By random sampling the hemisphere: π π π π, π π β 2π π π π π, π π , π π π π π, π π cos π π π=1 2. By sampling the lights directly: π π β² π΅ π π π cos π π cos π π π π π, π π β πππβπ’π‘ β 1 π π, π β² π π π β² π π β π π π π, π π , πβ² β₯ 2 β₯ π β π=1 For π = β , these yield the same result.
Advanced Graphics β Path Tracing 15 Path Tracing Direct Illumination We now have two methods to estimate direct illumination using Monte Carlo integration: 1. By random sampling the hemisphere: π π π π, π π β 2π π π π π, π π , π π π π π, π π cos π π π=1 2. By sampling the lights directly (three point notation): π π΅ π π π cos π π cos π π π π π‘ β π β πππβπ’π‘ β 1 π π β π π π π‘ β π β π π π π π π β π π β₯ 2 β₯ π β π=1 For π = β , these yield the same result.
Advanced Graphics β Path Tracing 16 Path Tracing π π π π, π π β 2π π π π π, π π , π π π π π, π π cos π π π=1 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; }
Advanced Graphics β Path Tracing 17 Path Tracing π π β² π΅ π π π cos π π cos π π π π π, π π β πππβπ’π‘ β 1 π π, π π, π π , π β² π π π β² π π β π π πβ² β₯ 2 β₯ π β π=1 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, new Vector3( 0, -1, 0 ) ); 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 * Scene.lightColor * solidAngle * cos_i;
Advanced Graphics β Path Tracing 18 Path Tracing 0.1s
Recommend
More recommend