Presentation is loading. Please wait.

Presentation is loading. Please wait.

David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke

Similar presentations


Presentation on theme: "David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke"— Presentation transcript:

1 David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke cs551dl@cs.virginia.eduhttp://www.cs.virginia.edu/~cs551dl

2 David Luebke3/12/2016 Administrivia Read Chapter 9 Read Chapter 9 Hand out Exercise 1 Hand out Exercise 1 Course action forms Course action forms

3 David Luebke3/12/2016 Illumination Model Recall: color at a surface is given by Recall: color at a surface is given by –Contribution of reflected ray (if any) –Contribution of transmitted ray (if any) –Contribution of local color In a typical ray-tracer, what determines this local color? In a typical ray-tracer, what determines this local color?

4 David Luebke3/12/2016 Illumination Model Local color depends on: Local color depends on: –Which light sources illuminate surface –The characteristics of the light Spectrum (approximated how?) Spectrum (approximated how?) Intensity Intensity –The material properties of the surface Color (diffuse and specular) Color (diffuse and specular) Shininess Shininess –Indirect lighting (approximated how?)

5 David Luebke3/12/2016 Illumination Model Local color depends on: Local color depends on: –Which light sources illuminate surface –The characteristics of the light Spectrum (approximated how?) Spectrum (approximated how?) Intensity Intensity –The material properties of the surface Color (diffuse and specular) Color (diffuse and specular) Shininess Shininess –Indirect lighting (approximated how?)

6 David Luebke3/12/2016 Shadow Rays Simple idea: 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 Q: how much extra work is involved? Q: how much extra work is involved? –A: each ray-surface intersection now spawns n + 2 rays, n = # light sources –Remember: intersections 95% of work

7 David Luebke3/12/2016 Shadow Rays What are some problems with using shadow rays as described? What are some problems with using shadow rays as described? –Lots of computation –Infinitely sharp shadows –No semitransparent object shadows

8 David Luebke3/12/2016 Shadow Ray Problems: Too Much Computation Light buffer (Haines/Greenberg, 86) 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! Light Buffer Occluding Polys Shadow Ray Current Intersection Point

9 David Luebke3/12/2016 Shadow Ray Problems: Sharp Shadows Why are the shadows sharp? Why are the shadows sharp? A: Infinitely small point light sources A: Infinitely small point light sources What can we do about it? What can we do about it? A: Implement area light sources A: Implement area light sources How? How?

10 David Luebke3/12/2016 Shadow Ray Problems: Area Light Sources Could trace a conical beam from point of intersection to light source: Could trace a conical beam from point of intersection to light source: Track portion of beam blocked by occluding polygons: Track portion of beam blocked by occluding polygons: 30% blockage

11 David Luebke3/12/2016 Shadow Ray Problems: Area Light Sources Too hard! Approximate instead: Too hard! Approximate instead: Sample the light source over its area and take weighted average: Sample the light source over its area and take weighted average: 50% blockage

12 David Luebke3/12/2016 Shadow Ray Problems: Area Light Sources Disadvantages: Disadvantages: –Less accurate (50% vs. 30% blockage) –Oops! Just quadrupled (at least) number of shadow rays Moral of the story: Moral of the story: –Soft shadows are very expensive in ray tracing

13 David Luebke3/12/2016 Shadow Ray Problems: Semitransparent Objects In principle: In principle: –Translucent colored objects should cast colored shadows –Translucent curved objects should create refractive caustics In practice: In practice: –Can fake colored shadows by attenuating color with distance –Caustics need backward ray tracing

14 David Luebke3/12/2016 Illumination Model Local color depends on: Local color depends on: –Which light sources illuminate surface –The characteristics of the light Spectrum (approximated how?) Spectrum (approximated how?) Intensity Intensity –The material properties of the surface Color (diffuse and specular) Color (diffuse and specular) Shininess Shininess –Indirect lighting (approximated how?)

15 David Luebke3/12/2016 Illumination Model A simple model based on Phong: A simple model based on Phong: I(P) = I local (P) + k rg (P r ) + kg t (P t ) P : intersection of point being considered P r : first hit of reflected ray from P P t : first hit of transmitted ray from P I local (P) = I a k a + I source [k d (NL) + k rl (NH) ns ] l See chapter 2 for explanation of all these constants and vectors

16 David Luebke3/12/2016 Illumination model l What’s wrong with this model? –Ambient term only “fakes” indirect lighting –Difficulties with soft shadows –Treats specular reflection inconsistently n Phong empirically spreads direct illumination n But traces rays from the eye exactly

17 David Luebke3/12/2016 Practical Ray Tracing Read Chapter 9: Practical Ray Tracing Read Chapter 9: Practical Ray Tracing Summary: Summary: –Ray tracing is too slow –Different methods to speed it up –Ways of using ray tracing selectively

18 David Luebke3/12/2016 Speedup Techniques Intersect rays faster Intersect rays faster Shoot fewer rays Shoot fewer rays Shoot “smarter” rays Shoot “smarter” rays

19 David Luebke3/12/2016 Intersect Rays Faster Bounding volumes Bounding volumes Spatial partitions Spatial partitions Reordering ray intersection tests Reordering ray intersection tests Optimizing intersection tests Optimizing intersection tests

20 David Luebke3/12/2016 Bounding Volumes Bounding volumes 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

21 David Luebke3/12/2016 Bounding Volumes Hierarchical bounding volumes Hierarchical bounding volumes –Group nearby volumes hierarchically –Test rays against hierarchy top-down

22 David Luebke3/12/2016 Bounding Volumes Different bounding volumes Different bounding volumes –Spheres Cheap intersection test Cheap intersection test Poor fit Poor fit Tough to calculate optimal clustering Tough to calculate optimal clustering –Axis-aligned bounding boxes (AABBs) Relatively cheap intersection test Relatively cheap intersection test Usually better fit Usually better fit Trivial to calculate clustering Trivial to calculate clustering

23 David Luebke3/12/2016 Bounding Volumes More bounding volumes More bounding volumes –Oriented bounding boxes (OBBs) Medium-expensive intersection test Medium-expensive intersection test Very good fit (asymptotically better) Very good fit (asymptotically better) Medium-difficult to calculate clustering Medium-difficult to calculate clustering –Slabs (parallel planes) Comparatively expensive Comparatively expensive Very good fit Very good fit Difficult to calculate good clustering Difficult to calculate good clustering

24 David Luebke3/12/2016 Spatial Partitioning Hierarchical bounding volumes surround objects in the scene with (possibly overlapping) volumes Hierarchical bounding volumes surround objects in the scene with (possibly overlapping) volumes Spatial partitioning techniques classify all space into non- overlapping portions Spatial partitioning techniques classify all space into non- overlapping portions

25 David Luebke3/12/2016 Spatial Partitioning Example spatial partitions: Example spatial partitions: –Uniform grid (2-D or 3-D) –Octree –k-D tree –BSP-tree

26 David Luebke3/12/2016 Uniform Grid Uniform grid pros: Uniform grid pros: –Very simple and fast to generate –Very simple and fast to trace rays across (How?) Uniform grid cons: Uniform grid cons: –Not adaptive Wastes storage on empty space Wastes storage on empty space Assumes uniform spread of data Assumes uniform spread of data

27 David Luebke3/12/2016 Octree Octree pros: Octree pros: –Simple to generate –Adaptive Octree cons: Octree cons: –Nontrivial to trace rays across –Adaptive only in scale

28 David Luebke3/12/2016 k-D Trees k-D tree pros: k-D tree pros: –Moderately simple to generate –More adaptive than octrees k-D tree cons: k-D tree cons: –Less efficient to trace rays across –Moderately complex data structure

29 David Luebke3/12/2016 BSP Trees BSP tree pros: BSP tree pros: –Extremely adaptive –Simple & elegant data structure BSP tree cons: BSP tree cons: –Very hard to create optimum BSP –Splitting planes can explode storage –Simple but slow to trace rays across

30 David Luebke3/12/2016 Reordering Ray Intersection Tests Caching ray hits (esp. shadow rays) Caching ray hits (esp. shadow rays) Memory-coherent ray tracing Memory-coherent ray tracing More later… More later…

31 David Luebke3/12/2016 Optimizing Ray Intersection Tests Fine-tune the math! Fine-tune the math! –Share subexpressions –Precompute everything possible Code with care Code with care –Even use assembly, if necessary –Will get its own lecture


Download ppt "David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke"

Similar presentations


Ads by Google