Computer graphics III – Monte Carlo integration II Jaroslav Křivánek, MFF UK

Slides:



Advertisements
Similar presentations
Monte Carlo Methods and Statistical Physics
Advertisements

Kartic Subr, Derek Nowrouzezahrai, Wojciech Jarosz, Jan Kautz and Kenny Mitchell Disney Research, University of Montreal, University College London.
Photorealistic Rendering. Ray tracing v. photorealistic rendering What illumination effects are not captured by ray tracing? What illumination effects.
Rendering with Environment Maps Jaroslav Křivánek, KSVI, MFF UK
Sampling Attila Gyulassy Image Synthesis. Overview Problem Statement Random Number Generators Quasi-Random Number Generation Uniform sampling of Disks,
Monte Carlo Integration Robert Lin April 20, 2004.
Advanced Computer Graphics (Spring 2005) COMS 4162, Lectures 18, 19: Monte Carlo Integration Ravi Ramamoorthi Acknowledgements.
Photon Tracing with Arbitrary Materials Patrick Yau.
Advanced Computer Graphics (Fall 2009) CS 294, Rendering Lecture 5: Monte Carlo Path Tracing Ravi Ramamoorthi
Advanced Computer Graphics (Fall 2010) CS 283, Lecture 10: Global Illumination Ravi Ramamoorthi Some images courtesy.
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
Monte Carlo Integration COS 323 Acknowledgment: Tom Funkhouser.
Rendering General BSDFs and BSSDFs Randy Rauwendaal.
Advanced Computer Graphics (Spring 2006) COMS 4162, Lecture 20: Monte Carlo Path Tracing Ravi Ramamoorthi Acknowledgements.
1 Monte Carlo Global Illumination Brandon Lloyd COMP 238 December 16, 2002.
Paper by Alexander Keller
1 Stratified sampling This method involves reducing variance by forcing more order onto the random number stream used as input As the simplest example,
Computer Graphics (Spring 2008) COMS 4160, Lecture 22: Global Illumination
Lecture II-2: Probability Review
Monte Carlo Integration Digital Image Synthesis Yung-Yu Chuang with slides by Pat Hanrahan and Torsten Moller.
Photo-realistic Rendering and Global Illumination in Computer Graphics Spring 2012 Stochastic Radiosity K. H. Ko School of Mechatronics Gwangju Institute.
Mathematics for Computer Graphics (Appendix A) Won-Ki Jeong.
01/24/05© 2005 University of Wisconsin Last Time Raytracing and PBRT Structure Radiometric quantities.
Random-walk solution of the global illumination problem László Szirmay-Kalos.
1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing.
-Global Illumination Techniques
Monte Carlo I Previous lecture Analytical illumination formula This lecture Numerical evaluation of illumination Review random variables and probability.
Module 1: Statistical Issues in Micro simulation Paul Sousa.
1 Lesson 8: Basic Monte Carlo integration We begin the 2 nd phase of our course: Study of general mathematics of MC We begin the 2 nd phase of our course:
Monte Carlo Methods.
02/10/03© 2003 University of Wisconsin Last Time Participating Media Assignment 2 –A solution program now exists, so you can preview what your solution.
Monte Carlo Methods So far we have discussed Monte Carlo methods based on a uniform distribution of random numbers on the interval [0,1] p(x) = 1 0  x.
Photo-realistic Rendering and Global Illumination in Computer Graphics Spring 2012 Stochastic Path Tracing Algorithms K. H. Ko School of Mechatronics Gwangju.
Importance Resampling for Global Illumination Justin Talbot, David Cline, and Parris Egbert Brigham Young University Provo, UT.
Stats Probability Theory Summary. The sample Space, S The sample space, S, for a random phenomena is the set of all possible outcomes.
Photo-realistic Rendering and Global Illumination in Computer Graphics Spring 2012 Material Representation K. H. Ko School of Mechatronics Gwangju Institute.
02/12/03© 2003 University of Wisconsin Last Time Intro to Monte-Carlo methods Probability.
Computer Graphics III – Monte Carlo integration Direct illumination
Photo-realistic Rendering and Global Illumination in Computer Graphics Spring 2012 Stochastic Path Tracing Algorithms K. H. Ko School of Mechatronics Gwangju.
Monte Carlo Path Tracing
Gil McVean, Department of Statistics Thursday February 12 th 2009 Monte Carlo simulation.
Instructor: Mircea Nicolescu Lecture 5 CS 485 / 685 Computer Vision.
01/26/05© 2005 University of Wisconsin Last Time Raytracing and PBRT Structure Radiometric quantities.
Global Illumination (3) Path Tracing. Overview Light Transport Notation Path Tracing Photon Mapping.
02/9/05© 2005 University of Wisconsin Last Time Lights Next assignment – Implement Kubelka-Munk as a BSDF.
Computer graphics III – Low-discrepancy sequences and quasi-Monte Carlo methods Jaroslav Křivánek, MFF UK
Computer graphics III – Multiple Importance Sampling Jaroslav Křivánek, MFF UK
Monte Carlo Integration Digital Image Synthesis Yung-Yu Chuang 12/3/2008 with slides by Pat Hanrahan and Torsten Moller.
Computer graphics III – Rendering equation and its solution
Generating Random Variates
Computer graphics III – Path tracing Jaroslav Křivánek, MFF UK
Advanced Computer Graphics
Lesson 8: Basic Monte Carlo integration
Introduction to Monte Carlo Method
Image-based Lighting Computational Photography
Sampling and Reconstruction of Visual Appearance
Path Tracing (some material from University of Wisconsin)
Homework #3 Environment Lights
Lecture 2 – Monte Carlo method in finance
Computer Graphics III Monte Carlo estimators – Exercises
(c) 2002 University of Wisconsin
Monte Carlo I Previous lecture Analytical illumination formula
Monte Carlo Rendering Central theme is sampling:
Foundations of Computer Graphics (Spring 2012)
Statistical Methods for Data Analysis Random number generators
Computer graphics III – Path tracing
Jaroslav Křivánek, MFF UK
Lesson 4: Application to transport distributions
Computer Graphics III Winter Term 2016 Organization
Monte Carlo Integration
Presentation transcript:

Computer graphics III – Monte Carlo integration II Jaroslav Křivánek, MFF UK

Monte Carlo integration General tool for estimating definite integrals 11 f(x)f(x) 01 p(x)p(x) 22 33 44 55 66 Integral: Monte Carlo estimate I: Works “on average”: CG III (NPGR010) - J. Křivánek

Generating samples from a distribution

Generating samples from a 1D discrete random variable Given a probability mass function p(i), and the corresponding cdf P(i) Procedure 1. Generate u from Uniform(0,1) 2. Choose x i for which (we define P(0) = 0 ) The search is usually implemented by interval bisection CG III (NPGR010) - J. Křivánek CDF

Generating samples from a 2D discrete random variable Given a probability mass function p I,J (i, j) Option 1:  Interpret the 2D PMF as a 1D vector of probabilities  Generate samples as in the 1D case CG III (NPGR010) - J. Křivánek

Generating samples from a 2D discrete random variable CG III (NPGR010) - J. Křivánek

Generating samples from a 2D discrete random variable Option 2 (better) 1. “Column” i sel is sampled from the marginal distribution, given by a 1D marginal pmf 2. “Row” j sel is sampled from the conditional distribution corresponding to the “column” i sel CG III (NPGR010) - J. Křivánek

Generating samples from a 1D continuous random variable Option 1: Transformation method Option 2: Rejection sampling CG III (NPGR010) - J. Křivánek

Transformation method Consider the random variable U from the uniform distribution Uniform(0,1). Then the random variable X has the distribution given by the cdf P. To generate samples according to a given pdf p, we need to:  calculate the cdf P(x) from the pdf p(x)  calculate the inverse cdf P -1 (u) 9 CG III (NPGR010) - J. Křivánek 2015

p(x)p(x) a 0 MAX b Rejection sampling in 1D Algorithm  Choose random u 1 from Uniform R(a, b)  Choose random u 2 from Uniform R(0, MAX)  Accept the sample only if p(u 1 ) > u 2  Repeat until a sample is accepted The accepted samples have the distribution given by the pdf p(x) Efficiency = % of accepted samples  Area under the pdf graph / area of the bounding rectangle CG III (NPGR010) - J. Křivánek

Transformation method vs. Rejection sampling Transformation method Pros Almost always more efficient than rejection sampling (unless the transformation formula x = P -1 (u) turns our extremely complex) Has a constant time complexity and the random number count is known upfront Transformation method Cons May not be feasible (we may not be able to find the suitable form for x = P -1 (u)), but rejection sampling is always applicable as long as we can evaluate the pdf (i.e. rejection sampling is more general) Smart rejection sampling can be very efficient (e.g. the Ziggurat method, see Wikipedia) CG III (NPGR010) - J. Křivánek

Sampling from a 2D continuous random variable Conceptually similar to the 2D discrete case Procedure  Given the joint density p X,Y (x, y) = p X (x) p Y|X (y | x) 1. Choose x sel from the marginal pdf 2. Choose y sel from the conditional pdf CG III (NPGR010) - J. Křivánek

Transformation formulas for common cases in light transport P. Dutré: Global Illumination Compendium, CG III (NPGR010) - J. Křivánek

Importance sampling from the physically-plausible Phong BRDF Ray hits a surface with a Phong BRDF. How do we generate the ray for continuing the light path? Procedure 1. Choose the BRDF component (diffuse reflection, specular reflection, refraction) 2. Sample the chosen component 3. Evaluate the total PDF and BRDF 14 CG III (NPGR010) - J. Křivánek 2015

Physically-plausible Phong BRDF Where Energy conservation: 15 CG III (NPGR010) - J. Křivánek 2015

Selection of the BRDF component pd = max(rhoD.r, rhoD.g, rhoD.b); ps = max(rhoS.r, rhoS.g, rhoS.b); pd /= (pd + ps); // prob of choosing the diffuse component ps /= (pd + ps); // prob of choosing the specular comp. if (rand(0,1) <= pd) genDir = sampleDiffuse(); else genDir = sampleSpecular(incDir); pdf = evalPdf(incDir, genDir, pd, ps); 16 CG III (NPGR010) - J. Křivánek 2015

Sampling of the diffuse reflection Importance sampling with the density p(  ) = cos(  ) /    …angle between the surface normal and the generated ray  Generating the direction: r1, r2 … uniform random variates on <0,1)  Reference: Dutre, Global illumination Compendium (on- line)  Derivation: Pharr & Huphreys, PBRT 17 CG III (NPGR010) - J. Křivánek 2015

sampleDiffuse() // generate spherical coordinates of the direction float r1 = rand(0,1), r2 = rand(0,1); float sinTheta = sqrt(1 – r2); float cosTheta = sqrt(r2); float phi = 2.0*PI*r1; float pdf = cosTheta/PI; // convert [theta, phi] to Cartesian coordinates Vec3 dir (cos(phi)*sinTheta, sin(phi)*sinTheta, cosTheta); return dir; 18 CG III (NPGR010) - J. Křivánek 2015

Sampling of the glossy (specular) reflection Importance sampling with the pdf p(  ) = (n+1)/(2  ) cos n (  )   …angle between the ideal mirror reflection of  o and the generated ray  Formulas for generating the direction: r1, r2 … uniform random variates on <0,1) 19 CG III (NPGR010) - J. Křivánek 2015

sampleSpecular() // build a local coordinate frame with R = z-axis Vec3 R = 2*dot(N,incDir)*N – incDir; // ideal reflected direction Vec3 U = arbitraryNormal(R); // U is perpendicular to R Vec3 V = crossProd(R, U); // orthonormal basis with R and U // generate direction in local coordinate frame Vec3 locDir = rndHemiCosN(n); // formulas form prev. slide, n=phong exp. // transform locDir to global coordinate frame Vec3 dir = locDir.x * U + locDir.y * V + locDir.z * R; return dir; 20 CG III (NPGR010) - J. Křivánek 2015

evalPdf(incDir, genDir, pd, ps) CG III (NPGR010) - J. Křivánek return pd * getDiffusePdf(genDir) + ps * getSpecularPdf(incdir, genDir); formulas from prev. slides

Variance reduction methods for MC estimators

Variance reduction methods Importance sampling  The most commonly used method in light transport (most often we use BRDF-proportional importance sampling) Control variates Improved sample distribution  Stratification  quasi-Monte Carlo (QMC) CG III (NPGR010) - J. Křivánek

Importance sampling X1X1 f(x) 01 p(x) X2X2 X3X3 X4X4 X5X5 X6X6 CG III (NPGR010) - J. Křivánek

Importance sampling Parts of the integration domain with high value of the integrand f are more important  Samples from these areas have higher impact on the result Importance sampling places samples preferentially to these areas  I.e. the pdf p is “similar” to the integrand f Decreases variance while keeping unbiasedness CG III (NPGR010) - J. Křivánek

Control variates f(x) 01 0 g(x) f(x)-g(x) CG III (NPGR010) - J. Křivánek

Consider a function g(x), that approximates the integrand and we can integrate it analytically: Numerical integration (MC) Hopefully with less variance than integrating f(x) directly. We can integrate analytically CG III (NPGR010) - J. Křivánek Control variates

Control variates vs. Importance sampling Importance sampling  Advantageous whenever the function, according to which we can generate samples, appears in the integrand as a multiplicative factor (e.g. BRDF in the reflection equation). Control variates  Better if the function that we can integrate analytically appears in the integrand as an additive term. This is why in light transport, we almost always use importance sampling and almost never control variates. CG III (NPGR010) - J. Křivánek

Better sample distribution Generating independent samples often leads to clustering of samples  Results in high estimator variance Better sample distribution => better coverage of the integration domain by samples => lower variance Approaches  Stratified sampling  quasi-Monte Carlo (QMC) CG III (NPGR010) - J. Křivánek

Stratified sampling Sampling domain subdivided into disjoint areas that are sampled independently CG III (NPGR010) - J. Křivánek x2x2 f(x) f(x i ) 01 x1x1 x3x3 x4x4

Subdivision of the sampling domain  into N parts  i : Resulting estimator: Stratified sampling CG III (NPGR010) - J. Křivánek

Stratified sampling Suppresses sample clustering Reduces estimator variance  Variance is provably less than or equal to the variance of a regular secondary estimator Very effective in low dimension  Effectiveness deteriorates for high-dimensional integrands CG III (NPGR010) - J. Křivánek

Uniform subdivision of the interval  Natural approach for a completely unknown integrand f If we know at least roughly the shape of the integrand f, we aim for a subdivision with the lowest possible variance on the sub-domains Subdivision of a d-dimensional interval leads to N d samples  A better approach in high dimension is N-rooks sampling How to subdivide the interval? CG III (NPGR010) - J. Křivánek

Combination of stratified sampling and the transformation method CG III (NPGR010) - J. Křivánek Stratification in the space of random numbers Transformation through the inverse cdf

Quasi-Monte Carlo methods (QMC) Use of strictly deterministic sequences instead of (pseudo-)random numbers Pseudo-random numbers replaced by low-discrepancy sequences Everything works as in regular MC, but the underlying math is different (nothing is random so the math cannot be built on probability theory) CG III (NPGR010) - J. Křivánek

Discrepancy Low Discrepancy (more uniform) High Discrepancy (clusters of points) CG III (NPGR010) - J. Křivánek

Stratified sampling Henrik Wann Jensen 10 paths per pixel CG III (NPGR010) - J. Křivánek

Quasi-Monte Carlo Henrik Wann Jensen 10 paths per pixel CG III (NPGR010) - J. Křivánek

Same random sequence for all pixels Henrik Wann Jensen 10 paths per pixel CG III (NPGR010) - J. Křivánek

Image-based lighting

Introduced by Paul Debevec (Siggraph 98) Routinely used for special effects in films & games 41 Image-based lighting CG III (NPGR010) - J. Křivánek 2015

42 Image-based lighting Eucaliptus grove Grace cathedral Uffizi gallery Illuminating CG objects using measurements of real light (=light probes) © Paul Debevec CG III (NPGR010) - J. Křivánek 2015

43 Point Light Source © Paul Debevec CG III (NPGR010) - J. Křivánek 2015

44 © Paul Debevec CG III (NPGR010) - J. Křivánek 2015

45 © Paul Debevec CG III (NPGR010) - J. Křivánek 2015

46 © Paul Debevec CG III (NPGR010) - J. Křivánek 2015

47 © Paul Debevec CG III (NPGR010) - J. Křivánek 2015

Mapping Eucaliptus grove Grace cathedral Debevec’s spherical“Latitude – longitude” (spherical coordinates) Cube map

“Latitude – longitude” (spherical coordinates) Mapping Uffizi gallery St. Peter’s Cathedral Debevec’s spherical Cube map

Mapping from direction in Cartesian coordinates to image UV. 50 Mapping float d = sqrt(dir.x*dir.x + dir.y*dir.y); float r = d>0 ? *acos(dir.z)/d : 0.0; u = dir.x * r; v = dir.y * r; Quote from “ The following light probe images were created by taking two pictures of a mirrored ball at ninety degrees of separation and assembling the two radiance maps into this registered dataset. The coordinate mapping of these images is such that the center of the image is straight forward, the circumference of the image is straight backwards, and the horizontal line through the center linearly maps azimuthal angle to pixel coordinate. Thus, if we consider the images to be normalized to have coordinates u=[-1,1], v=[-1,1], we have theta=atan2(v,u), phi=pi*sqrt(u*u+v*v). The unit vector pointing in the corresponding direction is obtained by rotating (0,0,-1) by phi degrees around the y (up) axis and then theta degrees around the -z (forward) axis. If for a direction vector in the world (Dx, Dy, Dz), the corresponding (u,v) coordinate in the light probe image is (Dx*r,Dy*r) where r=(1/pi)*acos(Dz)/sqrt(Dx^2 + Dy^2).

Technique (pdf) 1: BRDF importance sampling Generate directions with a pdf proportional to the BRDF Technique (pdf) 2: Environment map importance sampling  Generate directions with a pdf proportional to L(  ) represented by the EM 51 Sampling strategies for image based lighting CG III (NPGR010) - J. Křivánek 2015

Sampling strategies BRDF IS 600 samples EM IS 600 samples MIS samples Diffuse only Ward BRDF,  =0.2 Ward BRDF,  =0.05Ward BRDF,  =0.01

Sampling according to the environment map luminance Luminance of the environment map defines the sampling pdf on the unit sphere For details, see PBRT CG III (NPGR010) - J. Křivánek