Cis005 2 ray-tracing_v2
Upcoming SlideShare
Loading in...5
×
 

Cis005 2 ray-tracing_v2

on

  • 1,702 views

ray tracing

ray tracing

Statistics

Views

Total Views
1,702
Views on SlideShare
1,170
Embed Views
532

Actions

Likes
1
Downloads
14
Comments
0

1 Embed 532

http://aannewball.wikispaces.com 532

Accessibility

Upload Details

Uploaded via

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Cis005 2 ray-tracing_v2 Cis005 2 ray-tracing_v2 Presentation Transcript

  • 1CIS005-2 Computer Graphics Global Illumination Part 1: Ray Tracing Prof. Edmond Prakash Edmond.Prakash@beds.ac.uk CIS005-2 Computer Graphics 2010-2011
  • 2Today’s TopicsPart 1: Fundamentals of Global IlluminationPart 2: Ray tracing ConceptsPart 3: Ray Tracing ProcedurePart 4: Real-time Ray Tracing CIS005-2 Computer Graphics 2010-2011
  • 3 Global IlluminationObservation: light comes from other surfaces, not just designated light sources.Goal: simulate interreflection of light in 3-D scenes.Difficulty: you can no longer shade surfaces one at a time, since they’re now interrelated!Two general classes of algorithms:1. ray tracing methods: simulate motion of photons one by one, tracing photon paths either backwards (“eye ray tracing”) or forwards (“light ray tracing”) -- good for specular scenes2. radiosity methods: set up a system of linear equations whose solution is the light distribution -- good for diffuse scenes CIS005-2 Computer Graphics 2010-2011
  • 4Photo-Realism CIS005-2 Computer Graphics 2010-2011
  • 5Indirect Illumination Color Bleeding CIS005-2 Computer Graphics 2010-2011
  • 6Colour Bleeding CIS005-2 Computer Graphics 2010-2011
  • 7Caustics CIS005-2 Computer Graphics 2010-2011
  • 8Raytracing CIS005-2 Computer Graphics 2010-2011
  • 9Raytraced Images PCKTWTCH by Kevin Odhner, POV-Ray CIS005-2 Computer Graphics 2010-2011
  • 10Kettle,MikeMiller,CIS005-2 Computer GraphicsPOV-Ray 2010-2011
  • 11CIS005-2 Computer Graphics 2010-2011
  • Ray Tracing 12Image copyright Gilles Tran, 2002 - http://hof.povray.org/accident_bleu_1200x1600.html CIS005-2 Computer Graphics 2010-2011
  • 13Today’s TopicsPart 1: Fundamentals of Global IlluminationPart 2: Ray tracing ConceptsPart 3: Ray Tracing ProcedurePart 4: Real-time Ray Tracing CIS005-2 Computer Graphics 2010-2011
  • 14Ray Tracing• What is it?• Why use it?• Basics• Advanced topics• References CIS005-2 Computer Graphics 2010-2011
  • 15Ray-Tracing: Why Use It?• Simulate rays of light• Produces natural lighting effects • Reflection • Depth of Field • Refraction • Motion Blur • Soft Shadows • Caustics CIS005-2 Computer Graphics 2010-2011
  • 16Ray-traced picture CIS005-2 Computer Graphics 2010-2011
  • 17Shadow Rays CIS005-2 Computer Graphics 2010-2011
  • 18Recursive Ray Tracing CIS005-2 Computer Graphics 2010-2011
  • 19Ray-Tracing: Why Use It?• Hard to simulate effects with rasterization techniques (OpenGL)• Rasterizers require many passes• Ray-tracing easier to implement CIS005-2 Computer Graphics 2010-2011
  • 20Ray-Tracing: Who Uses It?• Entertainment (Movies, Commercials)• Games pre-production• Simulation CIS005-2 Computer Graphics 2010-2011
  • 21Ray-Tracing: History• Decartes, 1637 A.D. - analysis of rainbow• Arthur Appel, 1968 - used for lighting 3D models• Turner Whitted, 1980 - “An Improved Illumination Model for Shaded Display” really kicked everyone off.• 1980-until now - Lots of research CIS005-2 Computer Graphics 2010-2011
  • 22The Basics• Generating Rays• Intersecting Rays with the Scene• Lighting• Shadowing• Reflections CIS005-2 Computer Graphics 2010-2011
  • 23Raytracing - Basics• Represent specular global lighting• Trace light backward (usually) from the eye, through the pixel, and into the scene• Recursively bounce off objects in the scene, accumulating a color for that pixel• Final output is a single image of the scene CIS005-2 Computer Graphics 2010-2011
  • 24 The Basic Idea • Simulate light rays from light source to eye Eye Light ed ray Incid ent r tRe flec ay Surface CIS005-2 Computer Graphics 2010-2011
  • 25“Forward” Ray-Tracing• Trace rays from light• Lots of work for little return Light Image Light Rays PlaneEye Object CIS005-2 Computer Graphics 2010-2011
  • 26“Backward” Ray-Tracing• Trace rays from eye instead• Do work where it matters Light Image Plane Eye Object This is what most people mean by “ray tracing”. CIS005-2 Computer Graphics 2010-2011
  • 27 Ray Parametric form • Ray expressed as function of a single parameter (“t”)<x, y, z> = <xo, yo, zo> + t * <xd, yd, zd><x, y, z> = ro + trd t = 2.5 rd = <xd, yd, zd> t = 2.0 t = 1.0 t = 0.0 ro = <xo, yo, zo> CIS005-2 Computer Graphics 2010-2011
  • 28 Generating Rays• Trace a ray for each pixel in the image plane tan(fovx) * 2 Image Plane fovx Eye Eye (Looking down from the top) CIS005-2 Computer Graphics 2010-2011
  • 29 Generating Rays • Trace a ray for each pixel in the image plane(Looking from mthe side) (tan(fovx)* 2) / mEye (tan(fovy)* 2) / n n Image Plane CIS005-2 Computer Graphics 2010-2011
  • 30Today’s TopicsPart 1: Fundamentals of Global IlluminationPart 2: Ray tracing ConceptsPart 3: Ray Tracing ProcedurePart 4: Real-time Ray Tracing CIS005-2 Computer Graphics 2010-2011
  • 31Generating Rays• Trace a ray for each pixel in the image planerenderImage(){ for each pixel i, j in the image ray.setStart(0, 0, 0); // ro ray.setDir ((.5 + i) * tan(fovx)* 2 / m, (.5 + j) * tan(fovy)* 2 / n, 1.0); // rd ray.normalize(); image[i][j] = rayTrace(ray);} CIS005-2 Computer Graphics 2010-2011
  • 32 Triangle Intersection • Want to know: at what point (p) does ray intersect triangle? • Compute lighting, reflected rays, shadowing from that point p rdro <?, ?, ?> (t = ???) CIS005-2 Computer Graphics 2010-2011
  • 33Triangle Intersection• Step 1 : Intersect with plane ( Ax + By + Cz + D = 0 ) Plane normal n = <A, B, C> p rd ro p = -(n. ro + D) / (n. rd ) CIS005-2 Computer Graphics 2010-2011
  • 34 Triangle Intersection • Step 2 : Check against triangle edgesn V1 V0V1 E0 p Ei = ViVi+1 x n (plane A, B, C) V0 di = -A.N (plane D) V2 Plug p into (p. Ei + di ) for each edge if signs are all positive or negative, point is inside triangle! CIS005-2 Computer Graphics 2010-2011
  • 35 Triangle Normals • Could use plane normals (flat shading) • Better to interpolate from vertices nV1 V1 Find areas n nV0 c p a b V0nV2 V2 n = anV0 + bnV1 + cnV2 area(V0V1V2) CIS005-2 Computer Graphics 2010-2011
  • 36Finding Intersections• Check all triangles, keep the closest intersectionhitObject(ray) { for each triangle in scene does ray intersect triangle? if(intersected and was closer) save that intersection if(intersected) return intersection point andnormal} CIS005-2 Computer Graphics 2010-2011
  • 37Lighting• We’ll use triangles for lights – Build complex shapes from triangles• Some lighting termsLight Eye N I R V Surface CIS005-2 Computer Graphics 2010-2011
  • 38Lighting• Use modified Phong lighting – similar to OpenGL – simulates rough and shiny surfaces for each light In = IambientKambient + IdiffuseKdiffuse (L.N) + IspecularKspecular (R.V)n CIS005-2 Computer Graphics 2010-2011
  • 39 Ambient Light • Iambient Simulates the indirect lighting in a scene.Eye Light CIS005-2 Computer Graphics 2010-2011
  • 40Diffuse Light• Idiffuse simulates direct lighting on a rough surface• Viewer independent• Paper, rough wood, brick, etc... Eye Light CIS005-2 Computer Graphics 2010-2011
  • 41Specular Light• Ispecular simulates direct lighting on a smooth surface• Viewer dependent• Plastic, metal, polished wood, etc... Eye Light CIS005-2 Computer Graphics 2010-2011
  • 42Shadow Test• Check against other objects to see if point is shadowed Eye Shadowing Object CIS005-2 Computer Graphics 2010-2011
  • 43Reflection• Angle of incidence = angle of reflection ( θI = θR )• I, R, N lie in the same plane N I θI θR R . R = I - 2 (N I) N CIS005-2 Computer Graphics 2010-2011
  • 44Putting It All Together• Recursive ray evaluationrayTrace(ray) { hitObject(ray, p, n, triangle); color = object color; if(object is light) return(color); else return(lighting(p, n, color));} CIS005-2 Computer Graphics 2010-2011
  • 45Putting It All Together• Calculating surface colorlighting(point) { color = ambient color; for each light if(hitObject(shadow ray)) color += lightcolor * dot(shadow ray, n); color += rayTrace(reflection) * pow(dot(reflection, ray), shininess); return(color);} CIS005-2 Computer Graphics 2010-2011
  • 46Putting It All Together• The main programmain() { triangles = readTriangles(); image = renderImage(triangles); writeImage(image);} CIS005-2 Computer Graphics 2010-2011
  • 47This is A Good Start• Lighting, Shadows, Reflection are enough to make some compelling images• Want better lighting and objects• Need more speed CIS005-2 Computer Graphics 2010-2011
  • 48More Quality, More Speed• Better Lighting + Forward Tracing• Motion Blur, Depth of Field, Blurry Reflection/Refraction – Distributed Ray-Tracing• Improving Image Quality• Acceleration Techniques CIS005-2 Computer Graphics 2010-2011
  • 49Refraction• Keep track of medium (air, glass, etc)• Need index of refraction (η )• Need solid objectssin(θ I)= η 1 Nsin(θ T) η2 I θI Medium 1 (e.g. air) Medium 2 T (e.g. water) θT CIS005-2 Computer Graphics 2010-2011
  • 50Refraction CIS005-2 Computer Graphics 2010-2011
  • 51Improved Light Model• Cook & Torrance – Metals have different color at angle – Oblique reflections leak around corners – Based on a microfacet model CIS005-2 Computer Graphics 2010-2011
  • 52Using “Forward” Ray Tracing• Backward tracing doesn’t handle indirect lighting too well• To get caustics, trace forward and store results in texture map. CIS005-2 Computer Graphics 2010-2011
  • 53Using “Forward” Ray Tracing CIS005-2 Computer Graphics 2010-2011
  • 54Distributed Ray Tracing• Average multiple rays instead of just one ray• Use for both shadows, reflections, transmission (refraction)• Use for motion blur• Use for depth of field CIS005-2 Computer Graphics 2010-2011
  • 55Supersampling I• Problem: Each pixel of the display represents one single ray – Aliasing – Unnaturally sharp images• Solution: Send multiple rays through each “pixel” and average the returned colors together CIS005-2 Computer Graphics 2010-2011
  • 56 Supersampling II• Direct supersampling – Split each pixel into a grid and send rays through each grid point• Adaptive supersampling – Split each pixel only if it’s significantly different from its neighbors• Jittering – Send rays through randomly selected points within the pixel CIS005-2 Computer Graphics 2010-2011
  • 57Soft Shadows• Basic shadow generation was an on/off choice per point• “Real” shadows do not usually have sharp edges• Instead of using a point light, use an object with area• Shoot jittered shadow rays toward the light and count only those that hit it CIS005-2 Computer Graphics 2010-2011
  • 58 Soft Shadow Example Hard shadow Hard shadow Soft shadow Soft shadowFrom: http://www.cs.unc.edu/~andrewz/comp238/hw2/ CIS005-2 Computer Graphics 2010-2011
  • 59Raytraced Cornell Box Which paths are missing?Ray-traced Cornell box, due to Henrik Jensen, CIS005-2 Computer Graphicshttp://www.gk.dtu.dk/~hwj 2010-2011
  • 60A Better Rendered Cornell Box CIS005-2 Computer Graphics 2010-2011
  • 61Distributed Ray Tracing CIS005-2 Computer Graphics 2010-2011
  • 62Distributed Ray Tracing• One ray is not enough (jaggies)• Can use multiple rays per pixel - supersampling• Can use a few samples, continue if they’re very different - adaptive supersampling• Texture interpolation & filtering CIS005-2 Computer Graphics 2010-2011
  • 63Today’s TopicsPart 1: Fundamentals of Global IlluminationPart 2: Ray tracing ConceptsPart 3: Ray Tracing ProcedurePart 4: Real-time Ray Tracing CIS005-2 Computer Graphics 2010-2011
  • 64Raytracing - Pros • Simple idea and nice results • Inter-object interaction possible – Shadows – Reflections – Refractions (light through glass, etc.) • Based on real-world lighting CIS005-2 Computer Graphics 2010-2011
  • 65Raytracing - Cons• Takes a long time• Computation speed-ups are often highly scene-dependent• Lighting effects tend to be abnormally sharp, without soft edges, unless more advanced techniques are used• Hard to put into hardware CIS005-2 Computer Graphics 2010-2011
  • 66Acceleration• 1280x1024 image with 10 rays/pixel• 1000 objects (triangle, CSG, NURBS)• 3 levels recursion39321600000 intersection tests 100000 tests/second -> 109 days!Must use an acceleration method! CIS005-2 Computer Graphics 2010-2011
  • 67Bounding volumes• Use simple shape for quick test, keep a hierarchy CIS005-2 Computer Graphics 2010-2011
  • 68Space Subdivision• Break your space into pieces• Search the structure linearly CIS005-2 Computer Graphics 2010-2011
  • 69Parallel Processing• You can always throw more processors at it. CIS005-2 Computer Graphics 2010-2011
  • 70Really Advanced Stuff• Error analysis• Hybrid radiosity/ray-tracing• Metropolis Light Transport• Memory-Coherent Ray-tracing CIS005-2 Computer Graphics 2010-2011
  • 71References• Introduction to Ray-Tracing, Glassner et al, 1989, ISBN 0-12-286160-4• Advanced Animation and Rendering Techniques, Watt & Watt, 1992, ISBN 0-201-54412-1• Computer Graphics: Image Synthesis, Joy et al, 1988, ISBN 0-8186-8854-4• SIGGRAPH Proceedings• Ray Tracing explained http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtrace0.htm CIS005-2 Computer Graphics 2010-2011