ray tracing info

Upload: seotut

Post on 04-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Ray tracing info

    1/88

    Ray Tracing II

    Lecturer: Erick Fredj

    This presentation is largely inspired byPfister and Chan Computer Graphics

    Course from MIT 2007.

  • 7/29/2019 Ray tracing info

    2/88

    Outline

    Spatial Acceleration Data Structures

    Motivation Distribution Ray Tracing

    Monte Carlo Ray Tracing

    Importance & Stratified Sampling

    Path Tracing & Irradiance Caching

    Photon Mapping

  • 7/29/2019 Ray tracing info

    3/88

    Recap: Ray Tracing

  • 7/29/2019 Ray tracing info

    4/88

    Recap: Ray Tracingtrace ray

    Intersect all objects

    color = ambient term

    For every light

    cast shadow ray

    color += local shading termIf mirror

    color += colorrefl *

    trace reflected ray

    If transparent

    color += colortrans *

    trace transmitted ray

  • 7/29/2019 Ray tracing info

    5/88

    Ray Tracing Pros and Cons

  • 7/29/2019 Ray tracing info

    6/88

    Ray Tracing Pros and Cons

    Pros:

    Easy to implement

    Extends well to global illumination

    shadows reflections / refractions

    multiple light bounces

    atmospheric effects

    Cons:

    Speed! (seconds per frame, not frames per second)

  • 7/29/2019 Ray tracing info

    7/88

    Speedup Techniques

    Why is ray tracing slow? How to improve?

  • 7/29/2019 Ray tracing info

    8/88

    Speedup Techniques

    Why is ray tracing slow? How to improve?

    Too many objects, too many rays

    Reduce ray-object intersection tests

    Many techniques!

  • 7/29/2019 Ray tracing info

    9/88

    Acceleration of Ray Casting

    Goal: Reduce the number of ray/primitive intersections

  • 7/29/2019 Ray tracing info

    10/88

    Conservative Bounding Region

    First check for an intersection

    with a conservative bounding region

    Early reject

  • 7/29/2019 Ray tracing info

    11/88

    Bounding Regions

    What makes a good bounding region?

  • 7/29/2019 Ray tracing info

    12/88

    Conservative Bounding Regions

    arbitrary convex region

    (bounding half-spaces)

    non-alignedbounding box

    boundingsphere

    axis-aligned

    bounding box

  • 7/29/2019 Ray tracing info

    13/88

    Regular Grid

  • 7/29/2019 Ray tracing info

    14/88

    Create Grid

    Find bounding box of scene

    Choose grid resolution (nx, ny, nz)

    gridx neednot = gridy

  • 7/29/2019 Ray tracing info

    15/88

    Insert Primitives into Grid

    Primitives that

    overlap multiple

    cells?

    Insert into multiple

    cells (use pointers)

  • 7/29/2019 Ray tracing info

    16/88

    For Each Cell Along a Ray

    contain an

    intersection?

    Yes: return closest

    intersection

    No: continue

  • 7/29/2019 Ray tracing info

    17/88

    Preventing Repeated Computation

    Perform the

    computation

    once, "mark the

    object

    Don't re-intersect

    marked objects

  • 7/29/2019 Ray tracing info

    18/88

    Don't Return Distant Intersections

    If intersection t

    is not within

    the cell range,

    continue

    (there may besomething

    closer)

  • 7/29/2019 Ray tracing info

    19/88

    Adaptive Grids

    Subdivide until each cell contains no more than n elements, or

    maximum depth d is reached

    Nested Grids Octree/(Quadtree)

  • 7/29/2019 Ray tracing info

    20/88

    Primitives in an Adaptive Grid

    Can live at intermediate

    levels, or be pushed to

    lowest level of grid

    Octree/(Quadtree)

  • 7/29/2019 Ray tracing info

    21/88

    Binary Space Partition (BSP) Tree

    Recursively partition space by planes

    Every cell is a convex polyhedron

  • 7/29/2019 Ray tracing info

    22/88

    Binary Space Partition (BSP) Tree

    Simple recursive algorithms

    Example: point finding

  • 7/29/2019 Ray tracing info

    23/88

    Binary Space Partition (BSP) Tree

    Trace rays by recursion on tree

    BSP construction enables simple front-to-back traversal

  • 7/29/2019 Ray tracing info

    24/88

    Grid Discussion

    Regular + easy to construct + easy to

    traverse - may be only sparsely filled -

    geometry may still be clumped

    Adaptive + grid complexity matches

    geometric density - more expensive

    to traverse (especially BSP tree)

  • 7/29/2019 Ray tracing info

    25/88

    Outline

    Spatial Acceleration Data Structures

    Motivation Distribution Ray Tracing

    Monte Carlo Ray Tracing

    Importance & Stratified Sampling Path Tracing & Irradiance Caching

    Photon Mapping

  • 7/29/2019 Ray tracing info

    26/88

    Shadows & Light Sources

    http://www.davidfay.com/index.php

    http://3media.initialized.org/photos/200

    0-10-18/index_gall.htm

    http://www.davidfay.com/index.phphttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://3media.initialized.org/photos/2000-10-18/index_gall.htmhttp://www.davidfay.com/index.php
  • 7/29/2019 Ray tracing info

    27/88

    Shadows

    One shadow ray per intersection per point light source

    no shadow rays

    one shadow ray

  • 7/29/2019 Ray tracing info

    28/88

    Soft Shadows

    Multiple shadow rays to

    sample area light source

    one shadow ray

    lots of shadow rays

  • 7/29/2019 Ray tracing info

    29/88

    Probabilistic Soft Shadows

    Multiple shadow rays to

    sample area light source

    Monte-Carlo ray tracing

    generalizes this

    lots of shadow rays

  • 7/29/2019 Ray tracing info

    30/88

    Reflection

    One reflection ray per intersection

  • 7/29/2019 Ray tracing info

    31/88

    Glossy Reflection

    Random reflection rays around mirror direction

    Justin Legakis

  • 7/29/2019 Ray tracing info

    32/88

    Glossy Surfaces

    Glossy reflections can be handled by Monte Carlo methods

  • 7/29/2019 Ray tracing info

    33/88

    Motion Blur

    Sample objects temporally

  • 7/29/2019 Ray tracing info

    34/88

    Outline

    Spatial Acceleration Data Structures

    Motivation Distribution Ray Tracing

    Monte Carlo Ray Tracing

    Importance & Stratified Sampling Path Tracing & Irradiance Caching

    Photon Mapping

  • 7/29/2019 Ray tracing info

    35/88

    Ray Casting

    Cast a ray from the eye through each pixel

  • 7/29/2019 Ray tracing info

    36/88

    Ray Casting

    Cast a ray from the eye through each pixel

    Trace secondary rays (light, reflection, refraction)

  • 7/29/2019 Ray tracing info

    37/88

    Ray Casting

    Cast a ray from the eye through each pixel

    Trace secondary rays (light, reflection, refraction)

    Accumulate radiance contribution

  • 7/29/2019 Ray tracing info

    38/88

    Monte-Carlo computation of

    Take a square

    Take a random point (x,y) in the square

    Test if it is inside the disc (x2+y2 < 1)

    The probability is /4

  • 7/29/2019 Ray tracing info

    39/88

    Monte-Carlo computation of

    The probability is /4

    Count the inside ratio n = # inside / total # trials

    n * 4

    The error depends on the number or trials

  • 7/29/2019 Ray tracing info

    40/88

    Review of probability (discrete)

    Random variable can take discrete values xi

    Probability pi for each xi

    0 < pi

  • 7/29/2019 Ray tracing info

    41/88

    Example: Fair Dice

    5.3

    6543216

    1

    6

    16

    1

    6

    1

    i

    i

    i

    iidice

    x

    xpxE

  • 7/29/2019 Ray tracing info

    42/88

    Variance & Standard Deviation

    Variance 2:

    Measure of deviation from expected value

    Expected value of square difference (MSE)

    Also

    Standard deviation :

    Square root of variance (notion of error, RMS)

    222

    ii xExxExE

    222 xExE

  • 7/29/2019 Ray tracing info

    43/88

    Monte Carlo integration

    Functionf(x) of x[a b]

    We want to compute

    Consider a random variablex

    Ifx has uniform distribution, I=E[f(x)]/(b-a) By definition of the expected value

    Expected value of f(x) is the integral times (b-a)

    Accurate on average

    dxxfIb

    a

  • 7/29/2019 Ray tracing info

    44/88

    Sum of Random Variables

    N independent identically-distributed (IID) variables xi

    Share same probability (uniform here)

    Define

    n

    j

    iN xfN

    F1

    1

  • 7/29/2019 Ray tracing info

    45/88

    Variance of FN

    After some math:

    i.e. stddev (error) decreases by

    n

    i

    iN

    N

    xfF

    1

    22

    N

    xfFN

    2

    2

    N

  • 7/29/2019 Ray tracing info

    46/88

    Example

    1

    0

    45 dxxI

  • 7/29/2019 Ray tracing info

    47/88

    Example

    1

    0

    45 dxxI

    We know itshould be 1.0

    In practice with

    uniform

    samples:

  • 7/29/2019 Ray tracing info

    48/88

    Monte-Carlo Recap

    Expected value is the integrand

    Accurate on average

    Variance decrease in 1/N

    Error decreases inn1

  • 7/29/2019 Ray tracing info

    49/88

    Monte-Carlo Ray Tracing

    Cast a ray from the eye through each pixel

    Cast random rays from the visible point

    Recurse

  • 7/29/2019 Ray tracing info

    50/88

    Monte-Carlo Ray Tracing

    Cast a ray from the eye through each pixel

    Cast random rays from the visible point

    Recurse

  • 7/29/2019 Ray tracing info

    51/88

    Monte-Carlo Ray Tracing

    Cast a ray from the eye through each pixel

    Cast random rays from the visible point

    Recurse

  • 7/29/2019 Ray tracing info

    52/88

    1 sample per pixel

  • 7/29/2019 Ray tracing info

    53/88

    256 sample per pixel

  • 7/29/2019 Ray tracing info

    54/88

    Results

  • 7/29/2019 Ray tracing info

    55/88

    Outline

    Spatial Acceleration Data Structures

    Motivation Distribution Ray Tracing

    Monte Carlo Ray Tracing

    Importance & Stratified Sampling

    Path Tracing & Irradiance Caching

    Photon Mapping

  • 7/29/2019 Ray tracing info

    56/88

    Importance Sampling

    Consider N random samples drawn with probabilityp(x)

    Define estimator as:

    Probabilityp allows us to sample the domain more smartly

    N

    i

    xp

    xf

    ii

    NI 1

    1

  • 7/29/2019 Ray tracing info

    57/88

    Importance Sampling

    Choosep wisely to reduce variance

    p that resembles f

    Does not change convergence rate (still sqrt)

    But decreases the constant

    N

    i

    xp

    xf

    i

    i

    NI

    1

    1

    bad uniform good

  • 7/29/2019 Ray tracing info

    58/88

    Monte-Carlo

    Take reflectance into account

    Multiply incoming radiance by BRDF value

  • 7/29/2019 Ray tracing info

    59/88

    Sampling a BRDF

  • 7/29/2019 Ray tracing info

    60/88

    Sampling a BRDF

  • 7/29/2019 Ray tracing info

    61/88

    Sampling a BRDF

  • 7/29/2019 Ray tracing info

    62/88

    Sampling a BRDF

  • 7/29/2019 Ray tracing info

    63/88

    Stratified sampling

    With uniform sampling, we can get unlucky

    E.g. all samples in a corner

    To prevent it, subdivide domain

    into non-overlapping regions i

    Each region is called a stratum

    Take one random samples per i

  • 7/29/2019 Ray tracing info

    64/88

    Stratified Sampling

    Cheap and effective

    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)

  • 7/29/2019 Ray tracing info

    65/88

    Outline

    Spatial Acceleration Data Structures

    Motivation Distribution Ray Tracing

    Monte Carlo Ray Tracing

    Importance & Stratified Sampling

    Path Tracing & Irradiance Cache

    Photon Mapping

  • 7/29/2019 Ray tracing info

    66/88

    Monte Carlo Path Tracing

    Trace only one secondary ray per recursion

    But send many primary rays per pixel

  • 7/29/2019 Ray tracing info

    67/88

    Results

    10 paths/pixel

  • 7/29/2019 Ray tracing info

    68/88

    Results

    100 paths/pixel

  • 7/29/2019 Ray tracing info

    69/88

    Path Tracing is costly

    Needs tons of rays per pixel

  • 7/29/2019 Ray tracing info

    70/88

    Direct illumination

  • 7/29/2019 Ray tracing info

    71/88

    Global Illumination

  • 7/29/2019 Ray tracing info

    72/88

    Indirect Illumination

  • 7/29/2019 Ray tracing info

    73/88

    Irradiance cache

    The indirect illumination is smooth

  • 7/29/2019 Ray tracing info

    74/88

    Irradiance cache

    The indirect illumination is smooth

  • 7/29/2019 Ray tracing info

    75/88

    Irradiance cache

    The indirect illumination is smooth

    Interpolate nearby values

  • 7/29/2019 Ray tracing info

    76/88

    Irradiance cache

    The indirect illumination is smooth

    Interpolate nearby values

    But do full calculation for direct lighting

  • 7/29/2019 Ray tracing info

    77/88

    Irradiance caching

  • 7/29/2019 Ray tracing info

    78/88

    Outline

    Spatial Acceleration Data Structures

    Motivation Distribution Ray Tracing

    Monte Carlo Ray Tracing

    Importance & Stratified Sampling

    Path Tracing & Irradiance Caching

    Photon Mapping

    h

  • 7/29/2019 Ray tracing info

    79/88

    Photon mapping

    Preprocess: cast rays from light sources

    Store photons

    h i

  • 7/29/2019 Ray tracing info

    80/88

    Photon mapping

    Preprocess: cast rays from light sources

    Store photons (position + light power + incoming direction)

    h

  • 7/29/2019 Ray tracing info

    81/88

    Photon map

    Efficiently store photons for fast access

    Use hierarchical spatial structure (kd-tree)

    Ph i d i

  • 7/29/2019 Ray tracing info

    82/88

    Photon mapping - rendering

    For secondary rays

    reconstruct irradiance using adjacent stored photon

    Take the k closest photons

    Ph l

  • 7/29/2019 Ray tracing info

    83/88

    Photon map results

    Ph i i

  • 7/29/2019 Ray tracing info

    84/88

    Photon mapping - caustics

    Special photon map for specular reflection and refraction

  • 7/29/2019 Ray tracing info

    85/88

    1000 paths/pixel

  • 7/29/2019 Ray tracing info

    86/88

    Photon mapping

    Ph t M i R

  • 7/29/2019 Ray tracing info

    87/88

    Photon Mapping Recap

    Preprocess: Path tracing

    Store photons

    Special map for caustics (because not as uniform)

    Rendering

    Primary rays

    Direct lighting

    Indirect lighting

    Reconstruct irradiance using k nearest photons Irradiance caching

    Reconstruct caustics from caustic map

    E d

  • 7/29/2019 Ray tracing info

    88/88

    End

    Good Luck