MonteCarlo Ray Tracing - PowerPoint PPT Presentation

1 / 81
About This Presentation
Title:

MonteCarlo Ray Tracing

Description:

MonteCarlo Ray Tracing – PowerPoint PPT presentation

Number of Views:155
Avg rating:3.0/5.0
Slides: 82
Provided by: coursesC1
Category:
Tags: montecarlo | kia | ray | rio | tracing

less

Transcript and Presenter's Notes

Title: MonteCarlo Ray Tracing


1
Monte-Carlo Ray Tracing
Image by Henrik
2
Antialiasing integration
  • So far, Antialiasing as signal processing
  • Now, Antialiasing as integration
  • Complementary yet not always the same
  • in particular for jittered sampling

3
Why integration?
  • Simple version compute pixel coverage
  • More advanced Filtering (convolution)is an
    integralpixel s filter color
  • And integration is useful in tons of places in
    graphics

4
Global illumination
  • So far, we've seen only direct lighting (red
    here)
  • We also want indirect lighting
  • Full integral on hemisphere (multiplied by BRDF)
  • In practice, send tons of random rays

5
What else can we integrate?
  • Pixel antialiasing
  • Light sources Soft shadows
  • Lens Depth of field
  • Time Motion blur
  • BRDF glossy reflection
  • Hemisphere indirect lighting

6
Domains of integration
  • Pixel, lens (Euclidean 2D domain)
  • Time (1D)
  • Hemisphere
  • Work needed to ensure uniform probability
  • Light source
  • Same thing make sure that the probabilities and
    the measures are right.

7
Example Light source
  • Integrate over surface or over angle
  • Be careful to get probabilities and integration
    measure right!
  • More in 6.839

Sampling the source uniformly
Sampling the hemisphere uniformly
source
hemisphere
8
A little bit of eye candy for motivation
  • Glossy material rendering
  • Random reflection rays around mirror direction
  • 1 sample per pixel

9
A little bit of eye candy for motivation
  • Glossy material rendering
  • Random reflection rays around mirror direction
  • 256 sample per pixel

10
Error/noise expressed as variance
  • We use random rays
  • Run the algorithm again, ? get different image
  • What is the noise/variance/standard deviation?

11
Goal today
  • Prove that Monte-Carlo integration works
  • Notion of expected value
  • Discuss its convergence speed
  • Error notion of variance
  • For all this, we need to study what happens to
    expected value and variance when we had tons of
    random samples
  • Apply to ray tracing

12
Questions?
  • Image by Henrik

13
Integration
  • compute integral of weird arbitrary function
  • Continuous problem ? we need to discretize

14
Integration
  • You know trapezoid

15
Integration
  • Now come Monte Carlo use random samples and
    compute average
  • We dont keep track of spacing between samples
  • But we kind of hope it will be on average 1/n

16
Monte-Carlo computation of p
  • Take a square
  • Take a random point (x,y) in the square
  • Test if it is inside the ¼ disc (x2y2 lt 1)
  • The probability is p /4

Integral of the function that is one inside the
circle, zero outside
y
x
17
Monte-Carlo computation of p
  • The probability is p /4
  • Count the inside ratio n inside / total
    trials
  • p ? n 4
  • The error depends on the number or trials

Demo
long N_SAMPLES(long)1e9 long nSuccess0
long nTrial0 int pow1 for (long
i0 iltN_SAMPLES i) double
xMath.random() double yMath.random() if
(xxyylt1) nSuccess / if
(nTrialpow0) double myPi4.0(double)nSuc
cess/(double)i System.out.println("n"nTrial
" pi"myPi) pow2 / doubl
e myPi4.0(double)nSuccess/(double)N_SAMPLES S
ystem.out.println(myPi)
18
Why not use Simpson integration?
  • Yeah, to compute p, Monte Carlo is not very
    efficient
  • But convergence is independent of dimension
  • Better to integrate high-dimensional functions
  • For d dimensions, Simpson requires Nd domains

19
Questions?
  • Image from the ARNOLD Renderer by Marcos Fajardo

20
Continuous random variables
  • Real-valued random variable x
  • Probability density function (PDF) p(x)
  • Probability of a value between x and xdx is p(x)
    dx

21
Expected value
  • Expected value is linear
  • Ef1(x) a f2(x) Ef1(x) a Ef2(x)

22
Monte Carlo integration
  • Function f(x) of x 2 a b
  • We want to compute
  • Consider a random variable x
  • If x has uniform distribution, IEf(x)
  • By definition of the expected value

23
Sum of Random Variables
  • Use N independent identically-distributed (IID)
    variables xi
  • Share same probability (uniform here)
  • Define
  • By linearity of the expectationEFN Ef(x)

Monte Carlo estimator
24
Variance
  • Measure of deviation from expected value
  • Expected value of square difference (MSE)
  • Standard deviation s square root of variance
    (notion of error, RMS)

25
Dumbest Monte-Carlo integration
  • Compute 0.5 by flipping a coin
  • 1 flip 0 or 1gt average error 0.5
  • 2 flips 0, 0.5, 0.5 or 1 gtaverage error0. 25
  • 4 flips 0 (1),0.25 (4), 0.5 (6), 0.75(4),
    1(1) gt average error 0.1875
  • Does not converge very fast
  • Doubling the number of samples does not double
    accuracy

26
Study of variance
  • Recall s2xy s2x s2y 2 Covx,y
  • We have independent variables Covxi, xj0 if i
    ? j
  • s2ax a2 s2x
  • i.e. stddev s (error) decreases by

27
Example
  • We know it should be 1.0
  • In practicewith uniform samples

error
s2
- s2
N
28
Monte-Carlo Recap
  • Expected value is the integrand
  • Accurate on average
  • Variance decrease in 1/N
  • Error decreases in
  • Good news
  • Math are mostly over for today
  • OK, its bad news if you like math (and you
    should)

29
Advantages of MC Integration
  • Few restrictions on the integrand
  • Doesnt need to be continuous, smooth, ...
  • Only need to be able to evaluate at a point
  • Extends to high-dimensional problems
  • Same convergence
  • Conceptually straightforward
  • Efficient for solving at just a few points

30
Disadvantages of MC
  • Noisy
  • Slow convergence
  • Good implementation is hard
  • Debugging code
  • Debugging maths
  • Choosing appropriate techniques

31
Questions?
  • Images by Veach and Guibas

Naïve sampling strategy
Optimal sampling strategy
32
Smarter sampling
  • Sample a non-uniform probability
  • Called importance sampling
  • how to get probabilities right?

33
Example Glossy rendering
  • Integrate over hemisphere
  • BRDF times cosine times incoming light

Slide courtesy of Jason Lawrence
34
Sampling a BRDF
Slide courtesy of Jason Lawrence
35
Sampling a BRDF
25 Samples/Pixel
Slide courtesy of Jason Lawrence
36
Sampling a BRDF
75 Samples/Pixel
Slide courtesy of Jason Lawrence
37
Questions?
1200 Samples/Pixel
Traditional importance function
Better importance by Lawrence et al.
38
Stratified sampling
  • With uniform sampling, we can get unlucky
  • E.g. all samples in a corner
  • To prevent it, subdivide domain W into
    non-overlapping regions Wi
  • Each region is called a stratum
  • Take one random samples per Wi

39
Example
  • Borrowed from Henrik Wann Jensen

Unstratified
Stratified
40
Stratified sampling - bottomline
  • Cheap and effective
  • Mostly for low-dimensional domains
  • Typical example jittering for antialiasing
  • Signal processing perspective better than
    uniform because less aliasing (spatial patterns)
  • Monte-Carlo perspective better than random
    because lower variance (error for a given pixel)

41
Questions?
  • Image from the ARNOLD Renderer by Marcos Fajardo

42
Global illumination
  • e.g. indirect lighting bouncing off the walls

43
The Rendering Equation
x
?'
Kajiya 1986
?
x'
L(x',?') E(x',?') ??x'(?,?')L(x,?)G(x,x')V(x,x
') dA
Incominglight
Geometricterm
visibility
emission
BRDF
44
Ray Casting
  • Cast a ray from the eye through each pixel

45
Ray Tracing
  • Cast a ray from the eye through each pixel
  • Trace secondary rays (light, reflection,
    refraction)

46
Monte-Carlo Ray Tracing
  • Cast a ray from the eye through each pixel
  • Cast random rays from the visible point
  • Accumulate radiance contribution

47
Monte-Carlo Ray Tracing
  • Cast a ray from the eye through each pixel
  • Cast random rays from the visible point
  • Recurse

48
Monte-Carlo
  • Cast a ray from the eye through each pixel
  • Cast random rays from the visible point
  • Recurse

49
Monte-Carlo
  • Systematically sample primary light

50
Results
51
Monte Carlo Path Tracing
  • Trace only one secondary ray per recursion
  • But send many primary rays per pixel
  • (performs antialiasing as well)

52
Results
Think about it we compute an infinite-dimension
al integral with 10 samples!!!
  • 10 paths/pixel

53
Results glossy
  • 10 paths/pixel

54
Results glossy
  • 100 paths/pixel

55
Importance of sampling the light
Without explicit light sampling
With explicit light sampling
1 path per pixel
4 path per pixel
56
Why use random numbers?
  • Fixed random sequence
  • We see the structure in the error

57
Questions?
  • Vintage path tracing by Kajyia

58
Questions?
59
Path Tracing is costly
  • Needs tons of rays per pixel

60
Direct illumination
61
Global Illumination
62
Indirect illumination smooth
63
Irradiance cache
  • The indirect illumination is smooth

64
Irradiance cache
  • The indirect illumination is smooth

65
Irradiance cache
  • The indirect illumination is smooth
  • Interpolate nearby values

66
Irradiance cache
  • Store the indirect illumination
  • Interpolate existing cached values
  • But do full calculation for direct lighting

67
Irradiance caching
  • Yellow dots computation of indirect diffuse
    contribution

68
Radiance software by Greg Ward
  • The inventor of irradiance caching
  • http//radsite.lbl.gov/radiance/

69
Photon mapping
  • Preprocess cast rays from light sources
  • Store photons

70
Photon mapping
  • Preprocess cast rays from light sources
  • Store photons (position light power incoming
    direction)

71
Photon map
  • Efficiently store photons for fast access
  • Use hierarchical spatial structure (kd-tree)

72
Photon mapping - rendering
  • Cast primary rays
  • For secondary rays
  • reconstruct irradiance using adjacent stored
    photon
  • Take the k closest photons
  • Combine with irradiance caching and a number of
    other techniques

73
Photon map results
74
Photon mapping - caustics
  • Special photon map for specular reflection and
    refraction

Glass sphere
75
  • 1000 paths/pixel

76
  • Photon mapping

77
Photon mapping
  • Animation by Henrik Wann Jensen

78
Questions?
  • Image by Henrik

79
References
  • 6.839!
  • Eric Veachs PhD dissertationhttp//graphics.stan
    ford.edu/papers/veach_thesis/
  • Physically Based Rendering by Matt Pharr, Greg
    Humphreys

80
References
81
Questions?
Write a Comment
User Comments (0)
About PowerShow.com