21
Ray-Tracing ©Anthony Steed 2001-2003

1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

Embed Size (px)

Citation preview

Page 1: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

1

Ray-Tracing

©Anthony Steed 2001-2003

Page 2: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

2

Overview

Recursive Ray Tracing Shadow Feelers Snell’s Law for Refraction When to stop!

Page 3: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

3

Recap: Light Transport

Page 4: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

4

Recap: Local Illumination

Ambient, diffuse & specular components The sum is over the specular and diffuse

components for each light

M

j

mjsjdjiar nhklnkIkI

1 ,

Page 5: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

5

Recap: Result of Ray Casting

Page 6: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

6

Correcting for Non-Visible Lights

EN H

L

surface

Page 7: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

7

Where Sj is the result of intersecting the ray L with the scene objects

Note consider your intersection points along the ray L carefully• Hint – they might be beyond the light!

M

j

mjsjdjijar nhklnkISkI

1 ,

Page 8: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

8

Result of Shadow Feeler

Page 9: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

9

Recursive Ray-Tracing

We can simulate specular-specular transmission elegantly by recursing and casting secondary rays from the intersection points

We must obviously chose a termination depth to cope with multiple reflections

Page 10: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

10

Introducing Reflection

Where

EN H

L

surface

R

NENER 2

Page 11: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

11

Computing Reflectance

'rrlocalr IkII Where Ilocal is computed as before Ray r' is formed from intersection point

and the direction R and is cast into the scene as before

Page 12: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

12

Psuedo Code

Color RayTrace(Point p, Vector D, int depth) {

Point pd /* Intersection point */

Boolean intersection

if (depth > MAX) return Black

intersect(p,direction, &pd, &intersection)

if (!intersection) return Background

Ilocal = kaIa + Ip.v.(kd(n.l) + ks.(h.n)m)

return Ilocal + kr*RayTrace(pd, R, depth+1)

}

Normally kr = ks

Page 13: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

13

Result of Recursion

Page 14: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

14

Perfect Specular Transmission

N H

L

E

T

R

αSnell’s Law

1

2

sin

sin

η is index ofrefraction

β

Page 15: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

15

Using Snell’s Law

Using this law it is possible to show that:

Note that if the root is negative then total internal reflection has occurred and you just reflect the vector as normal

211

2

sin

sin

1cos1cos 22121212 NET

Page 16: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

16

New Psuedo Code

Color RayTrace(Point p, Vector D, int depth) { Point pd /* Intersection point */ Boolean intersection if (depth > MAX) return Black intersect(p,direction, &pd, &intersection) if (!intersection) return Background

Ilocal = kaIa + Ip.v.(kd(n.l) + ks.(h.n)m)

return Ilocal + kr*RayTrace(pd, R, depth+1) + kt*RayTrace(pd, T, depth+1)

}

Page 17: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

17

Direct Specular Transmission

A transparent surface can be illuminated from behind and this should be calculated in Ilocal

NH'

L

E

Page 18: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

18

Calculating H'

Use H‘ instead of H in specular term

1'

1

2

1

2

LE

H

Page 19: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

19

Putting Everything Together

Page 20: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

20

Discussion – What Can’t We Simulate?

Page 21: 1 Ray-Tracing ©Anthony Steed 2001-2003. 2 Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!

21

Summary

Recursive ray tracing is a good simulation of specular reflections

We’ve seen how the ray-casting can be extended to include shadows, reflections and transparent surfaces

However this is a very slow process and still misses some types of effect!