Stochastic Ray Tracing Contents Classical Ray Tracing with Area Light Sources
Total Page:16
File Type:pdf, Size:1020Kb
Contents Stochastic Ray Tracing • Monte Carlo Integration • Application to direct lighting by area light sources • Solving the radiance equation with the Kadi Bouatouch Monte Carlo Method IRISA – Distributed Ray Tracing Email: [email protected] – Path Traycing 1 2 Classical Ray Tracing With Area Light Sources • One shadow ray by intersection point • Only point light sources • Hard shadows: umbra • Soft shadows • Area light sources != point light sources 3 4 More Sample Points on the Light Solution to the Rendering Equation Source y ψ y • Analytical solution: too ψθy V(x,y)=? θy much difficult V(x,y)=?rxy rxy θx • Use the Monte Carlo θ x x Θx method Θ cosθxcosθy e L(x→Θ)= fr (x,Θ↔Ψ)L (y→Ψ)V(x,y) 2 dy ∫ rxy • Approximate the source by a set of points AL • Aliasing along the shadows’ borders 5 6 Direct Lighting Direct Lighting y ψ y • Random point sampling of ψθy ψ θy the area light sources V(x,y)=?rxy y rxyω’ θx θ x x • Use these points to evaluate Θx x Θ the integral Θ ω cosθxcosθy e 1 shadow ray 9 shadow rays L(x→Θ)= fr (x,Θ↔Ψ)L (y→Ψ)V(x,y) 2 dy 1 ∫ rxy p(y)= AL AS N N 1 D(yi) 1 cosθxcosθyi L(x→Θ)= D(y)dy L(x→Θ) = L(x→Θ) = As f(x,Θ↔Ψ)Le(yi→Ψi ) Vis(x,yi) ∫ ∑ i ∑ 2 N p(y) N rxyi AL i=1 i=1 7 8 Direct Lighting Stratified Sampling 36 shadow rays 100 shadow rays N cosθxcosθyi 1 s e i i L(x→Θ) = ∑A f(x,Θ↔Ψ)L (y→Ψi ) 2 Vis(x,y) 9 shadow rays 9 shadow rays N rxyi i=1 without stratification with stratification 9 10 Stratified Sampling Stratified Sampling 36 shadow rays no 36 shadow rays with 100 shadow rays no 100 shadow rays with stratification stratification stratification stratification 11 12 Multiple Light Sources Multiple Light Sources • The integral does not change : rather than integrating over one light source, integrate over all the surfaces of the light sources cosθxcosθy r e L(x→Θ)= f (x,Θ↔Ψ)L (y→Ψ)V(x,y) 2 dy ∫ rxy AL • The pdf for selecting points is modified : first select a light source S using pdf p(S), then a point y on S with p(y|S) 36 shadow rays per pixel in the 2 images but with different p(S)=ΦS p(yS)= 1 p(y)=p(S)p(yS) ΦT As pdf 13 14 Application to pixels: oversampling Application to pixels: oversampling • Compute radiance at the centre • Any sampling method of a pixel Æ aliasing • Oversample a pixel and compute radiance for sub-pixels • Use a filter L= ∫ f(x)L(x)dx Pixel … evaluated by the Monte Carlo method. N f(xi)L(xi) L≈ 1 ∑ N i=1 p(xi) 15 16 Application to pixels: oversampling Implementation • Comparison : 1 centered ray per pixel 100 centered rays per pixel 1 ray / pixel 10 rays / pixel 100 rays / pixel 100 random shadow rays 1 random shadow rays per per intersection intersection 17 18 The Rendering Equation The Rendering Equation • Evaluation of the rendering equation L(x→Θ)=Le(x→Θ)+ ∫ fr(x,Ψ↔Θ)⋅L(x←Ψ)⋅cos(Ψ,nx)⋅dωΨ • How to write the rendering equation and Ωx how to evaluate it using Monte Carlo Lx()←Ψ Lx() integration? →Θ Lxe ()→Θ – Which pdf to use for the rendering equation ? x – Algorithms and results 19 20 The Rendering Equation Computing Radiance • How to evaluate L ? L(x→Θ)=Le(x→Θ)+ ∫ fr(x,Ψ↔Θ)⋅L(x←Ψ)⋅cos(Ψ,nx)⋅dωΨ Ωx –Find Le(x→Θ) = Le + ⋅ fr ⋅cos – Add: ∫ L=? Ω x ∫ fr (x,Ψ ↔ Θ)⋅ L(x ← Ψ)⋅cos(Ψ,nx )⋅dωΨ Ωx 21 22 Computing Radiance Computing Radiance • How to evaluate L ? • Hemisphere Sampling θin – Monte Carlo Integration π / 2 dω Θin – Generate random directions on Ω , using the x θin probability density function p(Ψ) ϕ 0 in 0 2π ϕin L(x→Θ)= ∫ fr(x,Ψ↔Θ)⋅L(x←Ψ)⋅cos(Ψ,nx)⋅dωΨ Ωx p(Θ)=cosθ ⇒θ=acos( ξ )etϕ=2πξ π 1 2 N 1 fr(x,Ψi↔Θ)⋅L(x←Ψi)⋅cos(Ψi,nx) Θ=(θ,ϕ)⇒dωΘ=sinθ⋅dθ⋅dϕ L(x→Θ) = ∑ 1 N i=1 p(Ψi) p(Θ)=n+1cosnθ⇒θ=acos(ξ n+1)etϕ=2πξ 2π 1 2 23 24 Computing Radiance Computing Radiance • Generate a random direction Ψi z Evaluation of L(x←Ψi) ? 1 N f ( )⋅ L(x ← Ψ )⋅cos( ) L = ∑ r K i K N i=1 p(Ψi ) z Radiance is constant along the propagation direction. Evaluate the BRDF z rc(x, Ψ ) = first visible point. Evaluate the cos(…) i Evaluate L(x←Ψi) z L(x←Ψi) = L(rc(x, Ψi) → Ψi) 25 26 Computing Radiance Stopping Recursion • When recursion is stopped? • Recursive Evaluation • Each bounce adds a level of indirect lighting. The contributions of higher order reflections are negligible. If we ignore them, the estimates are biased ! 27 28 Terminating the Recursion Russian Roulette • When/how do we stop the recursion? •Integral f (x) – When the ray doesn’t hit any object 1 1 α • Can be very hard/impossible for dense scenes I = ∫ f (x)dx = ∫ f (x /α)dx 0 α 0 – When a maximum depth is reached • Estimator • This is highly scene dependent 1 roulette f ( x / α ) if x < α – Primarily specular scenes requires far more bounces than < I >= α diffuse scenes • Having a fixed path length results in a biased estimate 0 if x > α – When the contribution of the ray falls below a certain • Use Russian roulette to decide α threshold – ray is absorbed with probability 1-α • More efficient than a fixed max depth, but still gives a biased – results in unbiased estimator result 29 30 Russian Roulette Russian Roulette • A simple and unbiased termination criteria is Russian roulette: •Example – Given a uniform random number ξ, terminate the ray –p = 0.9 , then α = 1- p = 0.1 if ξ ≥ α, otherwise scale the contribution of the ray by 1/α – One chance in 10 that ray is reflected. • Here αє [0,1] is the absorption probability – The radiance due to one reflected ray – Recursion stops with a probability of p = 1- α – By scaling the contribution of rays that continue by is multiplied by 10. 1/ α, the result remains unbiased – instead of shooting 10 rays, we shoot • Russian roulette is not practically useful until we only 1, but count the contribution of add direct light to our ray tracer!! this one 10 times 31 32 Russian Roulette Russian Roulette • With Russian roulette the pseudo code now looks like this: • Case of n incident rays RGB radiance(Ray r) if(r hits at x) N if(ξ < α) 1 fr (x,Ψi ↔ Θ)⋅ L(x ← Ψi )⋅cos(Ψi ,nx ) L(x → Θ) = ∑ Generate new direction, Di, from p ( Ψ ) and i=1 i N p(Ψi ) the surface normal at x Ray ray(x, Di) •Case of one incident ray return Le(x) + R(x,Di)*radiance(ray) / α else f (x, Di ↔ Θ)⋅ L(x ← Di)⋅cos(Di,n ) return Le(x) L(x → Θ) = r x p(Di) else return background = R(x, Di).L(x ← Di) 33 34 Russian Roulette Distribution Ray Tracing • Non biased Estimate • Algorithm – Trace N rays per pixel • The expected value is correct – At each intersection point, trace 1 ray (or more) randomly chosen on the hemisphere to evaluate the rendering equation • Bigger variance – End recursion using the Russian roulette • But more efficient 35 36 Distribution Ray Tracing Distribution Ray Tracing computeImage() { basicPT(x, theta) { for each pixel (i,j) { estimatedRadiance = Le(x, theta) estimatedRadiance[i,j] = 0 if(not absorbed) { // russian roulette for s = 1 to #samples-in-pixel { for s = 1 to #radianceSamples { // ray directions generate Q in pixel (i,j) theta = (Q – E)/|Q-E| // E is the Eye psi = generate random direction on hemisphere x = trace(E,theta) y = trace(x, psi) estimatedRadiance [i,j] += computeRadiance(x,-theta) estimatedRadiance += } basicPT(y,-psi) * BRDF(x,psi,theta)* estimatedRadiance [i,j] /= # samples-in-pixel cos(Nx,psi) / pdf(psi) } } } computeRadiance(x, theta) { estimatedRadiance /= #radianceSamples estimatedRadiance = basicPT(x, theta) } return estimatedRadiance return estimatedRadiance/(absorption) } } 37 38 Distribution Ray Tracing Distribution Ray Tracing 39 40 Distribution Ray Tracing Distribution Ray Tracing 1 ray/pixel 16 rays/pixel 256 rays/pixel Very noisy : null contribution as long as the path does not reach a light source!! L = ?? 41 42 Distribution Ray Tracing Distribution Ray Tracing Lee = 00 Linin = ?? Lrr = ?? 43 44 Distribution Ray Tracing Distribution Ray Tracing L = ?? Linin = ?? 45 46 Distribution Ray Tracing Distribution Ray Tracing Linin = ?? Lee=00 Lrr=?? 47 48 Distribution Ray Tracing Distribution Ray Tracing Lee = 11..234234 Lrr = ?? L = ?? 49 50 Distribution Ray Tracing Distribution Ray Tracing • Improve the algorithm by dividing the integral into two parts: direct and indirect Li(x→Θ)=∫ fr(x,Ψ↔Θ)⋅Le(x←Ψ)⋅cos(Ψ,nx)⋅dωΨ Ωx + ∫ fr(x,Ψ↔Θ)⋅Li(x←Ψ)⋅cos(Ψ,nx)⋅dωΨ Ωx L(x→Θ)=Le(x→Θ)+Li(x→Θ) 51 52 Distribution Ray Tracing Direct Illumination L (x → Θ) = f ( )⋅ L (x ← Ψ)⋅cos( )⋅dω direct ∫ r K e K Ψ Ωx – Evaluate differently the direct and the indirect = f ( )⋅ L (y → x)⋅cos( )⋅dω components ∫ r K e K Ψ Ωx cos( )dA = f ( )⋅ L (y → x)⋅cos( )⋅( K y )⋅V (x, y) ∫ r K e K 2 Area rxy ⋅ f ⋅cos + ⋅ f ⋅cos source ∫ r ∫ r Source Ω x dAy Θ dA yycosθ dω = dω Θ 2 x Θ r 53 54 Indirect Illumination Indirect Illumination Li (x → Θ) = ∫ fr (x,Ψ ↔ Θ)⋅ Li (x ← Ψ)⋅cos(Ψ,nx )⋅dωΨ Li (x → Θ) = ∫ fr (x,Ψ ↔ Θ)⋅ Li (x ← Ψ)⋅cos(Ψ,nx )⋅dωΨ Ωx Ωx 55 56 Distribution Ray Tracing Distribution Ray Tracing L(x→Θ)= ∫ fr(x,Ψ↔Θ)⋅L(x←Ψ)⋅cos(Ψ,nx)⋅dωΨ •Uniform distribution Ωx N 1 fr(x,Ψi↔Θ)⋅L(x←Ψi)⋅cos(Ψi,nx) p(Ψ) = L(x→Θ) = 1 ∑ 2π N i=1 p(Ψi) 2π N • Depends on how to sample the hemisphere L(x → Θ) = ∑ fr (x,Ψi ↔ Θ)⋅ L(x ← Ψi )⋅cos(Ψi ,nx ) N i=1 – Uniform distribution – Importance sampling : pick p to match integral • Cosine distribution • BRDF distribution • BRDF*cosine distribution 57 58 Distribution Ray Tracing Distribution Ray Tracing •Cosine distribution •BRDF distribution cosθΨ p(Ψ) = p(Ψ) = fr(...) π π N 1 N L(x → Θ) = ∑ fr (x,Ψi ↔ Θ)⋅ L(x ← Ψi ) N i=1 L(x → Θ) = ∑ L(x ← Ψi )⋅cos(Ψi ,nx ) N i=1 59 60 Distribution Ray Tracing: Distribution Ray Tracing pixel sampling •BRDF*cosine distribution computeImage() { for (each pixel (i,j)) { estimatedRadiance[i,j] = 0 p(Ψ) = fr(...).cosθΨ for (s = 1 to #samples-in-pixel) { 1 N generate