Download presentation
Presentation is loading. Please wait.
Published byMoris Hensley Modified over 8 years ago
1
David Luebke2/23/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu http://www.cs.virginia.edu/~cs551
2
David Luebke2/23/2016 Administrivia l Upcoming graphics events –Graphics lunch: Olsson 236D n Ongoing, informal event; bring your lunch n Tomorrow’s topic: Art-Based Interactive Rendering by Derek Cornish (4th-year thesis proposal):
3
David Luebke2/23/2016 Adminstrivia l More upcoming graphics events –“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
4
David Luebke2/23/2016 Realism l What is not realistic about the following images?
5
David Luebke2/23/2016 Realism?
6
David Luebke2/23/2016 Realism?
7
David Luebke2/23/2016 Realism?
8
David Luebke2/23/2016 Realism?
9
David Luebke2/23/2016 Realism?
10
David Luebke2/23/2016 Realism… l A big part of realism is realistic lighting l Is OpenGL’s lighting model realistic? –Empirical specular term –“Ambient” term –No shadows –No surface interreflection Crude light-surface interaction model Strictly local illumination model
11
David Luebke2/23/2016 Global Illumination l Realistic lighting is global, not local –Surfaces shadow each other –Surfaces illuminate each other l Two long-time approaches –Ray-tracing: simulate light-ray optics –Radiosity: simulate physics of light transfer
12
David Luebke2/23/2016 Ray Tracing Overview l To determine visible surfaces at each pixel: –Cast a ray from the eyepoint through the center of the pixel –Intersect the ray with all objects in the scene –Whatever it hits first is the visible object l This is called ray casting
13
David Luebke2/23/2016 Ray Casting l An example: ScreenEyepointScene
14
David Luebke2/23/2016 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
15
David Luebke2/23/2016 Recursive Ray Tracing l Slightly less obvious extension: –Trace a ray from point of intersection to light source –If ray hits anything before light source, object is in shadow –These are called shadow rays
16
David Luebke2/23/2016 Ray Tracing Overview l Ray tracing is simple –No clipping, perspective projection matrices, scan conversion of polygons l Ray tracing is powerful –Hidden surface problem –Shadow computation –Reflection/refraction l Ray tracing is slow –Complexity proportional to # of pixels –Typical screen ~ 1,000,000 pixels –Typical scene « 1,000,000 polygons
17
David Luebke2/23/2016 Recursive Ray Tracing
18
David Luebke2/23/2016 Recursive Ray Tracing Pixel Image Plane
19
David Luebke2/23/2016 Recursive Ray Tracing “Direct” Ray To Eye
20
David Luebke2/23/2016 Recursive Ray Tracing “Indirect” Ray To Eye
21
David Luebke2/23/2016 Recursive Ray Tracing l Physically, we’re interested in path of light rays from light source to eye. l In practice, we trace rays backwards from eye to source (Why?)
22
David Luebke2/23/2016 Recursive Ray Tracing l Physically, we’re interested in path of light rays from light source to eye. l In practice, we trace rays backwards from eye to source (Why?) –Computational efficiency: we want the finite subset of rays that leave source, bounce around, and pass through eye –Can’t predict where a ray will go, so start with rays we know reach eye
23
David Luebke2/23/2016 Basic Algorithm Function TraceRay() Recursively trace ray R and return resulting color C –if R intersects any objects then n Find nearest object O n Find local color contribution Spawn reflected and transmitted rays, using TraceRay() to find resulting colors n Combine colors; return result –else n return background color
24
David Luebke2/23/2016 Basic Algorithm: Code 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);
25
David Luebke2/23/2016 Basic Algorithm: Code 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
26
David Luebke2/23/2016 Refining the 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
27
David Luebke2/23/2016 Ray-Object Intersection l Given a ray and a list of objects, what objects (if any) intersect the ray? l Query: Does ray R intersect object O? –How to represent ray? –What kind of object? n Sphere n Polygon n Box n General quadric
28
David Luebke2/23/2016 Representing Rays l How might we represent 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
29
David Luebke2/23/2016 Ray-Sphere Intersection Ray R = O + tD x = O x + t D x y = O y + t D y z = O z + t D z l Sphere at (l, m, n) of radius r is: (x - l) 2 + (y - m) 2 + (z - n) 2 = r 2 l Substitute for x,y,z and solve for t…
30
David Luebke2/23/2016 Ray-Sphere Intersection l Works out as a quadratic equation: at 2 + bt + c = 0 where a = D x 2 + D y 2 + D z 2 b = 2D x (O x - l) + 2D y (O y - m) + 2D z (O z - n) c = l 2 + m 2 + n 2 + O x 2 + O y 2 + O z 2 - 2(l O x + m O y + n O z + r 2 )
31
David Luebke2/23/2016 Ray-Sphere Intersection l If solving for t gives no real roots: ray does not intersect sphere l If solving gives 1 real root r, ray grazes sphere where t = r l If solving gives 2 real roots (r 1, r 2 ), ray intersects sphere at t = r 1 & t = r 2 –Ignore negative values –Smallest value is first intersection
32
David Luebke2/23/2016 Ray-Sphere Intersection l Find intersection point P i = (x i, y i, z i ) by plugging t back into ray equation l Find normal at intersection point by subtracting sphere center from P i and normalizing: l When will we need the normal? When not?
33
David Luebke2/23/2016 Ray-Polygon Intersection l Polygons are the most common model representation –Can render in hardware –Lowest common denominator l Basic approach: –Find plane equation of polygon –Find point of intersection between ray and plane –Does polygon contain intersection point?
34
David Luebke2/23/2016 Ray-Polygon Intersection Find plane equation of polygon: ax + by + cz + d = 0 l Remember how? N = [a, b, c] d = N P 1 x y N P1P1 P2P2 d
35
David Luebke2/23/2016 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
36
David Luebke2/23/2016 Ray-Box Intersection l Often want to find whether a ray hits an axis- aligned box (Why?) l One way: –Intersect ray with pairs of parallel planes that form box –If intervals of intersection overlap, the ray intersects the volume.
37
David Luebke2/23/2016 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 Q: how much extra work is involved? l A: each ray-surface intersection now spawns n + 2 rays, n = # light sources –Remember: intersections 95% of work
38
David Luebke2/23/2016 Shadow Rays l Some problems with using shadow rays as described: –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows
39
David Luebke2/23/2016 Shadow Rays l Some problems with using shadow rays as described: –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows
40
David Luebke2/23/2016 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
41
David Luebke2/23/2016 Shadow Rays l Some problems with using shadow rays as described: –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows
42
David Luebke2/23/2016 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?
43
David Luebke2/23/2016 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:
44
David Luebke2/23/2016 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
45
David Luebke2/23/2016 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
46
David Luebke2/23/2016 Shadow Rays l Some problems with using shadow rays as described: –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows
47
David Luebke2/23/2016 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
48
David Luebke2/23/2016 Speedup Techniques l Intersect rays faster l Shoot fewer rays l Shoot “smarter” rays
49
David Luebke2/23/2016 Speedup Techniques l Intersect rays faster l Shoot fewer rays l Shoot “smarter” rays
50
David Luebke2/23/2016 Intersect Rays Faster l Bounding volumes l Spatial partitions l Reordering ray intersection tests l Optimizing intersection tests
51
David Luebke2/23/2016 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
52
David Luebke2/23/2016 Bounding Volumes l Hierarchical bounding volumes –Group nearby volumes hierarchically –Test rays against hierarchy top-down
53
David Luebke2/23/2016 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
54
David Luebke2/23/2016 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
55
David Luebke2/23/2016 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
56
David Luebke2/23/2016 Spatial Partitioning l Example spatial partitions: –Uniform grid (2-D or 3-D) –Octree –k-D tree –BSP-tree
57
David Luebke2/23/2016 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
58
David Luebke2/23/2016 Octree l Octree pros: –Simple to generate –Adaptive l Octree cons: –Nontrivial to trace rays across –Adaptive only in scale
59
David Luebke2/23/2016 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
60
David Luebke2/23/2016 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
61
David Luebke2/23/2016 Reordering Ray Intersection Tests l Caching ray hits (esp. shadow rays) l Memory-coherent ray tracing
62
David Luebke2/23/2016 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
© 2024 SlidePlayer.com. Inc.
All rights reserved.