11 ray tracing - computer science at · pdf file1 ray tracing announcements: quiz • on...

8
1 Ray Tracing Announcements: Quiz On Tuesday (2/24), in class One 8.5x11 sheet of notes allowed Sample quiz (from prior year) is posted online Mostly “reading comprehension” (?) Will be curved Send Barb email if you have any questions about the quiz Announcements: Final Projects Everyone should post one or more ideas for a final project on the discussion forum Connect with potential teammates (teams of 2 recommended) Start reading background papers Detailed proposal & summary of background research due March 19 th Last Time? Rigid Body Finite Element Method – Stress/Strain • Fracture • Deformation – Level of Detail – Haptics Today Ray Casting Ray-Plane Intersection Ray-Sphere Intersection Point in Polygon Ray Tracing Recursive Ray Tracing Distribution Ray Tracing Durer’s Ray Casting Machine Albrecht Durer, 16 th century

Upload: hanhu

Post on 10-Feb-2018

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

1

Ray Tracing

Announcements: Quiz •  On Tuesday (2/24), in class •  One 8.5x11 sheet of notes allowed •  Sample quiz (from prior year) is posted online •  Mostly “reading comprehension” (?) •  Will be curved

•  Send Barb email if you have any questions about the quiz

Announcements: Final Projects •  Everyone should post one or more ideas for a

final project on the discussion forum •  Connect with potential teammates

(teams of 2 recommended) •  Start reading background papers •  Detailed proposal & summary of background

research due March 19th

Last Time? •  Rigid Body •  Finite Element Method

–  Stress/Strain •  Fracture •  Deformation

– Level of Detail – Haptics

Today •  Ray Casting

– Ray-Plane Intersection – Ray-Sphere Intersection – Point in Polygon

•  Ray Tracing •  Recursive Ray Tracing •  Distribution Ray Tracing

Durer’s Ray Casting Machine •  Albrecht Durer, 16th century

Page 2: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

2

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

Finding the intersection and normal is the central

part of ray casting

A Note on Local Shading •  Surface/Scene Characteristics:

–  surface normal –  direction to light –  viewpoint

•  Material Properties –  Diffuse (matte) –  Specular (shiny) –  …

•  More later!

Diffuse sphere Specular spheres

N L

V

Ray Representation? •  Two vectors:

– Origin – Direction (normalized is better)

•  Parametric line (explicit representation) – P(t) = origin + t * direction

origin direction

P(t)

3D Plane Representation? •  Plane defined by

– Po = (x,y,z) – n = (A,B,C)

•  Implicit plane equation – H(P) = Ax+By+Cz+D = 0

= n·P + D = 0 •  Point-Plane distance?

–  If n is normalized, distance to plane, d = H(P)

– d is the signed distance!

H Po

normal P

P' H(p) = d < 0

H(p) = d > 0

Explicit vs. Implicit? •  Ray equation is explicit P(t) = Ro + t * Rd

– Parametric – Generates points – Harder 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

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 t = -(D + n·Ro) / n·Rd P(t)

Page 3: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

3

Additional Housekeeping •  Verify that intersection is closer than previous

•  Verify that it is not out of range (behind eye) P(t) > tmin

P(t) < tcurrent

P(t)

Normal •  For shading

– diffuse: dot product between light and normal •  Normal is constant

normal

Ray-Triangle Intersection •  Use barycentric coordinates:

– P(α, β, γ) = αa + βb + γc with α + β + γ =1

–  If 0 < α < 1 & 0 < β < 1 & 0 < γ < 1 then the point is inside the triangle!

Ro Rd

c

a b

P

How Do We Compute α, β, γ ?

•  Ratio of opposite sub-triangle area to total area –  α = Aa/A β = Ab/A γ = Ac/A

•  Use signed areas for points outside the triangle

c

a b

P

Aa A

Using Cramer’s Rule…

A

R R a b a

R R a b a

R R a b a

dz oz z z z

dy oy y y y

dx ox x x x

- -

- -

- -

= γ

A

R a c a b a

R a c a b a

R a c a b a

t oz z z z z z

oy y y y y y

ox x x x x x

- - -

- - -

- - -

=

A

R c a R a

R c a R a

R c a R a

dz z z oz z

dy y y oy y

dx x x ox x

- -

- -

- -

= β

| | denotes the determinant

Can be copied mechanically

into code

•  Used to solve for one variable at a time in system of equations

Sphere Representation? •  Implicit sphere equation

– Assume centered at origin (easy to translate) – H(P) = P·P - r2 = 0

Rd Ro

Page 4: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

4

Ray-Sphere Intersection •  Insert explicit equation of ray into

implicit equation of sphere & solve for t

P(t) = Ro + t*Rd H(P) = P·P - r2 = 0 (Ro + tRd) · (Ro + tRd) - r2 = 0 Rd·Rdt2 + 2Rd·Rot + Ro·Ro - r2 = 0

Rd Ro

Ray-Sphere Intersection •  Quadratic: at2 + bt + c = 0

–  a = 1 (remember, ||Rd|| = 1) – b = 2Rd·Ro –  c = Ro·Ro – r2

•  with discriminant

•  and solutions

•  What does it mean if there are no solutions, 1 solution, or 2 solutions?

Questions?

depth normals local shading

Today •  Ray Casting •  Ray Tracing

– Shadows

– Reflection

– Refraction

•  Recursive Ray Tracing •  Distribution Ray Tracing

Find the point to be shaded For every light, Construct ray from point to light For every object find intersection of ray with object If no objects between point and light Add contribution from light

How Can We Add Shadows? Mirror Reflection •  Cast ray symmetric with

respect to the normal •  Multiply by reflection

coefficient (color)

Page 5: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

5

Reflection •  Reflection angle = view angle •  R = V – 2 (V · N) N

R V θ V θ R

N

V N N

V N N

V

Transparency •  Cast ray in refracted direction •  Multiply by transparency coefficient (color)

Qualitative Refraction

From “Color and Light in Nature” by Lynch and Livingston

Refraction I = N cos Өi – M sin Өi

M = (N cos Өi – I) / sin Өi

T = – N cos ӨT + M sin ӨT

= – N cos ӨT + (N cos Өi – I) sin ӨT / sin Өi = – N cos ӨT + (N cos Өi – I) ηr

= [ ηr cos Өi – cos ӨT ] N – ηr I

= [ ηr cos Өi – √1 – sin2 ӨT ] N – ηr I

= [ ηr cos Өi – √1 – ηr2 sin2 Өi ] N – ηr I

= [ ηr cos Өi – √1 – ηr2 (1 – cos2 Өi ) ] N – ηr I

= [ ηr (N · I) – √1 – ηr2 (1 – (N · I)2 ) ] N – ηr I

I

T

Өi

ӨT

N

-N

M ηT

ηi

Snell-Descartes Law: ηi sin Өi = ηT sin ӨT

sin ӨT ηi = = ηr sin Өi ηT •  Total internal reflection when

the square root is imaginary •  Don’t forget to normalize!

N cos Өi

– M sin Өi

•  Make sure you know whether you’re entering or leaving the transmissive material:

•  What about intersecting transparent objects?

Refraction & the Sidedness of Objects

T

ηT = material index

ηi=1

N

T

ηT= 1

ηi = material index

N

I I

Total Internal Reflection

From “Color and Light in Nature” by Lynch and Livingston

Page 6: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

6

Questions? Readings for Friday 2/20: •  "An improved illumination model for

shaded display" Turner Whitted, 1980. •  "Distributed Ray Tracing", Cook,

Porter, & Carpenter, SIGGRAPH 1984. •  "Interactive Depth of Field", Kass,

Lefohn, and Owens, Pixar TR 2006.

Today •  Ray Casting •  Ray Tracing •  Recursive Ray Tracing •  Distribution Ray Tracing

Stopping criteria: •  Recursion depth

–  Stop after a number of bounces

•  Ray contribution –  Stop if reflected /

transmitted contribution becomes too small

trace ray Intersect all objects color = ambient term For every light

cast shadow ray color += local shading term

If mirror color += colorrefl * trace reflected ray

If transparent color += colortrans * trace transmitted ray

•  Does it ever end?

Recap: Ray Tracing

The Ray Tree

R2

R1 R3

L2

L1 L3 N1

N2

N3

T1

T3

Ni surface normal Ri reflected ray Li shadow ray Ti transmitted (refracted) ray

Eye

L1

T3 R3

L3 L2

T1 R1

R2 Eye

Complexity?

Ray Debugging •  Visualize the ray tree for single image pixel

incoming reflected ray shadow ray transmitted (refracted) ray

Page 7: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

7

Today •  Ray Casting •  Ray Tracing •  Recursive Ray Tracing •  Distribution Ray Tracing

– Soft shadows – Antialiasing (getting rid of jaggies) – Glossy reflection – Motion blur – Depth of field (focus)

Shadows •  one shadow ray per

intersection per point light source

no shadow rays

one shadow ray

Shadows & Light Sources

http://www.pa.uky.edu/~sciworks/light/preview/bulb2.htm clear bulb frosted bulb

http://3media.initialized.org/photos/2000-10-18/index_gall.htm

http://www.davidfay.com/index.php

Soft Shadows •  multiple shadow rays

to sample area light source

one shadow ray

lots of shadow rays

Antialiasing – Supersampling •  multiple

rays per pixel

point light

area light

jaggies w/ antialiasing •  one reflection ray per intersection

perfect mirror

Reflection

θ θ

Page 8: 11 ray tracing - Computer Science at · PDF file1 Ray Tracing Announcements: Quiz • On Tuesday (2/24), in class • One 8.5x11 sheet of notes allowed • Sample quiz (from prior

8

Glossy Reflection •  multiple reflection

rays

polished surface θ θ

Justin Legakis

Motion Blur •  Sample objects

temporally

Rob Cook

Depth of Field •  multiple rays per pixel

Justin Legakis focal length film

Ray Tracing Algorithm Analysis •  Ray casting •  Lots of primitives •  Recursive •  Distributed Ray

Tracing Effects – Soft shadows – Anti-aliasing – Glossy reflection – Motion blur – Depth of field

cost ≈ height * width * num primitives * intersection cost * size of recursive ray tree *

num shadow rays * num supersamples *

num glossy rays * num temporal samples * num focal samples * . . .

can we reduce this?

these can serve double duty

•  Goral, Torrance, Greenberg & Battaile “Modeling the Interaction of Light Between Diffuse Surfaces”, SIGGRAPH '84

Reading for Friday 2/29:

Post a comment or question on the LMS discussion by 10am on Friday 2/29