Docsity

Ray Tracing Intersections: Recursive Method and Sphere Intersection Algorithms - Prof. J. , Study notes of Computer Science

Toggle sidebar
bg1
Ray Tracing Intersections
CS510
Lecture #4
January 26, 2009
© Bruce A. Draper & J. Ross Beveridge, January 26, 2009
CS510
CS510 -
-Computer Graphics, Spring 2009
Computer Graphics, Spring 2009
Recursive Ray Tracing:
The General Idea
How do we see objects?
–Light leaves a light source, bounces of an object, and onto our
retina (or film).
–Or, it leaves a light source, boun ces of one object, then off
another, and onto our retina.
–Or, it leaves a light source, bounces of one surface, then another,
…., and onto our retina.
We want to emulate this process, starting at the camera (or
retina) and working backwards….
© Bruce A. Draper & J. Ross Beveridge, January 26, 2009
CS510
CS510 -
-Computer Graphics, Spring 2009
Computer Graphics, Spring 2009
Computing Intersections
Ray-to-Surface Intersection Calculations are Key.
–This is most of the computation in R ay Tracing
Algorithms tied to surface type.
–Sphere
–Polygon
–Bicubic Surfaces (really hard! we won’t do these)
First pass: General Mathematics
Second pass: Highly Optimized Codes
© Bruce A. Draper & J. Ross Beveridge, January 26, 2009
CS510
CS510 -
-Computer Graphics, Spring 2009
Computer Graphics, Spring 2009
Representing a Ray
Defined by a point and a unit
vector.
Where E is the focal point
(Eye) and L is a pixel point
(Lens Point)
Rs
(
)
=
L
+
sU
U=L−
E
L−E
© Bruce A. Draper & J. Ross Beveridge, January 26, 2009
CS510
CS510 -
-Computer Graphics, Spring 2009
Computer Graphics, Spring 2009
Sphere Intersection
Parametric Ray - Brute Force
Consider a sphere centered at Pcwith radius r.
P−Pc
2=r2
L+sU −Pc
2−r2=0
substitute
T=Pc−L
Yielding a quadratic equation
sU −T
()
⋅sU −T
()
−r2=0
L
© Bruce A. Draper & J. Ross Beveridge, January 26, 2009
CS510
CS510 -
-Computer Graphics, Spring 2009
Computer Graphics, Spring 2009
Sphere Intersection
Brute Force (II)
Expand to see what is happening. Let
=
T
⎡
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎤
⎦
⎥
⎥
⎥
⎥
⎥
⎥
−
xcx0
−
ycy0
−
zcz0
= −
⎛
⎝
⎜
⎜
⎜
⎜
⎜
⎜
⎞
⎠
⎟
⎟
⎟
⎟
⎟
⎟
⎛
⎝
⎜
⎜
⎜
⎜
⎜
⎜
⎞
⎠
⎟
⎟
⎟
⎟
⎟
⎟
−
s
⎡
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎤
⎦
⎥
⎥
⎥
⎥
⎥
⎥
ux
uy
uz
⎡
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎤
⎦
⎥
⎥
⎥
⎥
⎥
⎥
tx
ty
tz
•
⎛
⎝
⎜
⎜
⎜
⎜
⎜
⎜
⎞
⎠
⎟
⎟
⎟
⎟
⎟
⎟
−
s
⎡
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎤
⎦
⎥
⎥
⎥
⎥
⎥
⎥
ux
uy
uz
⎡
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎤
⎦
⎥
⎥
⎥
⎥
⎥
⎥
tx
ty
tz
r20
W⋅W−r2=0=
W
⎡
⎣
⎢
⎢
⎢
⎢
⎢
⎢
⎤
⎦
⎥
⎥
⎥
⎥
⎥
⎥
−
su
xtx
−
su
yty
−
su
ztz
= + + −
()
−
su
xtx2()
−
su
yty2()
−
su
ztz2r20
pf3
pf4

Partial preview of the text

Download Ray Tracing Intersections: Recursive Method and Sphere Intersection Algorithms - Prof. J. and more Study notes Computer Science in PDF only on Docsity!

Ray Tracing Intersections

CS

Lecture

January 26, 2009

CS510CS510 -- Computer Graphics, Spring 2009Computer Graphics, Spring 2009 © Bruce A. Draper & J. Ross Beveridge, January 26, 2009

Recursive Ray Tracing:

The General Idea

z How do we see objects?

  • Light leaves a light source, bounces of an object, and onto our

retina (or film).

  • Or, it leaves a light source, bounces of one object, then off

another, and onto our retina.

  • Or, it leaves a light source, bounces of one surface, then another,

…., and onto our retina.

z We want to emulate this process, starting at the camera (or

retina) and working backwards….

CS510 -CS510- Computer Graphics, Spring 2009Computer Graphics, Spring 2009 © Bruce A. Draper & J. Ross Beveridge, January 26, 2009

Computing Intersections

z Ray-to-Surface Intersection Calculations are Key.

  • This is most of the computation in Ray Tracing

z Algorithms tied to surface type.

  • Sphere
  • Polygon
  • Bicubic Surfaces (really hard! we won’t do these)

z First pass: General Mathematics

z Second pass: Highly Optimized Codes

CS510CS510 -- Computer Graphics, Spring 2009Computer Graphics, Spring 2009 © Bruce A. Draper & J. Ross Beveridge, January 26, 2009

Representing a Ray

z Defined by a point and a unit

vector.

z Where E is the focal point

(Eye) and L is a pixel point

(Lens Point)

R s ( )= L + sU

U =

L − E

L − E

Sphere Intersection

Parametric Ray - Brute Force

z Consider a sphere centered at P c with radius r.

P − P

c

2

= r

2

L + sU − P

c

2

− r

2

substitute

T = P

c

− L

Yielding a quadratic equation

(^ sU^ −^ T ) ⋅^ ( sU^ −^ T ) −^ r

2

L

Sphere Intersection

Brute Force (II)

z Expand to see what is happening. Let

T =

x c − x 0

y (^) c − y 0

zc − z 0

s −

u (^) x

u (^) y

u z

t (^) x

t (^) y

t z

s −

u (^) x

u (^) y

u z

t (^) x

t (^) y

t z

r

2 0

W ⋅ W − r

2 = (^0) W=

s u x − t x

s u (^) y − t (^) y

s uz − t (^) z

( s ux − t (^) x )+ + − =

2 ( s uy − t (^) y )

2 ( s u (^) z − t (^) z )

2 r

2 0

CS510 -CS510- Computer Graphics, Spring 2009Computer Graphics, Spring 2009 © Bruce A. Draper & J. Ross Beveridge, January 26, 2009

Sphere Intersection (III)

z After multiplying out, expand and collect s terms.

( u x + + ) +

2 u (^) z

2 u (^) y

2 s

2

( (^) − 2 t (^) y u (^) y − 2 t (^) x ux − 2 t (^) z uz ) s +

t x − + + =

2 r

2 t (^) z

2 t (^) y

2 0

z U is a unit vector, so (u x

2

  • u y

2

  • u z

2 ) = 1

z So the equation may be written as:

s

2

− 2 ( U ⋅ T ) s + T ⋅ T − r

2

CS510CS510 -- Computer Graphics, Spring 2009Computer Graphics, Spring 2009 © Bruce A. Draper & J. Ross Beveridge, January 26, 2009

Sphere Intersection

Reduces to Quadratic

Consider that we now have a simple quadratic equation.

2 2

2

where

c T r

b UT

a

as bs c

2 2 2

2 2 2

2

Therefore:

s UT UT T r

UT UT T r s

a

b b ac s

CS510 -CS510- Computer Graphics, Spring 2009Computer Graphics, Spring 2009 © Bruce A. Draper & J. Ross Beveridge, January 26, 2009

Actual Sphere

Intersection Points

z Compute the two s values for the

two intersections:

(^222) 2

(^222) 1

s UT UT T r

s UT UT T r

8 multiplies/squares

(caching results; r 2

previously stored)

8 additions

1 square root

z Compute the actual positions along the ray for the smallest

positive s:

s

= min( s 1 , s 2

P

= P 0 + s

U

3 multiplies

3 additions

1 min

CS510CS510 -- Computer Graphics, Spring 2009Computer Graphics, Spring 2009 © Bruce A. Draper & J. Ross Beveridge, January 26, 2009

But Wait

z The proceeding follows naturally from parametric

approach to intersecting objects.

z But is it smart?

z Might there be a more efficient way?

z Yes.

  • Glassner, A. (ed) An Introduction to Ray Tracing. Academic Press, 1989
  • http://www.cs.unc.edu/~rademach/xroads-RT/RTarticle.html

z Let’s see it …

Sphere Ray Intersection

Faster Method

v d

b r

C

v

2

  • b

2 = c

2

d

2

  • b

2 = r

2

d

2 = r

2 − c

2 − v

2

d = r

2 − c

2 − v

2

E

O

R

• If d

2

less than zero, no intersection.

• Otherwise, Q = E + (v-d)R

Q

Faster Method

How Fast?

z Assume R is given - unit length ray direction.

z Need to compute v: v = (O-E)•R

  • 3 multiplies, 2 additions.

z Both r 2 and c 2 are already computed.

  • c 2 computed for case of ray coming from focal point

z Test if r

2 is greater than (c

2

  • v

2 )

  • 1 mulitply, one conditional.

z Only if intersection, Q = E+(v-d)R.

  • 1 subtract, 3 multiplies, 6 additions.

z Another reference on this approach:

  • http://www.groovyvis.com/other/raytracing/basic.html

Odd/Even Intersections (II)

z Key calculation: ray to ray intersection

  • Note that both rays have a free variable T
  • Three dimensions ⇒ 3 equations

(overconstrained)

  • For an intersection to be valid:

z 0 ≤ T (^) IPRay

z 0 ≤ T edge < 1

Is this efficient?

z No!

  • But its easy ☺
  • It’s general : works for non-convex and self-

intersecting polygons.

z More efficient methods for convex polygons

and for triangles