rendering monte carlo integration ii
play

Rendering: Monte Carlo Integration II Bernhard Kerbl Research - PowerPoint PPT Presentation

Rendering: Monte Carlo Integration II Bernhard Kerbl Research Division of Computer Graphics Institute of Visual Computing & Human-Centered Technology TU Wien, Austria With slides based on material by Jaakko Lehtinen, used with


  1. เถฑ Rendering: Monte Carlo Integration II Bernhard Kerbl Research Division of Computer Graphics Institute of Visual Computing & Human-Centered Technology TU Wien, Austria With slides based on material by Jaakko Lehtinen, used with permission

  2. Todayโ€™s Goal Integrating the cosine-weighted radiance ๐‘€ ๐‘— (๐‘ฆ, ๐œ•) at a point ๐‘ฆ Integral of the light function over the hemisphere, w.r.t. direction/solid angle at ๐œ• Letโ€™s find a solution! How do we integrate over the hemisphere? How do we do it smartly ? Rendering โ€“ Monte Carlo Integration I 2

  3. Sampling a Unit Disk Imagine we have a disk-shaped surface with radius ๐‘  = 1 that registers incoming light (color) from directional light sources As an exercise, we want to approximate the total incoming light over the diskโ€™s surface area r = 1 2 We integrate over an area of size ๐œŒ We will use the Monte Carlo integral for that 2 Rendering โ€“ Monte Carlo Integration II 3

  4. Uniformly Sampling the Unit Disk If we can manage to uniformly sample the disk, then we can compute the Monte Carlo integral as a simple average ร— ๐œŒ By drawing uniform samples in ๐‘ฆ and ๐‘ง , we cannot cover the area precisely Inscribed square: information lost Circumscribed square: unnecessary samples Rendering โ€“ Monte Carlo Integration II 4

  5. Uniformly Sampling the Unit Disk If we can manage to uniformly sample the disk, then we can compute the Monte Carlo integral as a simple average By drawing uniform samples in ๐‘ฆ and ๐‘ง , we cannot cover the area precisely Inscribed square: information lost Circumscribed square: unnecessary samples Rendering โ€“ Monte Carlo Integration II 5

  6. Uniformly Sampling the Unit Disk If we can manage to uniformly sample the disk, then we can compute the Monte Carlo integral as a simple average By drawing uniform samples in ๐‘ฆ and ๐‘ง , we cannot cover the area precisely Inscribed square: information lost Circumscribed square: unnecessary samples Rendering โ€“ Monte Carlo Integration II 6

  7. Uniformly Sampling the Unit Disk If we can manage to uniformly sample the disk, then we can compute the Monte Carlo integral as a simple average By drawing uniform samples in ๐‘ฆ and ๐‘ง , we cannot cover the area precisely Inscribed square: information lost Circumscribed square: unnecessary samples This is actually somewhat ok! Rendering โ€“ Monte Carlo Integration II 7

  8. Rejection Sampling Requires a PDF ๐‘ž ๐‘Œ (๐‘ฆ) and a constant ๐‘‘ such that ๐‘” ๐‘ฆ < ๐‘‘๐‘ž ๐‘Œ (๐‘ฆ) Draw ๐œŠ ๐‘— and ๐‘Œ ๐‘— from their respective distributions. If the point (๐‘Œ ๐‘— , ๐œŠ ๐‘— ๐‘‘๐‘ž ๐‘Œ ๐‘Œ ๐‘— ) lies under ๐‘” ๐‘ฆ , then the sample is accepted loop forever: sample ๐‘Œ from ๐‘ž ๐‘Œ โ€™s distribution if ๐œŠ ๐‘— โ‹… ๐‘‘๐‘ž ๐‘Œ ๐‘Œ ๐‘— < ๐‘” ๐‘Œ ๐‘— then return ๐‘Œ ๐‘— Rendering โ€“ Monte Carlo Integration II 8

  9. Rejection Sampling Requires a PDF ๐‘ž ๐‘Œ (๐‘ฆ) and a constant ๐‘‘ such that ๐‘” ๐‘ฆ < ๐‘‘๐‘ž ๐‘Œ (๐‘ฆ) Draw ๐œŠ ๐‘— and ๐‘Œ ๐‘— from their respective distributions. If the point (๐‘Œ ๐‘— , ๐œŠ ๐‘— ๐‘‘๐‘ž ๐‘Œ ๐‘Œ ๐‘— ) lies under ๐‘” ๐‘ฆ , then the sample is accepted loop forever: sample ๐‘Œ from ๐‘ž ๐‘Œ โ€™s distribution if ๐œŠ ๐‘— โ‹… ๐‘‘๐‘ž ๐‘Œ ๐‘Œ ๐‘— < ๐‘” ๐‘Œ ๐‘— then return ๐‘Œ ๐‘— ๐‘—๐‘” ( ๐‘ฆ 2 + ๐‘ง 2 โ‰ค 1) Unit disk: ๐‘” ๐‘ฆ, ๐‘ง = เต1 , ๐‘ž ๐‘ฆ, ๐‘ง = 1 4 , ๐‘‘ = 4 0 ๐‘๐‘ขโ„Ž๐‘“๐‘ ๐‘ฅ๐‘—๐‘ก๐‘“ Rendering โ€“ Monte Carlo Integration II 9

  10. Back to the Unit Disk We do not want to waste samples if we can avoid it Instead, find a way to generate uniform samples on the disk Second attempt: draw from 2D polar coordinates Polar coordinates defined by radius ๐‘  โˆˆ [0,1) and angle ๐œ„ โˆˆ [0,2๐œŒ) Transformation to cartesian coordinates: ๐‘ฆ = ๐‘  sin ๐œ„ y = ๐‘  cos ๐œ„ Rendering โ€“ Monte Carlo Integration II 10

  11. Uniformly Sampling the Unit Disk? Convert two ๐œŠ to ranges 0, 1 , [0,2๐œŒ) for polar coordinates Convert to cartesian coordinates void sampleUnitDisk() { std::default_random_engine r_rand_eng(0xdecaf); std::default_random_engine theta_rand_eng(0xcaffe); std::uniform_real_distribution<double> uniform_dist(0.0, 1.0); for (int i = 0; i < NUM_SAMPLES; i++) { auto r = uniform_dist(r_rand_eng); auto theta = uniform_dist(theta_rand_eng) * 2 * M_PI; auto x = r * sin(theta); auto y = r * cos(theta); samples2D[i] = std::make_pair(x, y); } } Rendering โ€“ Monte Carlo Integration II 11

  12. Clumping We successfully sampled the unit disk in the proper range 1 However, the distribution is not uniform with respect to the area 0,5 0 Samples clump together at center -0,5 Averaging those samples will give us a skewed result for the integral! -1 -1 -0,5 0 0,5 1 Rendering โ€“ Monte Carlo Integration II 12

  13. Uniformly Sampling the Unit Disk: A Solution The area of a disk is proportional to ๐‘  2 , times a constant factor ๐œŒ If we see the disk as concentric rings of width ฮ”๐‘  , the ๐‘˜ inner rings 2 ๐‘  ๐‘˜ up to radius ๐‘  ๐‘˜ = ๐‘˜ฮ”๐‘  should contain ๐‘‚ out of ๐‘‚ total samples ๐‘  ๐‘— Conversely, the ๐‘— ๐‘ขโ„Ž sample should lie in the ring at radius ๐‘  ๐‘— = ๐‘  ๐‘‚ Since ๐œŠ is uniform in [0, 1) , we can switch ๐‘˜ ๐‘‚ for ๐œŠ to get ๐‘  ๐‘— = ๐‘  ๐œŠ ๐‘— Rendering โ€“ Monte Carlo Integration II 13

  14. Uniformly Sampling the Unit Disk: A Solution 1 It works, and it is not even a bad way to arrive at the correct solution 0,5 0 -0,5 However, for more complex scenarios, we -1 might struggle to find the solution so easily -1 -0,5 0 0,5 1 1 With the tools we introduced earlier, we can 0,5 formalize this process for arbitrary setups 0 -0,5 -1 -1 -0,5 0 0,5 1 Rendering โ€“ Monte Carlo Integration II 14

  15. Polar To Cartesian Coordinates Letโ€™s transform a regular grid from polar to cartesian coordinates ๐œ„ ๐‘  ๐‘Œ = ๐‘  cos(๐œ„), ๐‘ = ๐‘  sin(๐œ„) Rendering โ€“ Monte Carlo Integration II 15

  16. First Attempt to Learn the PDF Take 100k samples, transform and see which box they end up in ฮพ 1 , ฮพ 2 ๐‘Œ = ๐œŠ 1 cos(2๐œŒ๐œŠ 2 ), ๐‘ = ๐œŠ 1 sin(2๐œŒ๐œŠ 2 ) Rendering โ€“ Monte Carlo Integration II 16

  17. Knowing the PDF If we know the effect of a transformation ๐‘ˆ on the PDF, we can Use it in the Monte Carlo integral to weight our samples, or Compensate to get a uniform sampling method after transformation ๐ฝ๐‘œ๐‘ž๐‘ฃ๐‘ข (๐œŠ 1 , ๐œŠ 2 ) ๐ท๐‘๐‘ ๐‘ข๐‘“๐‘ก๐‘—๐‘๐‘œ (๐‘ฆ, ๐‘ง) ๐‘„๐‘๐‘š๐‘๐‘  (r, ๐œ„) ๐‘ˆ(๐‘ , ๐œ„) Rendering โ€“ Monte Carlo Integration II 17

  18. Computing the PDF after a Transformation Assume a random variable ๐ต and a bijective transformation ๐‘ˆ that yields another variable ๐ถ = ๐‘ˆ ๐ต Bijectivity dictates that ๐‘ = ๐‘ˆ(๐‘) must be either monotonically increasing or decreasing with ๐‘ This implies that there is a unique ๐ถ i for every ๐ต i , and vice versa In this case, the CDFs for the two variables fulfill ๐‘„ ๐ถ ๐‘ˆ(๐‘) = ๐‘„ ๐ต (๐‘) Rendering โ€“ Monte Carlo Integration II 18

  19. Computing the PDF after a Transformation ๐‘’๐‘„ ๐ถ (๐‘) = ๐‘’๐‘„ ๐ต (๐‘) If ๐‘ = ๐‘ˆ(๐‘) and ๐‘ increases with ๐‘ , we have: ๐‘’๐‘ ๐‘’๐‘ ๐‘’๐‘„ ๐ถ (๐‘) = ๐‘’๐‘„ ๐ต (๐‘) If ๐‘ decreases with ๐‘ (e.g. ๐‘ = โˆ’๐‘) , we have: โˆ’ ๐‘’๐‘ ๐‘’๐‘ Since ๐‘ž ๐ถ is the non-negative derivative of ๐‘„ ๐ถ , we can rewrite as: ๐‘’๐‘ ๐‘ž ๐ถ ๐‘ ๐‘’๐‘ = ๐‘ž ๐ต ๐‘ , ๐‘‰๐‘ก๐‘—๐‘œ๐‘•: ๐‘’๐‘„ ๐‘Œ ๐‘ฆ = ๐‘ž ๐‘Œ ๐‘ฆ ๐‘’๐‘ฆ ๐‘’๐‘ง ๐‘’๐‘ง โˆ’1 ๐‘ž ๐ถ ๐‘ = ๐‘’๐‘ ๐‘ž ๐ต ๐‘ ๐‘’๐‘ Rendering โ€“ Monte Carlo Integration II 19

  20. Computing the PDF after a Transformation โˆ’1 ๐‘’๐‘ Letโ€™s interpret ๐‘ž ๐ถ ๐‘ = ๐‘ž ๐ต ๐‘ ๐‘’๐‘ โˆ’1 ๐‘’๐‘ It is the probability density of ๐ต , multiplied by ๐‘’๐‘ โˆ’1 ๐‘’๐‘ has two intuitive interpretations: ๐‘’๐‘ the change in sampling density at point ๐‘ if we transform ๐‘ by ๐‘ˆ or , the inverse change in the volume of an infinitesimal hypercube at point ๐‘ if we transform ๐‘ by ๐‘ˆ Rendering โ€“ Monte Carlo Integration II 20

  21. Multidimensional Transformations If we try to apply the above to the unit disk, we fail at ๐‘ฆ = ๐‘  sin ๐œ„ โˆ’1 ๐‘’๐‘ฆ We canโ€™t evaluate : the transformation that produces one ๐‘’๐‘  target variable is dependent on both input variables and vice-versa We cannot compute the change in the PDF between individual variables, we must take them all into account simultaneously Itโ€™s matrix time Rendering โ€“ Monte Carlo Integration II 21

  22. Multidimensional Transformations We write the set of ๐‘‚ values from a multidimensional variable ิฆ ๐ต as a vector ิฆ ๐‘ and the ๐‘‚ outputs of transformation ๐‘ˆ as a vector ๐‘ : ๐‘ 1 ๐‘ 1 ๐‘ˆ 1 ( ิฆ ๐‘) โ‹ฎ โ‹ฎ ๐‘ = ิฆ , ๐‘ = = โ‹ฎ = ๐‘ˆ( ิฆ ๐‘) ๐‘ ๐‘‚ ๐‘ ๐‘‚ ๐‘ˆ ๐‘‚ ( ิฆ ๐‘) Instead of quantifying the change in volume incurred by ๐‘ˆ ๐‘ , ๐‘’๐‘ˆ ๐‘ , our goal is now to quantify the change incurred by ๐‘ˆ ิฆ ๐‘ ๐‘’๐‘ Rendering โ€“ Monte Carlo Integration II 22

Recommend


More recommend