You are on page 1of 14

10/27/2011

MIT EECS 6.837 Computer Graphics

Part 2 – Rendering
Today: Intro to Rendering, Ray Casting

Cool Artifacts from Assignment 1

NVIDIA

MIT EECS 6.837 – Durand/Matusik

1

2

Cool Artifacts from Assignment 1

Cool Artifacts from Assignment 1

3

4

The Story So Far
• Modeling
– splines, hierarchies, transformations, meshes, etc.

The Remainder of the Term
• Ray Casting and Ray Tracing • Intro to Global Illumination
– Monte Carlo techniques, photon mapping, etc.

• Animation
– quaternions, skinning, ODEs, masses and springs

• Shading, texture mapping
– What makes materials look like they do?

• Now we’ll to see how to generate an image given a scene description!

• • • •
5

Sampling and antialiasing Rasterization, z-buffering Shadow techniques Graphics Hardware
6

[Lehtinen et al. 2008]

1

10/27/2011 Today • What does rendering mean? • Basics of ray casting Scene 7 8 Camera Scene 9 Pixels Camera Image plane Scene 10 Rendering = Scene to Image Image Rendering – Pinhole Camera Image Pixels Camera Image plane Scene 11 Pixels Scene Each pixel corresponds to one ray. 12 2 . We need to figure out which scene point each one hits.

we assume (for now) a single ray per pixel • Major algorithms: Ray casting and rasterization • Note: We are assuming a pinhole camera (for now) 15 16 Questions? Ray Casting • Ray Casting Basics • Camera and Ray Generation • Ray-Plane Intersection • Ray-Sphere Intersection 17 18 3 . need to figure out the visible scene point along each ray – Called “hidden surface problem” in older texts – “Visibility” is a more modern term – Also.10/27/2011 Rendering Image Rendering Image Pixels Scene What’s the color you put in each pixel? 13 Pixels Scene Pixel Color Determined by Lighting/Shading 14 Rendering • “Rendering” refers to the entire process that produces color values for pixels. we assume (for now) a single ray per pixel Rendering • “Rendering” refers to the entire process that produces color values for pixels • Pixels correspond to rays. need to figure out the visible scene point along each ray – Called “hidden surface problem” in older texts – “Visibility” is a more modern term – Also. given a 3D representation of the scene • Pixels correspond to rays.

... • Material Properties – Diffuse (matte) – Specular (shiny) – … • Light properties – Position – Intensity. i. .. Ray Tracing X ? “camera rays” are rays from the camera to the scene 23 ray from light to hit point is blocked.. point is in shadow 24 4 .10/27/2011 Ray Casting For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shading For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shade 19 20 Shading = What Surfaces Look Like • Surface/Scene Properties – surface normal – direction to light – viewpoint L V N Ray Casting vs.e. Ray Tracing • Let’s think about shadows. Ray Tracing Ray Casting vs. Diffuse sphere Specular spheres 21 22 • Much more! Ray Casting vs.

Ray Tracing • Ray casting = eye rays only. refractions Caustics 27 28 Ray Casting For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shade depending on light and normal vector N Ray Representation • Two vectors: – Origin – Direction (normalized is better) How would you represent a ray? • Parametric line – P(t) = origin + t * direction Finding the intersection point and normal is the central part of ray casting P(t) direction origin 29 30 5 . refractions. Secondary Rays Indirect illumination X Reflections Henrik Wann Jensen Refractions We’ll do all this a little later! 25 Shadows 6. doing reflections. tracing = also secondary Secondary rays are used for testing shadows. etc.837 – Durand Caustics 26 26 Ray Tracing Reflections Questions? Reflections.10/27/2011 Ray Casting vs.

16th century • Parametric line – P(t) = origin + t * direction P(t) direction origin 31 32 Dürer’s Ray Casting Machine • Albrecht Dürer.10/27/2011 Ray Representation • Two vectors: – Origin – Direction (normalized is better) Another way to put the ray casting problem statement: Find smallest t > 0 such that P(t) lies on a surface in the scene Dürer’s Ray Casting Machine • Albrecht Dürer. 16th century Ray Casting • Ray Casting Basics • Camera and Ray Generation • Ray-Plane Intersection • Ray-Sphere Intersection 33 34 Cameras For every pixel Construct a ray from the eye For every object in the scene Find intersection with ray Keep if closest Pinhole Camera • Box with a tiny hole • Inverted image • Similar triangles • Perfect image if hole infinitely small • Pure geometric optics • No depth of field issue (everything in focus) 35 36 6 .

abelardomorell. 1545 Also Called “Camera Obscura” 37 38 Camera Obscura Today Simplified Pinhole Camera • Eye-image pyramid (view frustum) • Note that the distance/size of image are arbitrary same image will result on this image plane Abelardo Morell www. v. direction) v Object coordinates World coordinates View coordinates Image coordinates w u 41 42 7 . w (horizontal.10/27/2011 Oldest Illustration • From Gemma Frisius.net 39 40 Camera Description? Camera Description? • Eye point e (center) • Orthobasis u. up.

Ray Generation in 2D p is point on image plane at coordinate x. direction) Field of view angle Image rectangle aspect ratio v Questions? Object coordinates World coordinates View coordinates Image coordinates w u 43 44 Image Coordinates Image plane -1 ≤ y ≤ 1 Convenient to define “normalized image coordinates” such that the x. we want to know the direction of the ray r image plane -1 < x < 1 x p r? view direction w Camera -1 ≤ x ≤ 1 45 field of view α eye point e right u 46 Ray Generation in 2D Ray Generation in 2D image plane -1 < x < 1 1 What is the distance D to the screen so that the normalized coordinates go to 1? view direction w image plane -1 < x < 1 1 D field of view view direction w field of view α right u 47 α right u 48 8 . y coordinates run from -1 to 1 regardless of the dimensions and aspect ratio of the image rectangle. up. w (horizontal. v.10/27/2011 Camera Description? • • • • Eye point e (center) Orthobasis u.

D*w) x then we just normalize r to get the ray image plane -1 < x < 1 p image plane -1 < x < 1 view direction w p r D field of view r D field of view eye point e right u 49 view direction w α α eye point e right u 50 That was 2D. u. Orthographic perspective orthographic • The point of the exercise with computing D was to allow us to use the [-1. except accounting for aspect ratio – r = (x*u. omnimax. 51 • Parallel projection • No foreshortening • No vanishing point 52 Orthographic Camera Other Weird Cameras • E. D*w) – Again. 3D is just as simple • y coordinate is treated just like x.g. D*w) x Ray Generation in 2D r = p-e = (x*u.10/27/2011 Ray Generation in 2D r = p-e = (x*u. aspect*y*v. w are the basis vectors of the view coordinate system – Aspect ratio handles non-square viewports • Think of your 16:9 widescreen TV Perspective vs.1] image coordinate system regardless of field of view. fish eye. v. parabolic • Ray Generation? – Origin = e + x*size*u + y*size*v – Direction is constant: w 53 CAVE Columbia University 54 9 .

y0.C) Po H • Implicit plane equation P' H(p) = d < 0 – H(P) = Ax+By+Cz+D = 0 = n·P + D = 0 P' H(p) = d < 0 59 60 10 . y0. z0) – n = (A.B.B. z0) – n = (A.C) P • (Infinite) plane defined by H P normal Po – Po = (x0.10/27/2011 Questions? Even Funkier Multiperspective Imaging Ray Casting • Ray Casting Basics • Camera and Ray Generation • Ray-Plane Intersection • Ray-Sphere Intersection 55 56 Ray Casting For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Recall: Ray Representation • Parametric line • P(t) = Ro + t * Rd • Explicit representation First we will study ray-plane intersection P(t) direction Rd 57 origin Ro 58 3D Plane Representation? H(p) = d > 0 3D Plane Representation? H(p) = d > 0 normal • (Infinite) plane defined by – Po = (x0.

insert explicit equation of ray into implicit equation of plane & solve for t P(t) = Ro + t * Rd H(P) = n·P + D = 0 n·(Ro + t * Rd) + D = 0 t = -(D + n·Ro) / n·Rd • Plane equation is implicit H(P) = n·P + D = 0 P(t) – Solution of an equation – Does not generate points – Verifies that a point is on the plane Done! • Exercise: Explicit plane and implicit ray? 63 64 Ray-Plane Intersection • Intersection means both are satisfied • So. Implicit? • Ray equation is explicit P(t) = Ro + t * Rd – Parametric – Generates points – Hard to verify that a point is on the ray Ray-Plane Intersection • Intersection means both are satisfied • So.B.10/27/2011 3D Plane Representation? H(p) = d > 0 3D Plane Representation? H(p) > 0 normal • (Infinite) plane defined by – Po = (x0. y0.C) P • (Infinite) plane defined by H P normal Po – Po = (x0.B. z0) – n = (A. insert explicit equation of ray into implicit equation of plane & solve for t P(t) = Ro + t * Rd H(P) = n·P + D = 0 n·(Ro + t * Rd) + D = 0 t = -(D + n·Ro) / n·Rd Additional Bookkeeping • Verify that intersection is closer than previous t < tcurrent t > tmin • Verify that it is not out of range (behind eye) P(t) P(t) Done! What’s the deal when n·Rd = 0? 65 66 11 . y0.C) Po H • Implicit plane equation – H(P) = Ax+By+Cz+D = 0 = n·P + D = 0 – What is D? P' H(p) = d < 0 • Implicit plane equation – H(P) = Ax+By+Cz+D = 0 = n·P + D = 0 P' H(p) < 0 (Point P0 must lie on plane) • Point-Plane distance? – If n is normalized. distance to plane is H(P) – it is a signed distance! 61 62 Explicit vs. z0) – n = (A.

• Lots of cool equivalences – intersection of 3 planes define a point – 3 points define a plane! 69 Questions? 70 Ray Casting • Ray Casting Basics • Camera and Ray Generation • Ray-Plane Intersection • Ray-Sphere Intersection Sphere Representation? • Implicit sphere equation – Assume centered at origin (easy to translate) – H(P) = ||P||2 . C.10/27/2011 Normal • Also need surface normal for shading – (Diffuse: dot product between light direction and normal.r2 = P·P . y. z. D) • Plane equation  dot product • You can map planes to points and points to planes in a dual space.r2 = 0 Rd Ro 71 72 12 . clamp to zero) Questions? • Normal is constant over the plane normal Image by Henrik Wann Jensen 67 68 Math Digression • Duality: points and planes are “dual” when you use homogeneous coordinates • Point (x. B. 1) • Plane (A.

r2 = 0 Ray-Sphere Intersection • Quadratic: at2 + bt + c = 0 – a = 1 (remember. depending on the sign of b2 – 4ac • What do these cases correspond to? • Which root (t+ or t-) should you choose? – Closest positive! Ray-Sphere Intersection • It's so easy that all ray-tracing images have spheres! :-) Turner Whitted 75 76 Sphere Normal • Simply Q/||Q|| – Q = P(t). H(P) = P·P . ||Rd|| = 1) – b = 2Rd·Ro – c = Ro·Ro – r2 • with discriminant • and solutions Rd Ro 73 74 Ray-Sphere Intersection • 3 cases.10/27/2011 Ray-Sphere Intersection • Insert explicit equation of ray into implicit equation of sphere & solve for t .r2 = 0 P(t) = Ro + t*Rd (Ro + tRd) · (Ro + tRd) .r2 = 0 Rd·Rdt2 + 2Rd·Rot + Ro·Ro . intersection point – (for spheres centered at origin) Questions? O Q Rd Ro normal 77 78 13 .

ray tracing NVIDIA MIT EECS 6. let’s watch a cool video! • Next time: Ray-triangle intersection.837 – Durand NVIDIA 79 MIT EECS 6.61 81 14 .93 – Stdev 12. voice up latest next Tuesday(Nov 1st) • Statistics – Mean 56.10/27/2011 That’s All for Today • But before we talk about the quiz.837 – Durand 80 Quiz • Grades are available in Stellar today after class • If you have issues with grading.