Docstoc

第六课 Ray Tracing

Document Sample
第六课 Ray Tracing Powered By Docstoc
					第五课 Ray Tracing
Overview of the Section

   Why Ray Tracing?
   What is Ray Tracing?
   How to tracing rays?
   How to accelerating ray-tracing?
Object-ordering rendering
   Each polygon or triangle is processed in
    turn and its visibility is determined using
    algorithms such as Z-buffer
   After determining its visibility, the
    polygon or triangle is projected onto the
    viewing plane
   Polygon or triangle is shaded using
    Phong Model\
   OpenGL, rasterization (光栅化)
Object-ordering rendering
   Advantage
       Fast rendering can be implemented on
        hardware
   Disadvantage
       Difficult to model lighting effects such as
        reflection or transparency
       Difficult to model lighting effects are caused
        by the interaction of objects, i.e. shadows
   Assumption
       Light travels from visible objects towards the
        eye
Ray tracing

   Question
       Do light proceed from the eye to the light
        source or from light source to the eye?
   To answer the question, it’s important to
    understand
       Light rays do travel in straight lines
       Light rays do not interfere if they cross
       Light rays travel from the light source to the
        eye but the physics are invariant under path
        reversal
Ray tracing

   Image order rendering
       Start from pixel, what do you see through
        this pixel
   Allows to add more realism to the
    rendered scene by allowing effects such
    as
       Shadows
       Transparency
       Reflections
How ray-tracing works

   Looks through each pixel (e.g. 640 x 480)
   Determines what eye sees through pixel
       Trace light ray: eye -> pixel (image plane) ->
        scene
       If a ray intersect any scene object?
           Yes, render pixel using object color
           No, it uses the background color
       Automatically solves hidden surface removal
        problem
Ray misses all objects
Ray hits an object
Ray hits an object
   Ray hits object: Check if hit point is in shadow,
    build secondary ray towards light sources
Ray hits an object
   If shadow ray hits another object before light
    source: first intersection point is in shadow of
    the second object. Otherwise, collect light
    contributions
Reflected Ray
   When a ray hits an reflective object, a reflection
    ray is generated which is tested against all of
    the object in the scene
Shadows and Reflections
Transparency
   If intersected object is transparent, transmitted
    ray is generated
Transparency
Recursion
   Reflected rays can generated other reflected
    rays
Recursion

   Scene with one layer of reflection
Recursion

   Scene with two layer of reflection
Ray Tree

   Reflective/transmitted rays are
    continually generated until ray
    leaves the scene without hitting any
    object or a preset recursion level
    has been reached
Ray-Object Intersections
   Express ray as equation (origin is eye, pixel
    determines direction)
       R0 = [x0, y0, z0] – origin of ray
       Rd = [xd, yd, zd] – direction of ray
   Define parametric equation of ray
       R (t) = R0 + Rd * t, with t > 0.0
   Express all objects mathematically
   Ray tracing idea:
       Put ray mathematical equation into object equation
       Determine if real solution exists
       Object with smallest hit time is object seen
Ray-Object Intersection

   Dependent on parametric equation of
    object
   Ray-Sphere Intersections
   Ray-Plane Intersections
   Ray-Polygon Intersections
   Ray-Box Intersections
   Ray-Quadric Intersections (cylinders,
    cones, ellipsoids, paraboloids)
Accelerating Ray Tracing
   Ray tracing is very time-consuming
    because of intersection calculations
   Each intersection requires many floating
    float point operations
   Solutions
       Use faster machines
       Use specialized hardware, especially parallel
        processors
       Speed up computations by using more
        efficient algorithms
       Reduce the number of ray-object
        computations
Reducing Ray-Object Intersections

   We will look at spatial (空间的) data
    structures
       Hierarchical (层次) bounding volumes (包围盒)
       Uniform Grids (均匀格)
       Quadtree/Octree (四叉树/八叉树)
       K-d Tree/BSP tree (空间二分树)
   Good spatial data structures could speed
    up ray tracing by 10-100 times
Ray intersection
Ray Intersection
Bounding Volume

   Wrap (包住) things with bound
    volumes that hard to test for
    intersection in things that are easy to
    test. Ray can’t hit the real object
    unless it hits the bounding volume
   Bounding Box and Bounding Sphere
Bounding Volume
Hierarchical Bounding Volume

   HBV (层次包围盒)
       Limitation of bounding volume
           Still need to test ray against every object,
            O(n) time complexity, where n is the
            number of objects
       A natural extension to bounding
        volumes is a HBV
HBV

   Given the bounding volumes of the
    objects in the scene, a tree data structure
    of bounding volumes is created with the
    bounding volume of the objects at the
    leaves
   Each interior node v of HBV corresponds
    to the bounding volumes that completely
    encloses the bounding volumes of all the
    children node of v
HBV

   An example
       Several triangles (right)
       HBV (below)
HBV
HBV
HBV

   Works well if you use good
    bounding volume and hierarchy
   Should give O(logn) time
    complexity
   Can have mulitple classes (box,
    sphere) of bounding volumes
Uniform Grids (均匀网格)

   Data structure: a 3D array of cells that
    tile space
       Each cell lists all primitives which
        intersect with that cell
Uniform Grids

   Intersection testing
       Start tracing at cell where ray begins
       Step from cell to cell, searching for the
        first intersection cell
       At each cell, test for intersection with
        all primitives intersected with that cell
       If there is an intersection, return the
        closest one
Uniform Grids
   Advantage
       Easy to construct and easy to traverse
   Disadvantage
       Uniform grids are a poor choice if the world
        is non-homogeneous (不均匀). Many
        polygons will cluster in a small space
       How many cells to use?
           Too few -> many objects in a cell -> slow
           Too many -> many empty cells to traverse -> slow
            and large storage
       Non-uniform spatial division is better
QuadTree/Octree
   QuadTree
       The 2D generalization of binary tree
       Node is a square
       Recursively split square into four equal sub-
        square
       Stop when leaves get “simple enough”
   Octree
       2D generalization of QuadTree
       Node is cube, recursively split into 8 equal sub-
        cubes
Construction of Octree
   First, enclose the entire scene in a
    minimal axis-aligned box
   Built recursively in a top-down fashion,
    and stops recursion when criterion is
    fulfilled
   These criteria include: a maximum
    number of recursion level has been
    reached, or that there is fewer than a
    threshold number of primitives in a node.
    (递归终止条件:已达到最大层次、或包围盒
    内物体已很少)
BSP tree
Construction of BSP

   Similar to octree, BSP is also
    constructed hierarchically in top-
    down fashion
       A splitting plane (perpendicular to axis
        x or y or z) is selected to subdivide a
        current leaf node into two equal size
        sub-nodes
BSP tree Examples
BSP tree Examples
KD-tree

   Difference between BSP and KD
    tree
       Distinguished by the position of the
        splitting plane: in BSP tree, the plane
        always lies at the mid-point of the current
        node, but the KD tree has arbitrarily
        position of the plane
   Thus, any BSP tree is a KD tree, but
    not vice versa
Thanks

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:5
posted:9/10/2012
language:English
pages:44