<<

MIT EECS 6.837 Part 2 – Rendering Today: Intro to Rendering, Ray Casting

© NVIDIA Inc. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. NVIDIA MIT EECS 6.837 – Matusik 1 Cool Artifacts from Assignment 1

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. 2 Cool Artifacts from Assignment 1

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. 3 The Story So Far

• Modeling – splines, hierarchies, transformations, meshes, etc.

• Animation – skinning, ODEs, masses and springs

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

4 The Remainder of the Term • Ray Casting and • Intro to Global Illumination – Monte Carlo techniques, photon mapping, etc. • , – What makes materials look like they do? • Image-based Rendering • Sampling and antialiasing • Rasterization, z-buffering • Shadow techniques • Graphics Hardware

© ACM. All rights reserved. This content is excluded from our Creative Commons [Lehtinen et al. 2008] license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. 5 Today

• What does rendering mean?

• Basics of ray casting

6 © source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. Scene 7 © source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain. Source: openclipart

© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. This content is excluded from our Creative Camera Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. Scene

8 © source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain. Source: openclipart

© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. Pixels Camera Image Scene plane 9 Rendering = Scene to Image

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. Image

This image is in the public domain. Source: openclipart

© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. Camera This content is excluded from our Creative Commons Pixels license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. Image Scene plane

10 Rendering – Pinhole Camera

© source unknown. All rights reserved. This content is excluded from our Creative Image Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain. Source: openclipart

© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. This content is excluded from our Creative Commons Pixels license. For more information, see Each pixel corresponds to http://ocw.mit.edu/help/faq-fair-use/. one ray. We need to figure out which scene point each Scene one hits. 11 Rendering

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, Image see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain. Source: openclipart

© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. This content is excluded from our Creative Commons Pixels What’s the license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. color you put Scene in each pixel?

12 Rendering

© source unknown. All rights reserved. This content is excluded from our Creative Image Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

This image is in the public domain. Source: openclipart

© Oscar Meruvia-Pastor, Daniel Rypl. All rights reserved. Pixel Color This content is excluded from our Creative Commons license. For more information, see Pixels http://ocw.mit.edu/help/faq-fair-use/. Determined by Lighting/Shading Scene 13 Rendering

• “Rendering” refers to the entire process that produces color values for pixels, given a 3D representation of the scene • 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, we assume (for now) a single ray per pixel

14 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, 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 Questions?

16 Ray Casting

• Ray Casting Basics

• Camera and Ray Generation

• Ray-Plane Intersection

• Ray-Sphere Intersection

17 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

18 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 Shading = What Surfaces Look Like • Surface/Scene Properties N – surface normal L – direction to light V – viewpoint • Material Properties – Diffuse (matte) – Specular (shiny) – … • Light properties – Position – Intensity, ... Diffuse sphere Specular spheres • Much more! 20 Ray Casting vs. Ray Tracing

• Let’s think about shadows...

This image is in the public domain. Source: openclipart

21 Ray Casting vs. Ray Tracing

?

“camera rays” This image is in the public domain. are rays from the Source: openclipart camera to the scene

22 Ray Casting vs. Ray Tracing

ray from light to hit point is blocked, i.e., X point is in shadow

This image is in the public domain. Source: openclipart

23 Ray Casting vs. Ray Tracing

• Ray casting = eye rays only, tracing = also secondary

Secondary rays are used for X testing shadows, doing reflections, refractions, etc.

This image is in the public domain. Source: openclipart We’ll do all this a little later!

24 Secondary Rays Indirect illumination

Reflections Refractions

Shadows Caustics Courtesy of Henrik Wann Jensen. Used with permission.

Henrik Wann Jensen Jensen Wann Henrik 25 Ray Tracing Reflections

Courtesy of Henrik Wann Jensen. Used with permission.

Reflections, refractions

© Turner Whitted, Bell Laboratories. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

Caustics © source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. 26 Questions?

27 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 Finding the intersection point and normal is the central part of ray casting

28 Ray Representation

• Origin – Point How would you • Direction – Vector represent a ray? – normalized is better • Parametric line – P(t) = origin + t * direction

P(t)

direction origin

29 Ray Representation

• Origin – Point Another way to put the ray casting • Direction – Vector problem statement: – normalized is better Find smallest t > 0 • Parametric line such that P(t) lies on a surface in the – P(t) = origin + t * direction scene

P(t)

direction origin

30 Dürer’s Ray Casting Machine

• Albrecht Dürer, 16th century

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

31 Dürer’s Ray Casting Machine

• Albrecht Dürer, 16th century

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

32 Ray Casting

• Ray Casting Basics

• Camera and Ray Generation

• Ray-Plane Intersection

• Ray-Sphere Intersection

33 Cameras

For every pixel Construct a ray from the eye For every object in the scene Find intersection with ray Keep if closest

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

34 Pinhole Camera • Box with a tiny hole • Perfect image if hole • Inverted image infinitely small • Similar triangles • Pure geometric optics • No depth of field issue (everything in focus)

35 Oldest Illustration

• From Gemma Frisius, 1545

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

36 Also Called “Camera Obscura”

Image courtesy of Wellcome Library, London. License: CC-BY-NC. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. 37 Camera Obscura Today

Images removed due to copyright restrictions -- please see http://www.abelardomorell.net/photography/cameraobsc_01/cameraobsc_17.html http://www.abelardomorell.net/posts/camera-obscura/ http://www.abelardomorell.net/photography/cameraobsc_49/cameraobsc_63.html for further details.

Abelardo Morell www.abelardomorell.net

38 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

39 Camera Description?

40 Camera Description?

• Eye point e (center) • Orthobasis u, v, w (horizontal, up, direction)

v Object coordinates World w coordinates u View coordinates Image coordinates 41 Camera Description?

• Eye point e (center) • Orthobasis u, v, w (horizontal, up, direction) • Field of view angle • Image rectangle aspect ratio v Object coordinates World w coordinates u View coordinates Image coordinates 42 Image Coordinates Image plane -1 ≤ y ≤ 1

Convenient to define “normalized image coordinates” such that the x, y coordinates run This image is in the public domain. from -1 to 1 Source: openclipart regardless of the Camera dimensions and -1 ≤ x ≤ 1 aspect ratio of the image rectangle. 43 Ray Generation in 2D

p is point on image plane at coordinate x, p x we want to know the image plane direction of the ray r -1 < x < 1 r? view direction w

field of view α eye point e right u

This image is in the public domain. Source: openclipart 44 Ray Generation in 2D

What is the distance 1 image plane D to the screen so -1 < x < 1 that the normalized coordinates go to 1?

view direction w

field of view α right u

This image is in the public domain. Source: openclipart 45 Ray Generation in 2D

1 image plane -1 < x < 1

D view direction w

field of view α right u

This image is in the public domain. Source: openclipart 46 Ray Generation in 2D

r = p-e = (x*u, D*w)

p image plane x -1 < x < 1 r D view direction w

field of view α eye point e right u

This image is in the public domain. Source: openclipart 47 Ray Generation in 2D

r = p-e = (x*u, D*w) then we just normalize r to get the ray p image plane x -1 < x < 1 r D view direction w

field of view α eye point e right u

This image is in the public domain. Source: openclipart 48 That was 2D, 3D is just as simple

• y coordinate is treated just like x, except accounting for aspect ratio – r = (x*u, aspect*y*v, D*w) – Again, u, v, w are the basis vectors of the view coordinate system – Aspect ratio handles non-square viewports • Think of your 16:9 widescreen TV

• The point of the exercise with computing D was to allow us to use the [-1,1] image coordinate system regardless of field of view.

49 Perspective vs. Orthographic

perspective orthographic

• Parallel projection • No foreshortening • No vanishing point

50 Orthographic Camera

• Ray Generation? – Origin = e + x*size*u + y*size*v – Direction is constant: w

51 Other Weird Cameras

• E.g. fish eye, omnimax, parabolic

CAVE Columbia University

© CAVE Lab, Columbia University. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/.

© source unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. 52 Questions?

Even Funkier Multiperspective Imaging

Courtesy of Paul Rademacher. Used with permission. 53 Ray Casting

• Ray Casting Basics

• Camera and Ray Generation

• Ray-Plane Intersection

• Ray-Sphere Intersection

54 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 First we will study ray-plane intersection

55 Recall: Ray Representation

• Parametric line

• P(t) = Ro + t * Rd • Explicit representation

P(t)

direction origin Rd Ro

56 3D Plane Representation?

H(p) = d > 0 • (Infinite) plane defined by P normal –Po = (x0, y0, z0) – n = (A,B,C) Po H

P' H(p) = d < 0

57 3D Plane Representation?

H(p) = d > 0 • (Infinite) plane defined by P normal –Po = (x0, y0, z0) – n = (A,B,C) Po H • Implicit plane equation

– H(P) = Ax+By+Cz+D = 0 P' = n·P + D = 0 H(p) = d < 0

58 3D Plane Representation?

H(p) = d > 0 • (Infinite) plane defined by P normal –Po = (x0, y0, z0) – n = (A,B,C) Po H • Implicit plane equation

– H(P) = Ax+By+Cz+D = 0 P' = n·P + D = 0 H(p) = d < 0 – What is D? (Point P0 must lie on plane)

59 3D Plane Representation?

H(p) > 0 • (Infinite) plane defined by P normal –Po = (x0, y0, z0) – n = (A,B,C) Po H • Implicit plane equation

– H(P) = Ax+By+Cz+D = 0 P' = n·P + D = 0 H(p) < 0 • Point-Plane distance? – If n is normalized, distance to plane is H(P) – it is a signed distance!

60 Explicit vs. Implicit?

• Ray equation is explicit P(t) = Ro + t * Rd – Parametric – Generates points – Hard to verify that a point is on the ray • Plane equation is implicit H(P) = n·P + D = 0 – Solution of an equation – Does not generate points – Verifies that a point is on the plane

• Exercise: Explicit plane and implicit ray?

61 Ray-Plane Intersection

• Intersection means both are satisfied • So, 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 P(t) t = -(D + n·Ro) / n·Rd Done!

62 Ray-Plane Intersection

• Intersection means both are satisfied • So, 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 P(t) t = -(D + n·Ro) / n·Rd Done! What’s the deal when n·Rd = 0?

63 Additional Bookkeeping

• Verify that intersection is closer than previous t < t current • Verify that it is not out of range (behind eye) t > tmin

P(t)

64 Normal

• Also need surface normal for shading – (Diffuse: dot product between light direction and normal, clamp to zero) • Normal is constant over the plane

normal

65 Questions?

Courtesy of Henrik Wann Jensen. Used with permission. Image by Henrik Wann Jensen

66 Ray Casting

• Ray Casting Basics

• Camera and Ray Generation

• Ray-Plane Intersection

• Ray-Sphere Intersection

67 Sphere Representation?

• Implicit sphere equation – Assume centered at origin (easy to translate) – H(P) = ||P||2 - r2 = P·P - r2 = 0

Rd Ro

68 Ray-Sphere Intersection

• Insert explicit equation of ray into implicit equation of sphere & solve for t 2 P(t) = Ro + t*Rd ; H(P) = P·P - r = 0 2 (Ro + tRd) · (Ro + tRd) - r = 0 2 2 Rd·Rdt + 2Rd·Rot + Ro·Ro - r = 0

Rd Ro

69 Ray-Sphere Intersection

• Quadratic: at2 + bt + c = 0

– a = 1 (remember, ||Rd|| = 1)

– b = 2Rd·Ro 2 – c = Ro·Ro – r

• with discriminant

• and solutions

70 Ray-Sphere Intersection

• 3 cases, depending on the sign of b2 – 4ac • What do these cases correspond to? • Which root (t+ or t-) should you choose? – Closest positive!

71 Ray-Sphere Intersection • It's so easy that all ray-tracing images have spheres!

:-)

© source unknown. All rights reserved. This content is excluded from our Creative

Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. Whitted Turner 72 Sphere Normal

• Simply Q/||Q|| – Q = P(t), intersection point – (for spheres centered at origin)

O

R Rd o Q normal

73 Questions?

Courtesy of Henrik Wann Jensen. Used with permission. 74 That’s All for Today

• But before we talk about the quiz, let’s watch a cool video! • Next time: Ray-triangle intersection, ray tracing

© NVIDIA Inc. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. NVIDIA MIT EECS 6.837 – Durand 75 MIT OpenCourseWare http://ocw.mit.edu

6.837 Computer Graphics Fall 2012

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.