0% found this document useful (0 votes)
12 views

Graphics2 04 Stochasticraytracing

Stochastic raytracing is a technique for approximating light transport towards a sensor using Monte Carlo integration. Rays are traced from light sources and the sensor to compute radiance contributions. At each intersection point, the radiance integral is evaluated to determine the propagated radiance. The radiance is accumulated at the sensor from multiple bounces to approximate the rendering equation and solve for the unknown radiance function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Graphics2 04 Stochasticraytracing

Stochastic raytracing is a technique for approximating light transport towards a sensor using Monte Carlo integration. Rays are traced from light sources and the sensor to compute radiance contributions. At each intersection point, the radiance integral is evaluated to determine the propagated radiance. The radiance is accumulated at the sensor from multiple bounces to approximate the rendering equation and solve for the unknown radiance function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Advanced Computer Graphics

Stochastic Raytracing 1
Matthias Teschner
From Radiosity to Raytracing
− Radiosity equation governs light transport
for diffuse surfaces.  How to describe
light transport for general surfaces?
− How to solve for the light transport?
− How to compute the relevant part of
the light transport towards a sensor?

University of Freiburg – Computer Science Department – 2



Stochastic Raytracing
− Light transport towards the sensor requires to solve

− Monte Carlo integration approximates


the reflectance integral
− E.g.,
− Trace rays into the scene
− Compute radiance along this ray
− Associate an area / solid angle with each ray
− Accumulate all contributions
University of Freiburg – Computer Science Department – 3

Outline
− Diffuse vs. general global illumination
− Monte Carlo integration
− Sampling of random variables

◼University of Freiburg – Computer Science Department – 4


Governing Equations
− Rendering equation
− Governing equation for general global illumination methods

− Radiosity equation
− Governing equation for diffuse global illumination methods

University of Freiburg – Computer Science Department – 5



A Solution Strategy - Radiosity
− Finite Element Method
− Start with a continuous form / function

− Discretization

− Solving for a vector with unknown radiosities

◼University of Freiburg – Computer Science Department – 6


An Alternative Strategy
− Start with the general form of the rendering equation,
e.g. in hemispherical form

− Solving for a function of unknown radiances


− I.e., radiance at all surface positions into all directions

◼University of Freiburg – Computer Science Department – 7


Operator Form of the Rendering Equation
we use operators to shorten the notations

− Operators transform a function into another one


− Scattering operator

− Applied to an incident radiance function , exitant


radiance after one bounce / scattering step is returned

− operates on an entire function, i.e. on all incident


radiances for all positions and direction
See, e.g.: Eric Veach: Robust Monte Carlo Methods for Light
Transport Simulation, Ph.D. thesis, Stanford University, 1997.
◼University of Freiburg – Computer Science Department – 8
Operator Form of the Rendering Equation

− Propagation operator
p’ indicates the raycast operator applied to p

− Applied to an exitant radiance function ,


incident radiance at from direction is returned

− Radiance is preserved / propagated along the line


between and if flux from p to p prime is preserved then flux is preserved in opposite direction also.

− and can be reversed, i.e.


See, e.g.: Eric Veach: Robust Monte Carlo Methods for Light
Transport Simulation, Ph.D. thesis, Stanford University, 1997.
University of Freiburg – Computer Science Department – 9

Operator Form of the Rendering Equation

− Light transport operator

− Composition of scattering and propagation


− Maps an exitant radiance function to the exitant
radiance function after one scattering step
− Remember: maps exitant radiance to incident radiance
propagated along a direction. Then, maps incident
radiance to exitant radiance after scattering

See, e.g.: Eric Veach: Robust Monte Carlo Methods for Light Transport Simulation, Ph.D. dissertation, Stanford University, 1997.

◼University of Freiburg – Computer Science Department – 10


Operator Form of the Rendering Equation

− Can be written as

− Light transport equation


Infinite number of equations with an infinite number of unknown exitant radiances

− relates exitant radiance functions Le adds flux to a scene but T removes flux from a scene

− Represents the light propagation equilibrium

University of Freiburg – Computer Science Department – 11



Light Transport Equation

− Solving for the unknown radiance function

− Neumann series

◼University of Freiburg – Computer Science Department – 12


Light Transport Equation
− Discussion
− Radiance function is a sum of
− Emitted radiance
− Emitted radiance after one scattering
− Emitted radiance after two scatterings
− …

◼University of Freiburg – Computer Science Department – 13


Terms in the Neumann Series
− Example contributions to terms

◼University of Freiburg – Computer Science Department – 14


Forward Raytracing
− Send rays / propagate radiance from all light source
positions into all directions 
− At all intersection points , solve the integral
consider all seen points

for all direction  we will stop the computation when all the sensor or camera elements
are hit by a ray

− Trace rays to propagate


− At all intersection points , solve the integral

for all direction


this is nothing but T Le


◼University of Freiburg – Computer Science Department – 15
Forward Raytracing
− At a sensor: Accumulate radiance contributions of rays
after n scattering steps, i.e. compute
Light source

accumulating
the radiance
elements

sensor elemnt x receives the


light transport contributions
from a small angle

Sensor
Exemplary rays

◼University of Freiburg – Computer Science Department – 16


Operator Form of the Rendering Equation

− Can be written as

− Light transport equation


Infinite number of equations with an infinite number of unknown exitant radiances

− relates exitant radiance functions


− Represents the light propagation equilibrium

University of Freiburg – Computer Science Department – 17



Light Transport Equation

− Solving for the unknown radiance function

− Neumann series

◼University of Freiburg – Computer Science Department – 18


Light Transport Equation
− Discussion
− Radiance function is a sum of
− Emitted radiance
− Emitted radiance after one scattering
− Emitted radiance after two scatterings
− …

◼University of Freiburg – Computer Science Department – 19


Backward Raytracing
− Consider rays from the sensor into the scene
− Propagate radiance from visible light sources
−  part of visible to the sensor
− At intersection points with the scene, compute
radiance
that is propagated in direction towards the sensor
−  part of visible to the sensor
−…
University of Freiburg – Computer Science Department – 20

Backward Raytracing
− Trace rays from the sensor into the scene

Light source

Sensor
Exemplary rays

◼University of Freiburg – Computer Science Department – 21


Setting at Sensor

Scene
Sensor
Light
source

− How to compute and what is its


the relation to ?
University of Freiburg – Computer Science Department – 22

Setting at First-Level Intersections

this domain splitting is called stratification


light source + scene

− is the part
of visible to the sensor
− Computation of
requires towards
sensor

University of Freiburg – Computer Science Department – 23



Setting at Second-Level Intersections

− is the part of
visible to the sensor
− Computation of
requires towards
p1

University of Freiburg – Computer Science Department – 24



Summary
− Recursive evaluation of

− Each recursion level computes parts of the functions


that are visible to the sensor

University of Freiburg – Computer Science Department – 25



Numerical Integration
− The integral is approximately computed
with a sum of samples
− For each sample i,
− A ray is cast into the scene
− Intersection with the scene is computed
− Radiance along the ray is computed

◼University of Freiburg – Computer Science Department – 26


Numerical Integration
− Typically,
is considered
− For , light source areas are sampled and
rays towards those positions are processed
− For , the respective solid angle is sampled
and rays towards those directions are processed

University of Freiburg – Computer Science Department – 27



Numerical Integration
− Due to the recursive nature, the number of processed
rays grows exponentially with the recursion level
−  Monte Carlo integration
− Efficient for multidimensional integral
− Adaptive sample distribution
− Very flexible in terms of the number of used samples
− Even one sample can be used to approximate an integral
 e.g., Path tracing
− At each recursion level, trace a fixed number of rays to light
sources and one ray into the scene (which generates a ray path)
◼University of Freiburg – Computer Science Department – 28
Advanced Computer Graphics
Stochastic Raytracing 2
Matthias Teschner
Outline
− Diffuse vs. general global illumination
− Monte Carlo integration
− Sampling of random variables

◼University of Freiburg – Computer Science Department – 30


Goal monte carlo goal is to approximate the solution of light transport eqn

− Approximating the solution of the light transport


equation
− Recursive evaluation of

− Each recursion level computes parts of the functions


that are visible to the sensor

◼University of Freiburg – Computer Science Department – 31


Numerical Integration – Fixed Sample Size

− E.g. Riemann sum



− More / smaller samples  better accuracy
− dimensional integrals require samples

University of Freiburg – Computer Science Department – 32



Numerical Integration – Adaptive Sample Size

− E.g., Monte Carlo integration


− , adaptive sample size
− More / smaller samples  better accuracy
− dimensional integrals work with arbitrary sample numbers
− Sample size is only approximated  noise

University of Freiburg – Computer Science Department – 33



Stochastic Raytracing - Concept
− Approximately evaluate the reflectance integral
by
− Tracing rays into randomly sampled 2D directions
− Computing the incoming radiances
− Integral is approximated with
we do not know the shape of the angle , we only have the
magnitude of the angle.

− 2 dimensional sample directions


− is an approximation of the solid angle
of sample direction
University of Freiburg – Computer Science Department – 34

Introduction
− Challenges
− Approximate the integral as exact as possible
− Trace as few rays as possible / use as few samples as possible
− Trace relevant rays / use relevant samples
− Rays / samples to light sources are very relevant
(Rays / samples to occluded light sources are irrelevant)
− For diffuse surfaces, rays / samples in normal direction are
more relevant than rays / samples perpendicular to the normal
− For specular surfaces, rays / samples in reflection direction are relevant

◼University of Freiburg – Computer Science Department – 35


Properties
− Benefits
− Processes only evaluations of the integrand
at arbitrary surface points in the domain
− Works for a large variety of integrands,
e.g., it handles discontinuities
− Appropriate for integrals of arbitrary dimensions
− Allows for non-uniform sample patterns /
adaptive sample sizes

University of Freiburg – Computer Science Department – 36



Properties
− Drawbacks
− Using n samples, the scheme converges
to the correct result with O (n½)
− I.e., to half the error, 4n samples are required
− Errors are perceived as noise,
i.e. pixels are arbitrarily too bright or dark
(due to the erroneous approximation of the sample size)
− Evaluation of the integrand at a point and for a direction
is expensive (ray intersection tests)

◼University of Freiburg – Computer Science Department – 37


Continuous Random Variables
− Motivation: random sampling of directions
− Continuous random variables generated by PDF

− In contrast to discrete random variables,


infinite number of possible values
− Canonical uniform random variable
− Sample sets with arbitrary distributions
can be computed from

University of Freiburg – Computer Science Department – 38



Probability Density Function PDF p(x)
also governs the generation of samples

− Motivation: PDF governs the size /


solid angle of a sample / sample direction
− Probability of a random variable taking certain value ranges

The probability, that the random
− variable has a certain exact value x =x , is 0.
0 1

− The probability, that the random variable is in the specified domain, is 1.

− Example
− Uniform PDF for

◼University of Freiburg – Computer Science Department – 39
Cumulative Distribution Function CDF P(x)

− Motivation: CDFs are required to generate sample sets


for arbitrary PDFs from uniform sample sets
− Probability of a random variable to be less or equal to


University of Freiburg – Computer Science Department – 40



Expected Value of estimator is reflectance integral

− Motivation: expected value of an estimator function


is equal to the reflectance integral
− Expected value of a function is defined as the
weighted average value of the function over a domain
Processes an infinite number of
− with samples x according to a PDF p(x)

− Properties

− For independent random variables Xi

◼University of Freiburg – Computer Science Department – 41


Expected Value
− Examples for uniform PDF

University of Freiburg – Computer Science Department – 42



Monte Carlo Estimator - Uniform Random Variables

− Motivation: approximation of the reflectance integral


− Goal: computation of
− Uniformly distributed random variables
− Probability density function Constant and integration to one

− Monte Carlo estimator


− Expected value of is equal to the integral

◼University of Freiburg – Computer Science Department – 43


Monte Carlo Estimator - Uniform Random Variables

University of Freiburg – Computer Science Department – 44



Monte Carlo Estimator - Uniform Random Variables

− PDF
− Estimator
− Integral

− Function value
− Approximate sample size

University of Freiburg – Computer Science Department – 45



Examples - Uniform Random Variables

− Integral
− Estimator Sample size approx. 1/N

− For an increasing number of uniformly distributed


random variables , the
estimator converges to one

Uniformly distributed [Suffern]


random samples
◼University of Freiburg – Computer Science Department – 46
Monte Carlo Estimator - Non-uniform Random Variables

− Monte Carlo estimator p (Xi)  0

University of Freiburg – Computer Science Department – 47



Monte Carlo Estimator - Non-uniform Random Variables

− PDF
− Estimator
− Integral
− larger value of p gives more samples in a domain

− Function value
− Approximate sample size

University of Freiburg – Computer Science Department – 48



Approximate Sample Size
constant

− Sample size / distance for uniform PDF:

− Sample size for non-uniform PDF:


linear

University of Freiburg – Computer Science Department – 49



Monte Carlo Estimator - Multiple Dimensions

− E.g.,
− Samples are two-dimensional
− Uniformly distributed random samples

− Probability density function


− Monte Carlo estimator

− Approximate sample size is

◼University of Freiburg – Computer Science Department – 50


Monte Carlo Estimator - Multiple Dimensions

− E.g.,
− Uniformly distributed random samples
− Probability density function
− Monte Carlo estimator
− Approximate sample size

Sample size Sample size


approx. 9/9 approx. 9/14

University of Freiburg – Computer Science Department – 51



Monte Carlo Estimator - Integration over a Hemisphere

− Approximate computation of the irradiance at a point

− Estimator
− Choosing a PDF This flexibility is an important aspect of Monte Carlo integration.

− Should be similar to the shape of the integrand


− As incident radiance is weighted with ,
it is appropriate to generate more samples
close to the top of the hemisphere

University of Freiburg – Computer Science Department – 52

Monte Carlo Estimator - Integration over a Hemisphere

− Probability distribution

− Estimator

If  and  are sampled according to PDF p(, )


University of Freiburg – Computer Science Department – 53

Monte Carlo Estimator - Integration over a Hemisphere

− Integral
− PDF
− Estimator

− Function value for direction


− Approximate sample size / solid angle
− For large
− The PDF in terms of the solid angle is
◼University of Freiburg – Computer Science Department – 54
Monte Carlo Integration - Steps
− Choose an appropriate
probability density function
− Generate random samples according to the PDF
− Evaluate the function for all samples
− Accumulate sample values weighted with their
approximate sample size

University of Freiburg – Computer Science Department – 55



Monte Carlo Estimator - Error Reduction

− Importance sampling
− Motivation: contributions of larger
sample values are more important
− PDF should be similar to the shape
of the function
[Suffern]
− Optimal PDF
− E.g., if incident radiance is weighted
with , the PDF should choose
more samples close to the normal
direction
University of Freiburg – Computer Science Department – 56

Monte Carlo Estimator - Error Reduction

− Stratified sampling
− Domain subdivision into strata
− E.g., handling direct and indirect illumination differently

light source samples areas


scenes samples solid angle

University of Freiburg – Computer Science Department – 57



Advanced Computer Graphics
Stochastic Raytracing 3
Matthias Teschner
Monte Carlo Estimator - Integration over a Hemisphere

− Approximate computation of the irradiance at a point

− Estimator
− Choosing a PDF This flexibility is an important aspect of Monte Carlo integration.

− Should be similar to the shape of the integrand


− As incident radiance is weighted with ,
it is appropriate to generate more samples
close to the top of the hemisphere

University of Freiburg – Computer Science Department – 59

Outline
− Diffuse vs. general global illumination
− Monte Carlo integration
− Sampling of random variables
− Inversion method
− Rejection method
− Transforming between distributions
− 2D sampling
− Examples

University of Freiburg – Computer Science Department – 60



Motivation - Rendering Equation
− Hemispherical form

− Area form

University of Freiburg – Computer Science Department – 61



Motivation - Monte Carlo Integration
− Choose an appropriate
probability density function
− Generate random samples according to the PDF
− Evaluate the function for all samples
− Accumulate function values weighted
with their approximate sample size

University of Freiburg – Computer Science Department – 62



Inversion Method
we have a pdf and the samples are generated based on this pdf

− Mapping of a uniform random


variable to a goal distribution
− Discrete example p1 p2 p3 p4 are relative pbty and their sum is 1

− Four outcomes with probabilities


and
− Computation of the cumulative
distribution function

1 2 3 4
[Pharr, Humphreys]
◼University of Freiburg – Computer Science Department – 63
Inversion Method
− Discrete example cont.
− Take a uniform random variable
− has the desired distribution
− Continuous case
− and are continuous functions 1 2 3 4
− Start with the desired PDF [Pharr, Humphreys]
− Derive
− Compute the inverse
− Obtain a uniformly distributed variable
the pdf . cdf. inversion of cdf are all continuous function

− Compute which adheres to

University of Freiburg – Computer Science Department – 64



Inversion Method - Example 1
− Power distribution used in reflection integral at specular surface

− E.g., for sampling the Blinn microfacet model


− Computation of the PDF

− PDF
− CDF
− Inverse of the CDF
− Sample generation
− Generate uniform random samples
− are samples from the distribution
University of Freiburg – Computer Science Department – 65

Inversion Method - Example 2
− Exponential distribution
− E.g., for considering participating media
− Computation of the PDF

− PDF
− CDF
− Inverse of the CDF
− Sample generation
− Generate uniform random samples
− are samples from the distribution
◼University of Freiburg – Computer Science Department – 66
Outline
− Context
− Diffuse vs. general global illumination
− Monte Carlo integration
− Sampling of random variables
− Inversion method
− Rejection method
− Transforming between distributions
− 2D sampling
− Examples
University of Freiburg – Computer Science Department – 67

Rejection Method
− Draws samples according to a function
− Dart-throwing approach
− Works with a PDF and a scalar with
− Properties
− is not necessarily a PDF
− PDF, CDF and inverse CDF
do not have to be computed
− Simple to implement
− Useful for debugging purposes

University of Freiburg – Computer Science Department – 68



Rejection Method
− Sample generation
− Generate a uniform random sample
− Generate a sample according to
− Accept if

a b

[Pharr, Humphreys]

◼University of Freiburg – Computer Science Department – 69


Outline
− Context
− Diffuse vs. general global illumination
− Monte Carlo integration
− Sampling of random variables
− Inversion method
− Rejection method
− Transforming between distributions
− 2D sampling
− Examples
University of Freiburg – Computer Science Department – 70

Transforming Between Distributions
− Computation of a resulting PDF, when a function is
applied to samples from an arbitrary distribution
− Random variables are drawn from
− Bijective transformation (one-to-one mapping)
− How does the distribution look like?

◼University of Freiburg – Computer Science Department – 71


Transforming Between Distributions

− Example


University of Freiburg – Computer Science Department – 72



Transforming Between Distributions
− Multiple dimensions
− is an n-dimensional random variable
− is a bijective transformation
− Transformation of the PDF

◼University of Freiburg – Computer Science Department – 73


Transforming Between Distributions
− Example (polar coordinates)
− Samples with density
− Corresponding density with and

University of Freiburg – Computer Science Department – 74



Transforming Between Distributions
− Example (spherical coordinates)




− Example (solid angle)



University of Freiburg – Computer Science Department – 75

Outline
− Context
− Diffuse vs. general global illumination
− Monte Carlo integration
− Sampling of random variables
− Inversion method
− Rejection method
− Transforming between distributions
− 2D sampling
− Examples
University of Freiburg – Computer Science Department – 76

Concept
− Samples from a 2D joint density function
− Procedure
− Compute the marginal density function
− Compute the conditional density function
− Generate a sample according to
− Generate a sample according to
− Marginal density function
− Integral of for a particular over all -values
− Conditional density function
− Density function for given a particular
◼ University of Freiburg – Computer Science Department – 77
Outline
− Context
− Diffuse vs. general global illumination
− Monte Carlo integration
− Sampling of random variables
− Inversion method
− Rejection method
− Transforming between distributions
− 2D sampling
− Examples
University of Freiburg – Computer Science Department – 78

Uniform Sampling of a Triangle
− Sampling an isosceles right triangle of area 0.5
− u, v can be interpreted as Barycentric coordinates
− Can be used to generate samples for arbitrary triangles

− Marginal density function (u, 1-u)
− v

− Conditional density u
− Inversion method


University of Freiburg – Computer Science Department – 79
◼ [Pharr, Humphreys]
Uniform Sampling of a Triangle
− Inversion method cont.
− Inverse functions of the cumulative distribution functions
− u is generated between 0 and 1
− v is generated between 0 and 1-u=(1-)½

− Generating uniformly sampled random values and


− Applying the inverse CDFs to obtain and

University of Freiburg – Computer Science Department – 80



Uniform Sampling of a Hemisphere
− PDF is constant with respect to a solid angle


− Marginal density function

− Conditional density for

− Inversion method [Suffern]


University of Freiburg – Computer Science Department – 81

Uniform Sampling of a Hemisphere
− Inversion method cont.
− Inverse functions of the cumulative distribution functions


− Generating uniformly sampled random values and
− Applying the inverse CDFs to obtain and
− Conversion to Cartesian space



− is a normalized direction
University of Freiburg – Computer Science Department – 82

Uniform Sampling of a Hemisphere
− Illustration for

Generate less samples


for smaller angles 

◼University of Freiburg – Computer Science Department – 83


Cosine-Weighted Sampling of a Hemisphere

− PDF is proportional to :


− Marginal density function

− Conditional density for

− Inversion method
− [Suffern]


University of Freiburg – Computer Science Department – 84

Cosine-Weighted Sampling of a Hemisphere

− Inversion method cont.


− Inverse functions of the cumulative distribution functions


− Generating uniformly sampled random values and
− Applying the inverse CDFs to obtain and
− Conversion to Cartesian space x- y- values uniformly sample a unit
disk, i.e., cosine-weighted samples
− of the hemisphere can also be obtained
− by uniformly sampling a unit sphere
and projecting the samples onto the
− hemisphere
− is a normalized direction
University of Freiburg – Computer Science Department – 85

Cosine-Weighted Sampling of a Hemisphere

− Illustration for

Generate less samples [Suffern]


for smaller and larger
angles  Cosine-weighted
hemisphere
(top view, side view)

◼University of Freiburg – Computer Science Department – 86

You might also like