Upcoming SlideShare
×

CS 354 Ray Casting & Tracing

3,367 views
3,195 views

Published on

April 17, 2012; CS 354 Computer Graphics; University of Texas at Austin

Published in: Technology, Art & Photos
4 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

Views
Total views
3,367
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
123
0
Likes
4
Embeds 0
No embeds

No notes for slide

CS 354 Ray Casting & Tracing

1. 1. CS 354Ray Casting & TracingMark KilgardUniversity of TexasApril 17, 2012
2. 2. CS 354 2 Today’s material  In-class quiz  On typography lecture  Lecture topic  Finish digital typography  Project 3  Ray tracing & casting
3. 3. CS 354 3 My Office Hours  Tuesday, before class  Painter (PAI) 5.35  8:45 a.m. to 9:15  Thursday, after class  ACE 6.302  11:00 a.m. to 12  Randy’s office hours  Monday & Wednesday  11 a.m. to 12:00  Painter (PAI) 5.33
4. 4. CS 354 4 Last time, this time  Last lecture, we discussed  Digital typography  This lecture  Ray casting and tracing  Projects  Project 3 due Wednesday, April 18, 2012  Tomorrow!  Project 4 on ray tracing on Piazza
5. 5. CS 354 5 On a sheet of paper Daily Quiz • Write your EID, name, and date • Write #1, #2, #3, #4 followed by its answer  Multiple choice: Pica and Em are:  Multiple choice: Unicode supports how many character points? a) Names of two commonly used type faces a) 256 b) Units of typographic b) 65,536 measurement c) Over ¼ million c) Two dominant types of Bezier curves d) 4,294,967,296 d) Graphics researchers  Multiple choice: Kerning responsible for font hinting adjusts what property of text? a) Spacing between characters  True or False: This text is written in a serif type face. b) Whether accent marks are included on glyphs c) Control of vertical layout
6. 6. CS 354 6 Project 3  Accept Biovision Hierarchy (BVH) files containing motion capture data  Hierarchy of affine transformations  Visualize a stick figure  Animate the figure
7. 7. CS 354 7 Rendering Outline Glyphs  Conventional method  CPU-based scan-line rasterization  Augmented by hinting  Adaptively Sampled Distance Fields (ADFs)  MERL’s Saffron type system  Glyphs are static so pre-computation is effective  Bitmaps often cached
8. 8. CS 354 8 Massively Parallel GPU-accelerated Path Rendering Visualized Anchored triangle Anchored triangle fans geometry fans net stencil Stencil =1 Path commands and control points Resulting net coverage in stencil Curved segment Curved segment geometry net stencil Stencil -1 Stencil +1Credit: [Kokoji 2006]
9. 9. CS 354 9 OpenGL Bitmap Fonts  GLUT includes implementation  glutBitmapCharacter  Calls glBitmap with pre-compiled bitmap data  Also window system specific routines to get bitmaps from system fonts  wglUseFontBitmaps for Windows  glXUseXFont for X Window System (Linux)
10. 10. CS 354 10 OpenGL Stroke Fonts  Draw glyph’s stroke as line segments  Can transform arbitrarily  Use glEnable(GL_LINE_SMOOTH) for anti-aliasing  glutStrokeCharacter does this
11. 11. CS 354 11 Other Text Approaches  Pack glyphs in texture atlas  Then draw textured rectangles with the correct texture coordinates for each glyph
12. 12. CS 354 12 First-class Text Support in Various Rendering Systems Rendering system Vendor / Sponsor First-class text? Cairo Open source Yes Direct2D / Direct3D Microsoft Yes Flash Adobe Yes GDI Microsoft Yes Java 2D Sun Yes OpenGL Khronos No OpenVG Khronos Yes Office Open XML Microsoft / ECMA Yes PDF Adobe Yes PHIGS ISO Yes PostScript Adobe Yes Qt Nokia Yes Quart 2D Apple Yes Scalable Vector Graphics (SVG) World Wide Web Consortium Yes Silverlight Microsoft Yes Xlib X Consortium Yes
13. 13. CS 354 13 How did OpenGL’s lack of text support last for so long?  OpenGL was designed in 1992  Pre-Unicode world  Fonts were bitmaps of ASCII back then  Now TrueType and OpenType dominate  The primitive initial state of OpenGL’s font support has become mistaken for a philosophical dictate  Text-based applications uniformly ignore OpenGL  Not a good thing  3D applications have their expectations adjusted to expect lousy text  Not a good thing  Example: Quake 2 console text is miniscule because textured bitmap characters assumed text sized for 800x600 display
14. 14. CS 354 14 The World Has Changed Since 1992  Unicode universally accepted now  Systems ship with near-complete, resolution-independent Unicode fonts now  Good fonts come with your operating system license  International character of web makes UTF-8 text common today  Windows adoption of UTF-16 makes that common within Windows  Web has expanded font repertoire of systems  Content providers and users expect wide range of available fonts  Fonts have standard names embedded in web content  These font names span operating systems  Screen resolution has increased  1992: 640x480 aliased  2009: 1920x1200+ multisampled  Needing all text to be in small point sizes to fit screen isn’t a mandate anymore  3D support and acceleration is pervasive now  Text makes sense mixed with 3D content today
15. 15. CS 354 15 Direct Path Rendering of Text in OpenGL  Recent work  NV_path_rendering provides GPU-acceleration of paths, including glyphs  Glyph support is first-class
16. 16. CS 354 16 Digital Typography Trends  Hinting & ClearType likely going away  Mainly due to denser screens  Expectation of antialiased font appearance  Text not always presented axis-aligned or black-on-white  More font variety in web content  Improving standards  More available fonts  Even font variety for East Asian writing systems
17. 17. CS 354 17 OpenGL’s Realism Limitations  OpenGL is based on a pipeline model in which primitives are rendered one at time  No automatic shadows (except by tricks or multiple renderings)  No automatic multiple reflections  Multi-pass algorithms for shadows and reflections  Physically plausible & global approaches  Rendering equation  Ray tracing  Radiosity 17
18. 18. CS 354 18 Ray Casting  Arthur Appel (1968)  Cast rays from eye… what object is hit?
19. 19. CS 354 19 Ray Tracing  “An Improved Illumination Model for Shaded Display”  Turner Whitted (1980)  Communications of the ACM  Performance  512x512 pixels  74 Minutes on VAX (1979)  6 seconds on PC (2006)  60+ frames/second on GPU (2012)
20. 20. CS 354 20 Ray Tracing  Follow rays of light from a point source  Can account for reflection and transmission 20
21. 21. CS 354 21 Example of Complex Ray Traced Scene
22. 22. CS 354 22 Computational Limits of Ray Tracing  Should be able to handle all physical interactions  Ray tracing paradigm is physically plausible  But most rays do not affect what we see  Scattering produces many (infinite) additional rays  Alternative: ray casting 22
23. 23. CS 354 23 Ray Casting  Only rays that reach the eye matter  Reverse direction and cast rays  Need at least one ray per pixel 23
24. 24. CS 354 24 Ray Casting Quadrics  Ray casting has become a standard way to visualize quadrics which are implicit surfaces in CSG systems  Constructive Solid Geometry  Primitives are solids  Build objects with set operations  Union, intersection, set difference 24
25. 25. CS 354 25 Ray Casting a Sphere  Ray is parametric  Sphere is quadric  Resulting equation is a scalar quadratic equation which gives entry and exit points of ray (or no solution if ray misses) 25
26. 26. CS 354 26 Shadow Rays  Even if a point is visible, it will not be lit unless we can see a light source from that point  Cast shadow or feeler rays 26
27. 27. CS 354 27 Reflection  Must follow shadow rays off reflecting or transmitting surfaces  Process is recursive 27
28. 28. CS 354 28 Reflection and Transmission 28
29. 29. CS 354 29 Ray Trees 29
30. 30. CS 354 30 Ray Tree 30
31. 31. CS 354 31 Diffuse Surfaces  Theoretically the scattering at each point of intersection generates an infinite number of new rays that should be traced  In practice, we only trace the transmitted and reflected rays but use the Phong model to compute shade at point of intersection  Radiosity works best for perfectly diffuse (Lambertian) surfaces 31
32. 32. CS 354 32 Building a Ray Tracer  Best expressed recursively  Can remove recursion later  Image based approach  For each ray …….  Find intersection with closest surface  Need whole object database available  Complexity of calculation limits object types  Compute lighting at surface  Trace reflected and transmitted rays 32
33. 33. CS 354 33 More bounces When to stop  Some light will be absorbed at each intersection  Track amount left  Ignore rays that go off to infinity  Put large sphere around problem  Count steps Fewer bounces 33
34. 34. CS 354 34 Recursive Ray Tracer color c = trace(point p, vector d, int step) { color local, reflected, transmitted; point q; normal n; if(step > max) return(background_color); 34
35. 35. CS 354 35 Recursive Ray Tracer q = intersect(p, d, status); if(status==light_source) return(light_source_color); if(status==no_intersection) return(background_color); n = normal(q); r = reflect(q, n); t = transmit(q,n); 35
36. 36. CS 354 36 Recursive Ray Tracer local = phong(q, n, r); reflected = trace(q, r, step+1); transmitted = trace(q,t, step+1); return(local+reflected+transmitted); 36
37. 37. CS 354 37 Computing Intersections  Implicit Objects  Quadrics  Planes  Polyhedra  Parametric Surfaces 37
38. 38. CS 354 38 Implicit Surfaces Ray from p0 in direction d p(t) = p0 +t d General implicit surface f(p) = 0 Solve scalar equation f(p(t)) = 0 General case requires numerical methods 38
39. 39. CS 354 39 Quadrics General quadric can be written as pTAp + bTp +c = 0 Substitute equation of ray p(t) = p0 +t d to get quadratic equation 39
40. 40. CS 354 40 Sphere (p – pc) • (p – pc) – r2 = 0 p(t) = p0 +t d p0 • p0 t2+ 2 p0 • (d – p0) t + (d – p0) • (d – p0) – r2 = 0 40
41. 41. CS 354 41 Planes p•n+c=0 p(t) = p0 +t d t = -(p0 • n + c)/ d • n 41
42. 42. CS 354 42 Implicit Surface Ray Tracing Example  Paul Heckbert 1983
43. 43. CS 354 43 Polyhedra  Generally we want to intersect with closed objects such as polygons and polyhedra rather than planes  Hence we have to worry about inside/outside testing  For convex objects such as polyhedra there are some fast tests 43
44. 44. CS 354 44 Ray Tracing Polyhedra  If ray enters an object, it must enter a front facing polygon and leave a back facing polygon  Polyhedron is formed by intersection of planes  Ray enters at furthest intersection with front facing planes  Ray leaves at closest intersection with back facing planes  If entry is further away than exit, ray must miss the polyhedron 44
45. 45. CS 354 45 Ray Tracing Polyhedra 45
46. 46. CS 354 46 Ray Tracing a Polygon 46
47. 47. CS 354 47 Ray Tracing a Polygon 47
48. 48. CS 354 48 Algorithmic Complexity of Ray Tracing  Time complexity  Rasterization: O(b • m)  coherent!  Naïve ray tracing: O(b • p)  Accelerated ray tracing: O(log b • p)  incoherent  Key  b = # of objects in the scene  p = # of pixels in the scene  m = average # of pixels per object
49. 49. CS 354 49 Real-time Ray Tracing  GPUs doing ray tracing  General purpose compute on GPUs [Optix, NVIDIA, SIGGRAPH 2009]
50. 50. CS 354 50 Ray Tracing Quality  Aliasing is a problem in ray tracing  Spatial and temporal  Spatial anti-aliasing  Average over several samples per pixel 1 sample 5x5 grid 5x5 jittered grid
51. 51. CS 354 51 Distribution Ray Tracing  Spatial anti-aliasing 1 sample per pixel multiple samples per pixel
52. 52. CS 354 52 Distribution Ray Tracing  Soft shadows  Distribute shadow rays over light source region All shadow rays No shadow rays Some shadow rays hit light source, hit light source, hit light source, fully illuminated fully shadowed partially shadowed
53. 53. CS 354 53 Soft Shadows Example  Multiple ray tracing effects  Including soft shadows
54. 54. CS 354 54 Distribution Ray Tracing  Motion blur  Distribute rays over time Pool Balls Tom Porter RenderMan
55. 55. CS 354 55 Distribution Ray Tracing  Depth of field  Distribute rays across a discrete camera aperture No depth-of-field More rays Jittered depth-of-field More images for depth-of-field Even more rays
56. 56. CS 354 56 Next Class  Next lecture  Global illumination  How is the complex interaction of light within a scene realistically modeled?  Reading: Chapter 11, 559-568  Project 3  Due tomorrow—Wednesday, April 18, 2012  Next up: Project 4 is a simple ray tracer  Due May 2, 2012
57. 57. CS 354 57 Credits • Ed Angel and Dave Shreiner: Interactive Computer Graphics 6E © Addison-Wesley (2012) • Pat Hanrahan • Paul Heckbert