Download presentation
Presentation is loading. Please wait.
Published byCuthbert Douglas Modified over 9 years ago
1
David Luebke10/9/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu http://www.cs.virginia.edu/~cs551
2
David Luebke10/9/2015 Administrivia l Upcoming graphics events –Graphics lunch: Olsson 236D n Ongoing, informal event; bring your lunch –“Graphics week”: 2 upcoming colloquia n Dec 1: Dan Aliaga (Bell Labs), Image-Based Rendering n Dec 6: Ben Watson (U. Alberta), Level of detail control
3
David Luebke10/9/2015 Recap: Ray Casting l An example: ScreenEyepointScene
4
David Luebke10/9/2015 Recap: Recursive Ray Tracing l Obvious extension: –Spawn additional rays off reflective surfaces –Spawn transmitted rays through transparent surfaces l Leads to recursive ray tracing Primary Ray Secondary Rays
5
David Luebke10/9/2015 Recap: Basic Algorithm Object allObs[]; Color image[]; RayTraceScene() allObs = initObjects(); for (Y all rows in image) for (X all pixels in row) Ray R = calcPrimaryRay(X,Y); image[X,Y] = TraceRay(R); display(image);
6
David Luebke10/9/2015 Recap: Basic Algorithm Color TraceRay(Ray R) if rayHitsObjects(R) then Color localC, reflectC, refractC; Object O = findNearestObject(R); localC = shade(O,R); Ray reflectedRay = calcReflect(O,R) Ray refractedRay = calcRefract(O,R) reflectC = TraceRay(reflectedRay); refractC = TraceRay(refractedRay); return localC reflectC refractC else return backgroundColor
7
David Luebke10/9/2015 Recap: Representing Rays l We represent a ray parametrically: –A starting point O –A direction vector D –A scalar t O D t = 1t < 0 R = O + tD t > 1
8
David Luebke10/9/2015 Recap: Ray-Polygon Intersection Find plane equation of polygon: ax + by + cz + d = 0 l To find coefficients: N = [a, b, c] d = N P 1 x y N P1P1 P2P2 d
9
David Luebke10/9/2015 Recap: Ray-Polygon Intersection l Find intersection of ray and plane: t = -(aO x + bO y + cO z + d) / (aD x + bD y + cD z ) Does polygon contain intersection point P i ? –One simple algorithm: Draw line from P i to each polygon vertex n Measure angles between lines (how?) If sum of angles between lines is 360°, polygon contains P i –Slow — better algorithms available
10
David Luebke10/9/2015 Recap: Shadow Rays l Simple idea: –Where a ray intersects a surface, send a shadow ray to each light source –If the shadow ray hits any surface before the light source, ignore light l Note: each ray-surface intersection now spawns n + 2 rays, n = # light sources –Remember: intersections 95% of work
11
David Luebke10/9/2015 Recap: Shadow Rays l Some problems with using shadow rays as described: –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows
12
David Luebke10/9/2015 Shadow Ray Problems: Too Much Computation l Light buffer (Haines/Greenberg, 86) –Precompute lists of polygons surrounding light source in all directions –Sort each list by distance to light source –Now shadow ray need only be intersected with appropriate list! Occluding Polys Shadow Ray Current Intersection Point Light Buffer
13
David Luebke10/9/2015 Shadow Rays l Some problems with using shadow rays as described: –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows
14
David Luebke10/9/2015 Shadow Ray Problems: Sharp Shadows l Why are the shadows sharp? l A: Infinitely small point light sources l What can we do about it? l A: Implement area light sources l How?
15
David Luebke10/9/2015 Shadow Ray Problems: Area Light Sources 30% blockage l Could trace a conical beam from point of intersection to light source: l Track portion of beam blocked by occluding polygons:
16
David Luebke10/9/2015 Shadow Ray Problems: Area Light Sources l Too hard! Approximate instead: l Sample the light source over its area and take weighted average: 50% blockage
17
David Luebke10/9/2015 Shadow Ray Problems: Area Light Sources l Disadvantages: –Less accurate (50% vs. 30% blockage) –Oops! Just quadrupled (at least) number of shadow rays l Moral of the story: –Soft shadows are very expensive in ray tracing
18
David Luebke10/9/2015 Shadow Rays l Some problems with using shadow rays as described: –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows
19
David Luebke10/9/2015 Shadow Ray Problems: Semitransparent Objects l In principle: –Translucent colored objects should cast colored shadows –Translucent curved objects should create refractive caustics l In practice: –Can fake colored shadows by attenuating color with distance –Caustics need backward ray tracing
20
David Luebke10/9/2015 Speedup Techniques l Intersect rays faster l Shoot fewer rays l Shoot “smarter” rays
21
David Luebke10/9/2015 Speedup Techniques l Intersect rays faster l Shoot fewer rays l Shoot “smarter” rays
22
David Luebke10/9/2015 Intersect Rays Faster l Bounding volumes l Spatial partitions l Reordering ray intersection tests l Optimizing intersection tests
23
David Luebke10/9/2015 Bounding Volumes l Bounding volumes –Idea: before intersecting a ray with a collection of objects, test it against one simple object that bounds the collection 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
24
David Luebke10/9/2015 Bounding Volumes l Hierarchical bounding volumes –Group nearby volumes hierarchically –Test rays against hierarchy top-down
25
David Luebke10/9/2015 Bounding Volumes l Different bounding volumes –Spheres n Cheap intersection test n Poor fit n Tough to calculate optimal clustering –Axis-aligned bounding boxes (AABBs) n Relatively cheap intersection test n Usually better fit n Trivial to calculate clustering
26
David Luebke10/9/2015 Bounding Volumes l More bounding volumes –Oriented bounding boxes (OBBs) n Medium-expensive intersection test n Very good fit (asymptotically better) n Medium-difficult to calculate clustering –Slabs (parallel planes) n Comparatively expensive n Very good fit n Difficult to calculate good clustering
27
David Luebke10/9/2015 Spatial Partitioning l Hierarchical bounding volumes surround objects in the scene with (possibly overlapping) volumes l Spatial partitioning techniques classify all space into non-overlapping portions
28
David Luebke10/9/2015 Spatial Partitioning l Example spatial partitions: –Uniform grid (2-D or 3-D) –Octree –k-D tree –BSP-tree
29
David Luebke10/9/2015 Uniform Grid l Uniform grid pros: –Very simple and fast to generate –Very simple and fast to trace rays across (How?) l Uniform grid cons: –Not adaptive n Wastes storage on empty space n Assumes uniform spread of data
30
David Luebke10/9/2015 Octree l Octree pros: –Simple to generate –Adaptive l Octree cons: –Nontrivial to trace rays across –Adaptive only in scale
31
David Luebke10/9/2015 k-D Trees l k-D tree pros: –Moderately simple to generate –More adaptive than octrees l k-D tree cons: –Less efficient to trace rays across –Moderately complex data structure
32
David Luebke10/9/2015 BSP Trees l BSP tree pros: –Extremely adaptive –Simple & elegant data structure l BSP tree cons: –Very hard to create optimum BSP –Splitting planes can explode storage –Simple but slow to trace rays across
33
David Luebke10/9/2015 Reordering Ray Intersection Tests l Caching ray hits (esp. shadow rays) l Memory-coherent ray tracing
34
David Luebke10/9/2015 Optimizing Ray Intersection Tests l Fine-tune the math! –Share subexpressions –Precompute everything possible l Code with care –Even use assembly, if necessary
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.