ray tracing - computer graphics€¦ · classic ray tracing greeks: do light rays proceed from the...

18
Page 1 CS348B Lecture 2 Pat Hanrahan, Spring 2005 Ray Tracing Today Basic algorithms Overview of pbrt Ray-surface intersection for single surface Next lecture Acceleration techniques for ray tracing large numbers of geometric primitives CS348B Lecture 2 Pat Hanrahan, Spring 2005 Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three ideas about light 1. Light rays travel in straight lines 2. Light rays do not interfere with each other if they cross 3. Light rays travel from the light sources to the eye (but the physics is invariant under path reversal - reciprocity).

Upload: others

Post on 16-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 1

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray Tracing

Today

Basic algorithms

Overview of pbrt

Ray-surface intersection for single surface

Next lecture

Acceleration techniques for ray tracing large numbers of geometric primitives

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Classic Ray Tracing

Greeks: Do light rays proceed from the eye to the light, or from the light to the eye?

Gauss: Rays through lenses

Three ideas about light

1. Light rays travel in straight lines

2. Light rays do not interfere with each other if they cross

3. Light rays travel from the light sources to the eye (but the physics is invariant under path reversal - reciprocity).

Page 2: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 2

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray Tracing in Computer Graphics

Appel 1968 - Ray casting

1. Generate an image by sending one ray per pixel

2. Check for shadows by sending a ray to the light

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray Tracing in Computer Graphics

Whitted 1979

Recursive ray tracing (reflection and refraction)

Page 3: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 3

Ray Tracing Video

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (g/m 10)

Page 4: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 4

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (mirror 0)

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (mirror 1)

Page 5: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 5

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (mirror 2)

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (mirror 5)

Page 6: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 6

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (mirror 10)

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (glass 0)

Page 7: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 7

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (glass 1)

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (glass 2)

Page 8: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 8

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (glass 5)

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (glass 10)

Page 9: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 9

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Spheres-over-plane.pbrt (glass 10)

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Page 10: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 10

CS348B Lecture 2 Pat Hanrahan, Spring 2005

PBRT Architecture

CS348B Lecture 2 Pat Hanrahan, Spring 2005

PBRT Architecture

Page 11: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 11

Ray-Surface Intersection

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Plane Intersection

Ray:

Plane:

Solve for intersection

Substitute ray equation into plane equation

t= +P O D

( ) 00ax by cz d

− • =′+ + + =P P N

OD

t

0 t≤ < ∞ N

− • = + − • =′ ′

− •′= −

( ) ( ) 0( )

t

t

P P N O D P N

O P ND N

P

′P

Page 12: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 12

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Polyhedra

Ray-Slab

Ray-Convex PolyhedraRay-Box

1t 2t

Note: Procedural geometry

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Triangle Intersection 1

1P

2P3P

P1s

2s3s

1 1 2 2 3 3s s s= + +P P P P

Barycentric coordinates

1

2

3

1 2 3

0 10 10 1

1

sss

s s s

≤ ≤

≤ ≤

≤ ≤

+ + =

Inside triangle criteria

1 2 3area( )s = ∆PP P

2 3 1area( )s = ∆PP P

3 1 2area( )s = ∆PPP

Page 13: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 13

CS348B Lecture 2 Pat Hanrahan, Spring 2005

2D Homogeneous Coordinates

ax by cz• = + +L P

1 2 1 2

1 2 1 2 1 2

1 2 1 2

x b c c by c a a cz a b b a

− = = × = − −

P L L

1 2 1 2

1 2 1 2 1 2

1 2 1 2

a y z z yc z x x zc x y y x

− = = × = − −

L P P

CS348B Lecture 2 Pat Hanrahan, Spring 2005

2D Homogeneous Coordinates

1 1 1

1 2 3 2 2 2

3 3 3

area( )x y zx y zx y z

∝PP P

1 1 1

1 2 3 2 2 2

3 3 3

x y zx y zx y z

• × =P P P

Page 14: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 14

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Triangle Intersection 2

= + +1 1 2 2 3 3s s sP P P P

[ ] [ ]1

1 2 3 2

3

sss

=

P P P P

[ ]1 2 3

2 3 1

3 1 2

sss

× = × ×

P PP P PP P

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Triangle Intersection 3

2 3 2 31 2 3

1 2 3

1 3 3 12 3 1

1 2 3

1 2 1 23 1 2

1 2 3

s

s

s

×= = • = • ×

×= = • = • ×

×= = • = • ×

P P P P PP P P PP P P

P P P P PP P P PP P P

P P P P PP P P PP P P

[ ]1 2 3

2 3 1

3 1 2

sss

× = × ×

P PP P PP P

Page 15: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 15

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Polygon Intersection

1. Find intersection with plane of support

2. Test whether point is inside 3D polygon

a. Project onto xy plane

b. Test whether point is inside 2D polygon

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Point in Polygon

inside(vert v[], int n, float x, float y){ int cross=0; float x0, y0, x1, y1;x0 = v[n-1].x - x;y0 = v[n-1].y - y;while( n-- ) {x1 = v->x - x;y1 = v->y - y;if( y0 > 0 ) {if( y1 <= 0 )if( x1*y0 > y1*x0 ) cross++;}else { if( y1 > 0 )if( x0*y1 > y0*x1 ) cross++;}x0 = x1; y0 = y1; v++;}return cross & 1;}

Page 16: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 16

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Sphere Intersection

Ray:

Sphere: ( )2 2 0R− − =P CO

C

D

( )2 2 0t R+ − − =O D C

2 0at bt c+ + =2a = D

2( )b = − •O C D2 2( )c R= − −O C

2 42

b b acta

− ± −=

t= +P O DP

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Geometric Methods

Methods

Find normal and tangents

Find surface parameters

e.g. Sphere

Normal

Parameters

= −N P C

sin cossin sincos

xyz

θ φθ φθ

===

1

1

tan ( , )cos

x yz

φ

θ

=

=

N

ST

, ,u vP

Page 17: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 17

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Implicit Surface Intersection

1. Substitute ray equation

2. Find positive, real roots

Univariate root finding

Newton’s method

Regula-falsi

Interval methods

Heuristics

( , , ) 0f x y z =

*( ) 0f t =

0 1

0 1

0 1

x x x ty y y tz z z t

= +

= +

= +

CS348B Lecture 2 Pat Hanrahan, Spring 2005

Ray-Algebraic Surface Intersection

( , , ) 0np x y z =

*( ) 0np t =

Degree n

Linear: Plane

Quadric: Spheres, …

Quartic: Tori

Polynomial root finding

Quadratic, cubic, quartic

Bezier/Bernoulli basis

Descartes’ rule of signs

Sturm sequences

0 1

0 1

0 1

x x x ty y y tz z z t

= +

= +

= +

Page 18: Ray Tracing - Computer Graphics€¦ · Classic Ray Tracing Greeks: Do light rays proceed from the eye to the light, or from the light to the eye? Gauss: Rays through lenses Three

Page 18

CS348B Lecture 2 Pat Hanrahan, Spring 2005

History

Polygons Appel ‘68Quadrics, CSG Goldstein & Nagel ‘71Tori Roth ‘82Bicubic patches Whitted ‘80, Kajiya ‘82Superquadrics Edwards & Barr ‘83Algebraic surfaces Hanrahan ‘82Swept surfaces Kajiya ‘83, van Wijk ‘84Fractals Kajiya ‘83Height fields Coquillart & Gangnet ’84, Musgrave ‘88Deformations Barr ’86Subdivision surfs. Kobbelt, Daubert, Siedel, ’98

P. Hanrahan, A survey of ray-surface intersection algorithms