1 / 22

Advanced Computer Graphics Lecture 2: Ray Tracing

Advanced Computer Graphics Lecture 2: Ray Tracing. David Luebke cs551dl@cs.virginia.edu http://www.cs.virginia.edu/~cs551dl. Recursive Ray Tracing. Idea dates back to Descartes (1637) In graphics: Turner Whitted (1980) Used recursive ray tracing as general framework for:

xiang
Télécharger la présentation

Advanced Computer Graphics Lecture 2: Ray Tracing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Computer GraphicsLecture 2: Ray Tracing David Luebke cs551dl@cs.virginia.edu http://www.cs.virginia.edu/~cs551dl David Luebke 6/10/2014

  2. Recursive Ray Tracing • Idea dates back to Descartes (1637) • In graphics: Turner Whitted (1980) • Used recursive ray tracing as general framework for: • Hidden surface problem • Shadow computation • Reflection/refraction • Much work in the 80’s, then fell into academic disfavor (Turner’s old joke) David Luebke 6/10/2014

  3. Recursive Ray Tracing David Luebke 6/10/2014

  4. Recursive Ray Tracing Pixel ImagePlane David Luebke 6/10/2014

  5. Recursive Ray Tracing “Direct” Ray To Eye David Luebke 6/10/2014

  6. Recursive Ray Tracing “Indirect” Ray To Eye David Luebke 6/10/2014

  7. Recursive Ray Tracing • Physically, we’re interested in path of light rays from light source to eye. • In practice, we trace rays backwards from eye to source (Why?) David Luebke 6/10/2014

  8. Recursive Ray Tracing • Physically, we’re interested in path of light rays from light source to eye. • 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 David Luebke 6/10/2014

  9. Basic Algorithm • Function TraceRay() Recursively trace ray Rand return resulting color C • IfRintersects any objects then • Find nearest object O • Find local color contribution • Spawn reflected and transmitted rays, using TraceRay() to find resulting colors • Combine colors; return result • else • return background color David Luebke 6/10/2014

  10. 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); David Luebke 6/10/2014

  11. Basic Algorithm: Code Color TraceRay(Ray R) ifrayHitsObjects(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 returnbackgroundColor David Luebke 6/10/2014

  12. Refining theBasic Algorithm Color TraceRay(Ray R) ifrayHitsObjects(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 returnbackgroundColor David Luebke 6/10/2014

  13. Ray-Object Intersection • Given a ray and a list of objects, what (if any) objects does the ray intersect? • Query: Does ray R intersect object O? • How to represent ray? • What kind of object? • Sphere • Polygon • Box • General quadric David Luebke 6/10/2014

  14. R = O+ tD O t < 0 t = 1 t > 1 D Representing Rays • How might we represent rays? • We represent a ray parametrically: • A starting point O • A direction vector D • A scalar t • Why? David Luebke 6/10/2014

  15. Ray-Sphere Intersection • Ray R = O + tD x = Ox + t * Dx y = Oy + t * Dy z = Oz + t * Dz • Sphere at (l, m, n) of radius r is: (x - l)2 + (y - m)2 + (z - n)2 = r 2 • Substitute for x,y,z and solve for t… David Luebke 6/10/2014

  16. Ray-Sphere Intersection • Works out as a quadratic equation: at2 + bt + c = 0 where a = Dx2 + Dy2 + Dz2 b =2Dx(Ox - l) + 2Dy(Oy - m) + 2Dz(Oz - n) c = l2 + m2 + n2 + Ox2 + Oy2 + Oz2 - 2(l Ox + m Oy + n Oz + r2) David Luebke 6/10/2014

  17. Ray-Sphere Intersection • If solving for t gives no real roots: ray does not intersect sphere • If solving gives 1 real root r, ray grazes sphere where t = r • If solving gives 2 real roots (r1, r2), ray intersects sphere at t = r1& t = r2 • Ignore negative values • Smallest value is first intersection David Luebke 6/10/2014

  18. Ray-Sphere Intersection • Find intersection point Pi = (xi, yi, zi) by plugging t back into ray equation • Find normal at intersection point by subtracting sphere center from Pi and normalizing: (When might we need the normal? When not?) David Luebke 6/10/2014

  19. Ray-Polygon Intersection • Polygons are the most common model representation (Why?) • Basic approach: • Find plane equation of polygon • Find intersection of ray and plane • Does polygon contain intersection point? David Luebke 6/10/2014

  20. y N P2 P1 d x Ray-Polygon Intersection • Find plane equation of polygon:ax + by + cz + d = 0 • How? N = [a, b, c] d = N  P1 (How to find N ?) David Luebke 6/10/2014

  21. Ray-Polygon Intersection • Find intersection of ray and plane: t = -(aOx + bOy + cOz + d) / (aDx + bDy + cDz) • Does poly contain intersection point Pi ? • Book’s algorithm: • Draw line from Pi to each polygon vertex • Measure angles between lines (how?) • If sum of angles between lines is 360°, polygon contains Pi • Slow — better algorithms available David Luebke 6/10/2014

  22. Ray-Box Intersection • Often want to find whether a ray hits an axis-aligned box (Why?) • One way: • Intersect ray with pairs of parallel planes that form box • If intervals of intersection overlap, the ray intersects the volume. David Luebke 6/10/2014

More Related