INFOMAGR β Advanced Graphics Jacco Bikker - February β April 2016 Welcome! π± π, π β² = π(π, π β² ) π π, π β² + π π, π β² , π β²β² π± π β² , π β²β² ππβ²β² π»
Todayβs Agenda: ο§ Introduction ο§ Stratification ο§ Next Event Estimation ο§ Importance Sampling ο§ MIS
Advanced Graphics β Variance Reduction 3 Introduction Previously in Advanced Graphics
Advanced Graphics β Variance Reduction 4 Introduction
Advanced Graphics β Variance Reduction 5 Introduction Today in Advanced Graphics: Stratification ο§ Next Event Estimation ο§ Importance Sampling ο§ Multiple Importance Sampling ο§ Resampled Importance Sampling* ο§ Aim: ο§ to get a better image with the same number of samples ο§ to increase the efficiency of a path tracer ο§ to reduce variance in the estimate Requirement: ο§ produce the correct image *: If time permits
Todayβs Agenda: ο§ Introduction ο§ Stratification ο§ Next Event Estimation ο§ Importance Sampling ο§ MIS
Advanced Graphics β Variance Reduction 7 Stratification Uniform Random Sampling To sample a light source, we draw two random values in the range 0..1. The resulting 2D positions are not uniformly distributed over the area. We can improve uniformity using stratification : one sample is placed in each stratum.
Advanced Graphics β Variance Reduction 8 Stratification Uniform Random Sampling To sample a light source, we draw two random values in the range 0..1. The resulting 2D positions are not uniformly distributed over the area. We can improve uniformity using stratification : one sample is placed in each stratum. For 4x4 strata: stratum_x = (idx % 4) * 0.25 // idx = 0..15 stratum_y = (idx / 4) * 0.25 r0 = Rand() * 0.25 r1 = Rand() * 0.25 P = vec2( stratum_x + r0, stratum_y + r1 )
Advanced Graphics β Variance Reduction 9 Stratification
Advanced Graphics β Variance Reduction 10 Stratification Use Cases Stratification can be applied to any Monte Carlo process: ο§ Anti-aliasing (sampling the pixel) ο§ Depth of field (sampling the lens) ο§ Motion blur (sampling time) ο§ Soft shadows (sampling area lights) ο§ Diffuse reflections (sampling the hemisphere) However, there are problems: ο§ We need to take one sample per stratum ο§ Stratum count: higher is better, but with diminishing returns ο§ Combining stratification for e.g. depth of field and soft shadows leads to correlation of the samples, unless we stratify the 4D space - which leads to a very large number of strata: the curse of dimensionality .
Advanced Graphics β Variance Reduction 11 Stratification Alleviating the Curse of Dimensionality Imagine we have 2x2 strata for the lens, and 2x2 for area lights. We can sample this with 4 samples without correlation by randomly combining strata. In practice: ο§ We generate 4 positions on the lens with stratification; ο§ We generate 4 positions on the area light with stratification; ο§ When sampling the lens, we randomly select a stratum from the array of lens samples; ο§ When sampling the area light, we randomly select a stratum from the array of area light samples.
Advanced Graphics β Variance Reduction 12 Stratification Alleviating the Curse of Dimensionality Imagine we have 2x2 strata for the lens, and 2x2 for area lights. We can sample this with 4 samples without correlation by randomly combining strata. Even more practical: ο§ Generate an array of stratified pairs of random numbers: random[N][M][2], where π is the number of strata and π is the number of dimensions / 2. ο§ Shuffle entries 0..N-1 for each M. ο§ Take samples from this array whenever you need a random number. ο§ If you run out, switch to uniform random numbers.
Advanced Graphics β Variance Reduction 13 Stratification Troubleshooting Path Tracing Experiments When experimenting with stratification and other variance reduction methods you will frequently produce incorrect images. Tip: Keep a simple reference path tracer without any tricks. Compare your output to this reference solution frequently.
Todayβs Agenda: ο§ Introduction ο§ Stratification ο§ Next Event Estimation ο§ Importance Sampling ο§ MIS
Advanced Graphics β Variance Reduction 15 NEE Next Event Estimation Recall the rendering equation: β¦and the way we Vector3 R = DiffuseReflection( ray.N ); sampled it using Also recall that we had two ways Ray rayToHemisphere = new Ray( I + R * EPSILON, R ); to sample direct illumination: Monte Carlo: Scene.Intersect( rayToHemisphere ); if (rayToHemisphere.objIdx == LIGHT) { randomly sampling Vector3 BRDF = material.diffuse / π ; the hemisphere float cos_i = Vector3.Dot( R, ray.N ); 2.0f * π * BRDF * return Scene.lightColor * cos_i; } directly sampling the lights Can we apply this to the full rendering equation, instead of just direct illumination?
Advanced Graphics β Variance Reduction 16 NEE Next Event Estimation Light travelling via any vertex on the path consists of indirect light and direct light for that vertex. Next Event Estimation : sampling direct and indirect separately.
Advanced Graphics β Variance Reduction 17 NEE Next Event Estimation Light travelling via any vertex on the path consists of indirect light and direct light for that vertex. Next Event Estimation: sampling direct and indirect separately. Mathematically: Problem: we are now sampling lights twice. = π π π¦, π π Solution 1: scale by 0.5. 1 + π π π¦, π π , π π π π π¦, π π cos π π ππ π Solution 2: π» ignore direct light when using 1 . πππβπ’π‘ π΅ π π π cos π π cos π π π π¦ β π¦β² 2 + π π π‘ β π¦ β π¦β² π π ππ π β₯ π¦ β π¦β² β₯ 2 π΅ π=1
Advanced Graphics β Variance Reduction 18 NEE Next Event Estimation Per surface interaction, we trace two rays. ο§ Ray A returns via point x the energy reflected by π§ ο§ Ray B returns the direct illumination on point π¦ ο§ Ray C returns the direct illumination on point π§ , which will reach the sensor via ray A. ο§ Ray D leaves the scene. π§ C D A B π¦
Advanced Graphics β Variance Reduction 19 NEE Next Event Estimation When a ray for indirect illumination stumbles upon a light, the path is terminated and no energy is transported via ray D: This way, we prevent accounting for direct illumination on point π§ twice. π§ D C A B π¦
Advanced Graphics β Variance Reduction 20 NEE Next Event Estimation Color Sample( Ray ray ) { // trace ray I, N, material = Trace( ray ); BRDF = material.albedo / PI; // terminate if ray left the scene if (ray.NOHIT) return BLACK; // terminate if we hit a light source if (material.isLight) return BLACK; // sample a random light source L, Nl, dist, A = RandomPointOnLight(); Ray lr( I, L, dist ); if (NβL > 0 && Nl β -L > 0) if (!Trace( lr )) { solidAngle = ((Nl β -L) * A) / dist 2 ; Ld = lightColor * solidAngle * BRDF * Nβ L; } // continue random walk R = DiffuseReflection( N ); Ray r( I, R ); Ei = Sample( r ) * (NβR ); return PI * 2.0f * BRDF * Ei + Ld; }
Advanced Graphics β Variance Reduction 21 NEE
Advanced Graphics β Variance Reduction 22 NEE
Advanced Graphics β Variance Reduction 23 NEE
Advanced Graphics β Variance Reduction 24 NEE Next Event Estimation Some vertices require special attention: ο§ If the first vertex after the camera is emissive, its energy canβt be reflected to the camera. ο§ For specular surfaces, the BRDF to a light is always 0. Since a light ray doesnβt make sense for specular vertices, we will include emission from a vertex directly following a specular vertex. The same goes for the first vertex after the camera: if this is emissive, we will also include this. This means we need to keep track of the type of the previous vertex during the random walk.
Advanced Graphics β Variance Reduction 25 NEE Color Sample( Ray ray, bool lastSpecular ) { // trace ray I, N, material = Trace( ray ); BRDF = material.albedo / PI; // terminate if ray left the scene if (ray.NOHIT) return BLACK; // terminate if we hit a light source if (material.isLight) if (lastSpecular) return material.emissive; else return BLACK; // sample a random light source L, Nl, dist, A = RandomPointOnLight(); Ray lr( I, L, dist ); if (NβL > 0 && Nl β -L > 0) if (!Trace( lr )) { solidAngle = ((Nl β -L) * A) / dist 2 ; Ld = lightColor * solidAngle * BRDF * Nβ L; } // continue random walk R = DiffuseReflection( N ); Ray r( I, R ); Ei = Sample( r, false ) * (NβR ); return PI * 2.0f * BRDF * Ei + Ld; }
Todayβs Agenda: ο§ Introduction ο§ Stratification ο§ Next Event Estimation ο§ Importance Sampling ο§ MIS
Advanced Graphics β Variance Reduction 27 Importance Sampling Importance Sampling for Monte Carlo Monte Carlo integration: π πΆ πΆ β π΅ β πΆ π π΅ = π(π¦) ππ¦ = ππ¦ πΉ π π¦ π x π π π΅ π΅ π=1 Example 1: rolling two dice πΈ 1 and πΈ 2 , the outcome is 6πΈ 1 + πΈ 2 . What is the expected value of this experiment? (average die value is 3.5, so the answer is of course 3.5 * 6 + 3.5 = 24.5) Using Monte Carlo: π π = 1 π( πΈ 1 ) + π( πΈ 2 ) π₯βππ π: πΈ 1 , π πΈ 1 β {1,2,3,4,5,6}, π π¦ = 6π¦, π π¦ = π¦ π=1
Recommend
More recommend