6.837-7 Ray Tracing ( Computer Graphics)

Add to Favourites
Post to:

MIT EECS 6.837, Cutler and Durand 1 MIT 6.837 -Ray TracingMIT EECS 6.837, Cutler and Durand 2 Ray TracingMIT EECS 6.837Frédo Durand and Barb CutlerSome slides courtesy of Leonard McMillan Courtesy of James Arvo and David Kirk. Used with permission.MIT EECS 6.837, Cutler and Durand 3 Administrative•Assignment 2–Due tomorrow at 11:59pm•Assignment 3 –Online this evening–Due Wednesday October 1MIT EECS 6.837, Cutler and Durand 4 Review of last week?MIT EECS 6.837, Cutler and Durand 5 Review of last week•Linear, affine and projective transforms•Homogeneous coordinates•Matrix notation•Transformation composition is not commutative•Orthonormalbasis changeMIT EECS 6.837, Cutler and Durand 6 Review of last week•Transformation for ray tracing–Transforming the ray•For the direction, linear part of the transform only–Transforming t or not–Normal transformation•Constructive Solid Geometry (CSG)nWSnWST=nOS(M-1)vWSMIT EECS 6.837, Cutler and Durand 7 Fun with transformations: Relativity•Special relativity: Lorentztransformation–4 vector (t, x, y, z)•4thcoordinate can be ct or t–Lorentztransformation depends on object speed v⎟⎟⎟⎟⎟⎠⎞⎜⎜⎜⎜⎜⎝⎛⎟⎟⎟⎟⎟⎠⎞⎜⎜⎜⎜⎜⎝⎛−−=⎟⎟⎟⎟⎟⎠⎞⎜⎜⎜⎜⎜⎝⎛zyxtvvzyxt100001000000''''γγγγhttp://casa.colorado.edu/~ajsh/sr/sr.shtmlDigressionMIT EECS 6.837, Cutler and Durand 8 Relativity•Transform ray by Lorentztransformation0.65c0.70c0.90c0.99cSee also http://www.cs.mu.oz.au/~andrbh/raytrace/raytrace.htmlDigressionMIT EECS 6.837, Cutler and Durand 9 Today: Ray Tracing Image removed due to copyright considerations.MIT EECS 6.837, Cutler and Durand 10 Overview of today•Shadows•Reflection•Refraction•Recursive Ray Tracing11 Ray Casting (a.k.a. Ray Shooting)For every pixel (x,y)Construct a ray from the eye color[x,y]=castRay(ray)•Complexity?–O(n * m)–n: number of objects, m: number of pixelsMIT EECS 6.837, Cutler and Durand 12 Ray Casting with diffuse shadingColor castRay(ray)Hit hit();For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getColor();For every light Lcol=col+hit->getColorL()*L->getColor*L->getDir()->Dot3( hit->getNormal() );Return col;MIT EECS 6.837, Cutler and Durand 13 Encapsulating shadingColor castRay(ray)Hit hit();For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light Lcol=col+hit->getMaterial()->shade(ray, hit, L->getDir(), L->getColor());Return col;MIT EECS 6.837, Cutler and Durand 14 How can we add shadows?Color castRay(ray)Hit hit();For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light Lcol=col+hit->getMaterial()->shade (ray, hit, L->getDir(), L->getColor());Return col;MIT EECS 6.837, Cutler and Durand 15 ShadowsColor castRay(ray)Hit hit();For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light LRay ray2(hitPoint, L->getDir()); Hit hit2(L->getDist(),,)For every object obob->intersect(ray2, hit2, 0);If (hit->getT> L->getDist())col=col+hit->getMaterial()->shade (ray, hit, L->getDir(), L->getColor());Return col;MIT EECS 6.837, Cutler and Durand 16 Shadows –problem?Color castRay(ray)Hit hit();For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light LRay ray2(hitPoint, L->getDir()); Hit hit2(L->getDist(),,)For every object obob->intersect(ray2, hit2, 0);If (hit->getT> L->getDist())col=col+hit->getMaterial()->shade (ray, hit, L->getDir(), L->getColor());Return col;MIT EECS 6.837, Cutler and Durand 17 Avoiding self shadowingColor castRay(ray)Hit hit();For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light LRay ray2(hitPoint, L->getDir()); Hit hit2(L->getDist(),,)For every object obob->intersect(ray2, hit2, epsilon);If (hit->getT> L->getDist())col=col+hit->getMaterial()->shade (ray, hit, L->getDir(), L->getColor());Return col;MIT EECS 6.837, Cutler and Durand 18 Shadow optimization•Shadow rays are special•How can we accelerate our code?MIT EECS 6.837, Cutler and Durand 19 Shadow optimization•We only want to know whether there is an intersection, not which one is closest•Special routine Object3D::intersectShadowRay()–Stops at first intersectionMIT EECS 6.837, Cutler and Durand 20 Shadow ray casting history•Due to Appel[1968]•First shadow method in graphics•Not really used until the 80sMIT EECS 6.837, Cutler and Durand 21 Questions?Image removed due to copyright considerations.MIT EECS 6.837, Cutler and Durand 22 Overview of today•Shadows•Reflection•Refraction•Recursive Ray TracingMIT EECS 6.837, Cutler and Durand 23 Mirror Reflection•Compute mirror contribution•Cast ray –In direction symmetric wrtnormal•Multiply by reflection coefficient (color)MIT EECS 6.837, Cutler and Durand 24 Mirror Reflection•Cast ray –In direction symmetric wrtnormal•Don’t forget to add epsilon to the rayWithout epsilonWith epsilonMIT EECS 6.837, Cutler and Durand 25 Reflection•Reflection angle = view angleRθVθRVNMIT EECS 6.837, Cutler and Durand 26 Reflection•Reflection angle = view angle()NNVVR􀁇􀁇􀁇􀁇􀁇•−=2RθVθRVNVNNVNNVMIT EECS 6.837, Cutler and Durand 27 Amount of Reflection•Traditional (hacky) ray tracing–Constant coefficient reflectionColor–Component per component multiplicationRθVθRVNMIT EECS 6.837, Cutler and Durand 28 Amount of ReflectionRθVθRVN•More realistic:–Fresnelreflection term–More reflection at grazing angle–Schlick’sapproximation: R(θ)=R0+(1-R0)(1-cos θ)5 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.91 10 20 40 30 50 60 70 80 90 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.91 10 20 40 30 50 60 70 80 90 S Polarization METAL DIELECTRIC (GLASS) P Polarization Unpolarized Reflectance Reflectance Angle from Normal Angle from NormalMIT EECS 6.837, Cutler and Durand 29 Fresnelreflectance demo•Lafortuneet al., Siggraph1997 Image removed due to copyright considerations.MIT EECS 6.837, Cutler and Durand 30 Overview of today•Shadows•Reflection•Refraction•Recursive Ray TracingMIT EECS 6.837, Cutler and Durand 31 Transparency•Compute transmitted contribution•Cast ray –In refracted direction•Multiply by transparency coefficient (color)MIT EECS 6.837, Cutler and Durand 32 Qualitative refraction • From “Color and Light in Nature” by Lynch and LivingstonMIT EECS 6.837, Cutler and Durand 33 RefractionNˆNˆ−MˆTˆIˆiθtθINiˆcosˆ−θiNθcosˆNote that I is the negative of the incoming raySnell-Descartes LawMIT EECS 6.837, Cutler and Durand 34 Refractionrittiηηηθθ==sinsinNˆNˆ−MˆTˆIˆiθtθINiˆcosˆ−θiNθcosˆNote that I is the negative of the incoming raySnell-Descartes LawMIT EECS 6.837, Cutler and Durand 35 RefractionSnell-Descartes LawNMTttˆcosˆsinˆθθ−=iiINMθθsin)ˆcosˆ(ˆ−=NˆNˆ−MˆTˆIˆiθtθINiˆcosˆ−θiNθcosˆNote that I is the negative of the incoming rayrittiηηηθθ==sinsinMIT EECS 6.837, Cutler and Durand 36 RefractionSnell-Descartes LawNMTttˆcosˆsinˆθθ−=iiINMθθsin)ˆcosˆ(ˆ−=NINTtiitˆcos)ˆcosˆ(sinsinˆθθθθ−−=INTrtirˆˆ)coscos(ˆηθθη−−=NˆNˆ−MˆTˆIˆiθtθINiˆcosˆ−θiNθcosˆNote that I is the negative of the incoming rayriittηηηθθ==sinsinMIT EECS 6.837, Cutler and Durand 37 RefractionSnell-Descartes LawNMTttˆcosˆsinˆθθ−=iiINMθθsin)ˆcosˆ(ˆ−=NINTtiitˆcos)ˆcosˆ(sinsinˆθθθθ−−=INTrtirˆˆ)coscos(ˆηθθη−−=NˆNˆ−MˆTˆIˆiθtθINiˆcosˆ−θiNθcosˆNote that I is the negative of the incoming ray))ˆˆ(1(1sin1sin1cosˆˆcos22222ININrirtti⋅−−=−=−=⋅=ηθηθθθrittiηηηθθ==sinsinMIT EECS 6.837, Cutler and Durand 38 RefractionSnell-Descartes LawNMTttˆcosˆsinˆθθ−=iiINMθθsin)ˆcosˆ(ˆ−=NINTtiitˆcos)ˆcosˆ(sinsinˆθθθθ−−=INTrtirˆˆ)coscos(ˆηθθη−−=))ˆˆ(1(1sin1sin1cosˆˆcos22222ININrirtti⋅−−=−=−=⋅=ηθηθθθINININTrrrˆˆ))ˆˆ(1(1)ˆˆ(ˆ22ηηη−⎟⎠⎞⎜⎝⎛⋅−−−⋅=NˆNˆ−MˆTˆIˆiθtθINiˆcosˆ−θiNθcosˆTotal internal reflection when the square root is imaginaryNote that I is the negative of the incoming rayrtiitηηηθθ==sinsinDon’t forget to normalizeMIT EECS 6.837, Cutler and Durand 39 Total internal reflection•From “Color and Light in Nature” by Lynch and Livingstone 97.2o THE OPTICAL MANHOLE. LIGHT FROM THE HORIZON (ANGLE OF INCIDENCE = 90O) IS REFRACTED DOWNWARD AT AN ANGLE OF 48.6O. THIS COMPRESSES THE SKY INTO A CIRCLE WITH A DIAMETER OF 97.2O INSTEAD OF ITS USUAL 180O. O Lynch, David K. and William Livingston. Color and Light in Nature. Cambridge University Press. June 2001. ISBN: 0-521-77504-3. Image adapted from:MIT EECS 6.837, Cutler and Durand 40 Cool refraction demo•Enright, D., Marschner, S. and Fedkiw, R., Image removed due to copyright considerations.MIT EECS 6.837, Cutler and Durand 41 Cool refraction demo•Enright, D., Marschner, S. and Fedkiw, R., Image removed due to copyright considerations.MIT EECS 6.837, Cutler and Durand 42 Refraction and the lifeguard problem•Running is faster than swimming BeachPerson in troubleLifeguardWaterRunSwimDigressionMIT EECS 6.837, Cutler and Durand 43 Wavelength•Refraction is wavelength-dependent•Newton’s experiment•Usually ignored in graphicsMIT EECS 6.837, Cutler and Durand 44 Rainbow•Refraction depends on wavelength•Rainbow is caused by refraction+internal reflection+refraction•Maximum for angle around 42 degreesDigression Image removed due to copyright considerations.MIT EECS 6.837, Cutler and Durand 45 Overview of today•Shadows•Reflection•Refraction•Recursive Ray TracingMIT EECS 6.837, Cutler and Durand 46 Recap: Ray TracingtraceRayIntersect all objectsAmbient shadingFor every lightShadow rayshadingIf mirrorTrace reflected rayIf transparentTrace transmitted rayMIT EECS 6.837, Cutler and Durand 47 Recap: Ray TracingColor traceRay(ray)For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light LIf ( not castShadowRay( hit->getPoint(), L->getDir())col=col+hit->getMaterial()->shade(ray, hit, L->getDir(), L->getColor());If (hit->getMaterial()->isMirror())Ray rayMirror(hit->getPoint(), getMirrorDir(ray->getDirection(), hit->getNormal());Col=col+hit->getMaterial->getMirrorColor()*traceRay(rayMirror, hit2);If (hit->getMaterial()->isTransparent()Ray rayTransmitted(hit->getPoint(), getRefracDir(ray, hit->getNormal(), curentRefractionIndex, hit->Material->getRefractionIndex());Col=col+hit->getMaterial->getTransmittedColor()*traceRay(rayTransmitted, hit3);Return col;MIT EECS 6.837, Cutler and Durand 48 Does it end?Color traceRay(ray)For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light LIf ( not castShadowRay( hit->getPoint(), L->getDir())col=col+hit->getMaterial()->shade(ray, hit, L->getDir(), L->getColor());If (hit->getMaterial()->isMirror())Ray rayMirror(hit->getPoint(), getMirrorDir(ray->getDirection(), hit->getNormal());Col=col+hit->getMaterial->getMirrorColor()*traceRay(rayMirror, hit2);If (hit->getMaterial()->isTransparent()Ray rayTransmitted(hit->getPoint(), getRefracDir(ray, hit->getNormal(), curentRefractionIndex, hit->Material->getRefractionIndex());Col=col+hit->getMaterial->getTransmittedColor()*traceRay(rayTransmitted, hit3);Return col;MIT EECS 6.837, Cutler and Durand 49 Avoiding infinite recursionStopping criteria:•Recursion depth–Stop after a number of bounces•Ray contribution–Stop if transparency/transmitted attenuation becomes too smallUsually do bothColor traceRay(ray)For every object obob->intersect(ray, hit, tmin); Color col=ambient*hit->getMaterial()->getDiffuse();For every light LIf ( not castShadowRay( hit->getPoint(), L->getDir())col=col+hit->getMaterial()->shade(ray, hit, L->getDir(), L->getColor());If (hit->getMaterial()->isMirror())Ray rayMirror(hit->getPoint(), getMirrorDir(ray->getDirection(), hit->getNormal());Col=col+hit->getMaterial->getMirrorColor()*traceRay(rayMirror);If (hit->getMaterial()->isTransparent()Ray rayTransmitted(hit->getPoint(), getRefracDir(ray, hit->getNormal(), curentRefractionIndex, hit->Material->getRefractionIndex());Col=col+hit->getMaterial->getTransmittedColor()*traceRay(rayTransmitted);Return col;MIT EECS 6.837, Cutler and Durand 50 Recursion for reflection1 recursion0 recursion2 recursions (Images removed due to copyright considerations.)MIT EECS 6.837, Cutler and Durand 51 The Ray TreeR2R3L2L1L3N3T1T3EyeL1T3R3L3L2T1R1R2N2R1N1Nisurface normalRireflected rayLishadow rayTitransmitted (refracted) rayEyeMIT EECS 6.837, Cutler and Durand 52 Ray Tracing History•Ray Casting: Appel, 1968•CSG and quadrics: Goldstein & Nagel 1971•Recursive ray tracing: Whitted, 1980 A BC D E Image adapted from: Appel, A. “Some Techniques for Shading Machine Renderings of Solids.” Proceedings of the Spring Joint Computer Conference. 1968, pp. 37-45. Image plane Image removed due to copyright considerations.MIT EECS 6.837, Cutler and Durand 53 Does Ray Tracing simulate physics?•Photons go from the light to the eye, not the other way•What we do is backward ray tracingMIT EECS 6.837, Cutler and Durand 54 Forward ray tracing•Start from the light source•But low probability to reach the eye–What can we do about it?MIT EECS 6.837, Cutler and Durand 55 Forward ray tracing•Start from the light source•But low probability to reach the eye–What can we do about it?–Always send a ray to the eye•Still not efficientMIT EECS 6.837, Cutler and Durand 56 Does Ray Tracing simulate physics?•Ray Tracing is full of dirty tricks •e.g. shadows of transparent objects–Dirtiest: opaque–Still dirty: multiply by transparency color•But then no refractionMIT EECS 6.837, Cutler and Durand 57 Correct transparent shadowDigressionAnimation by HenrikWannJensenUsing advanced refraction technique (refraction for illumination is usually not handled that well) (Image removed due to copyright considerations.)MIT EECS 6.837, Cutler and Durand 58 The Rendering equation•Clean mathematical framework for light-transport simulation•We’ll see that in November•At each point, outgoing light in one directionis the integral of incoming light in all directionsmultiplied by reflectance propertyMIT EECS 6.837, Cutler and Durand 59 Thursday•Reflectance properties, shading and BRDF•Guest lecture r f q q r r n ( ( i i r fr fi fi , , , q q

Description
This lecture notes introduces Shadows, Reflection, Refraction and Recursive Ray Tracing

.“Prof. Frédo Durand & Prof. Barbara ,6.837-7 Ray Tracing , 6.837 Computer Graphics ,Electrical Engineering and Computer Science, Engineering, Massachusetts Institute of Technology: MIT Open Course Ware,http://ocw.mit.edu (22-08-2011).License: Creative Commons BY-NC-SA: http://ocw.mit.edu/terms/#cc

Comments

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
LearnOnline Through OCW
OpenCourseWare
User
102 Followers

Your Facebook Friends on WizIQ

Explore Similar Courses

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect