Download presentation
Presentation is loading. Please wait.
Published byMelinda Grant Modified over 9 years ago
1
第五课 Ray Tracing
2
Overview of the Section Why Ray Tracing? What is Ray Tracing? How to tracing rays? How to accelerating ray-tracing?
3
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 ( 光栅化 )
4
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
5
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
6
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
7
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
8
Ray misses all objects
9
Ray hits an object
10
Ray hits object: Check if hit point is in shadow, build secondary ray towards light sources
11
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
12
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
13
Shadows and Reflections
14
Transparency If intersected object is transparent, transmitted ray is generated
15
Transparency
16
Recursion Reflected rays can generated other reflected rays
17
Recursion Scene with one layer of reflection
18
Recursion Scene with two layer of reflection
19
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
20
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
21
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)
22
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
23
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
24
Ray intersection
25
Ray Intersection
26
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
27
Bounding Volume
28
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
29
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
30
HBV An example Several triangles (right) HBV (below)
31
HBV
33
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
34
Uniform Grids ( 均匀网格 ) Data structure: a 3D array of cells that tile space Each cell lists all primitives which intersect with that cell
35
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
36
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
37
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
38
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. ( 递归终止条件:已达到最大层次、或包围盒 内物体已很少 )
39
BSP tree
40
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
41
BSP tree Examples
43
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
44
Thanks
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.