Ray tracing Computer Graphics 2006 Based on slides by: Santa Clara - - PowerPoint PPT Presentation

ray tracing
SMART_READER_LITE
LIVE PREVIEW

Ray tracing Computer Graphics 2006 Based on slides by: Santa Clara - - PowerPoint PPT Presentation

Ray tracing Computer Graphics 2006 Based on slides by: Santa Clara University Ray Tracing What is it? Why use it? Basics Advanced topics References Ray-Tracing: Why Use It? Simulate rays of light Produces natural


slide-1
SLIDE 1

Ray tracing

Computer Graphics 2006 Based on slides by: Santa Clara University

slide-2
SLIDE 2

Ray Tracing

What is it? Why use it? Basics Advanced topics References

slide-3
SLIDE 3

Ray-Tracing: Why Use It?

Simulate rays of light Produces natural lighting effects

  • Reflection
  • Depth of Field
  • Refraction
  • Motion Blur
  • Soft Shadows •

Caustics

slide-4
SLIDE 4

Spheres galore

slide-5
SLIDE 5

Ray-Tracing: Why Use It?

Hard to simulate effects with rasterization

techniques (OpenGL)

Rasterizers require many passes Ray-tracing easier to implement

slide-6
SLIDE 6

Ray-Tracing: Who Uses It?

Entertainment (Movies, Commercials) Games pre-production Simulation

slide-7
SLIDE 7

Ray-Tracing: History

Decartes, 1637 A.D. - analysis of rainbow Arthur Appel, 1968 - used for lighting 3D

models

Turner Whitted, 1980 - “An Improved

Illumination Model for Shaded Display” really kicked everyone off.

1980-now - Lots of research

slide-8
SLIDE 8

The Basics

Generating Rays Intersecting Rays with the Scene Lighting Shadowing Reflections

slide-9
SLIDE 9

The Basic Idea

Simulate light rays from light source to eye

Reflected ray Incident ray Eye Surface Light

slide-10
SLIDE 10

“Forward” Ray-Tracing

Trace rays from light Lots of work for little return

Eye Light Image Plane Object Light Rays

slide-11
SLIDE 11

“Backward” Ray-Tracing

Trace rays from eye instead Do work where it matters

Eye Light This is what most people mean by “ray tracing”. Image Plane Object

slide-12
SLIDE 12

Ray Parametric form

Ray expressed as function of a single

parameter (“t”)

<x, y, z> = <xo, yo, zo> + t * <xd, yd, zd> <x, y, z> = ro + trd

ro = <xo, yo, zo> rd = <xd, yd, zd> t = 0.0 t = 1.0 t = 2.0 t = 2.5

slide-13
SLIDE 13

Generating Rays

Trace a ray for each pixel in the image

plane

Eye

tan(fovx) * 2

(Looking down from the top) Image Plane Eye

fovx

slide-14
SLIDE 14

Generating Rays

Trace a ray for each pixel in the image

plane

m n (tan(fovx)* 2) / m (tan(fovy)* 2) / n

Eye Image Plane (Looking from the side)

slide-15
SLIDE 15

Generating Rays

Trace a ray for each pixel in the image

plane

renderImage(){ for each pixel i, j in the image ray.setStart(0, 0, 0); // ro ray.setDir ((.5 + i) * tan(fovx)* 2 / m, (.5 + j) * tan(fovy)* 2 / n, 1.0); // rd ray.normalize(); image[i][j] = rayTrace(ray); }

slide-16
SLIDE 16

Intersection Computation

Parametric ray: r(t) = o + t d

  • t ≥ 0
  • t is distance along ray

Implicit object: f(p) = 0 Intersection occurs when f(r(t)) = 0

  • Real function of one real variable
  • Intersection ≡ root finding
slide-17
SLIDE 17

Sphere Object

class Sphere : public Primitive { Point c; double r; boolean intersects(Ray r, HitObject ho); } c r

slide-18
SLIDE 18

Sphere Intersection

f(p)=(p - c)⋅(p - c) - r2 f(r(t)) = (o + t d - c)⋅(o + t d - c) - r2 = d⋅d t2 + 2 (o-c)⋅d t + (o-c)⋅(o-c) - r2 A = d⋅d = 1 B = 2 (o-c)⋅d C = (o-c)⋅(o-c) - r2

A AC B B t 2 4

2 −

± − =

D = B*B - 4*C; if (D < 0.0) return FALSE; rootD = sqrt(D); t0 = 0.5*(-B - rootD); t1 = 0.5*(-B + rootD); if (t0 >= 0) t = t0, return TRUE; if (t1 >= 0) t = t1, return TRUE; return FALSE;

slide-19
SLIDE 19

Other HitObject Values

hit = r.o + t*r.d n = hit - c What about an ellipsoid?

slide-20
SLIDE 20

Ellipsoid Intersection

f(x) = 0 f(T-1x)=0 Let T be a 4x4 transformation T distorts a sphere into an ellipsoid f(T-1r(t)) = f(T-1(o + t d)) = f(T-1o + t T-1d)) Ellipsoid is implicit surface of f(T-1x) Ellipsoid::intersects(r,&ho) { Ray Tir = (Ti * o, Ti * d); Sphere::intersects(Tir,ho); }

  • d

T-1o T-1d T x T-1x

slide-21
SLIDE 21

What about the normal?

f(x) = 0 f(T-1x)=0 T Tx x n is tangent plane [a b c d] x is point [x y z 1]T Such that matrix product n x = 0 n (n Q) Tx = 0 What is Q? Q = T-1 (n T-1) Tx = n (T-1 T)x = 0 New normal n’ = n T-1 = (T-1)T nT n’

slide-22
SLIDE 22

Plane Intersection

So how do we do it with a minimum of

work?

The road to the square is a close one

slide-23
SLIDE 23

Quadrics

Sphere: x2 + y2 + z2 – r2 Cylinder: x2 + y2 – r2 Cone: x2 + y2 – z2 Tapered cylinder : x2 + y2 – ( 1 + (s-1)z)2 Paraboloid: x2 + y2 – z Hyperboloid: x2 + y2 – z2 ± r2

(Variations: Use again the 4x4 transformation trick)

slide-24
SLIDE 24

Torus

Product of two implicit circles

(x – R)2 + z2 – r2 = 0 (x + R)2 + z2 – r2 = 0 ((x – R)2 + z2 – r2)((x + R)2 + z2 – r2) (x2 – 2Rx + R2 + z2 – r2) (x2 + 2Rx + R2 + z2 – r2) x4 + 2x2z2 + z4 – 2x2r2 – 2z2r2 + r4 – 2x2R2 + 2z2R2 – 2r2R2 + R4 (x2 + z2 – r2 – R2)2 + 4z2R2 – 4r2R2

Surface of rotation

replace x2 with x2 + y2 f(x,y,z) = (x2 + y2 + z2 – r2 – R2)2 + 4R2(z2 – r2)

Quartic!!!

R r

slide-25
SLIDE 25

Finding Roots

How do we find roots for higher

degrees?

Newton’s Method

  • Converges fast
  • Might converge to wrong root

Root Isolation

  • Guarantees single root
  • Sturm Sequences
slide-26
SLIDE 26

Newton’s Method

1

( ) '( )

i i

f x x x f x

+ =

.

slide-27
SLIDE 27

Finding Intersections

Check all the objects, keep the closest

intersection

hitObject(ray) { for each object in scene does ray intersect the object? if(intersected and was closer) save that intersection if(intersected) return intersection point and normal }

slide-28
SLIDE 28

Lighting

We’ll use triangles for lights

  • Build complex shapes from triangles

Some lighting terms

Eye V R N I Surface Light

slide-29
SLIDE 29

Lighting

Use modified Phong lighting

  • similar to OpenGL
  • simulates rough and shiny surfaces

for each light In = IambientKambient + IdiffuseKdiffuse (L.N) + IspecularKspecular (R.V)n

slide-30
SLIDE 30

Ambient Light

Iambient Simulates the indirect lighting in

a scene.

Eye Light

slide-31
SLIDE 31

Diffuse Light

Idiffuse simulates direct lighting on a

rough surface

Viewer independent Paper, rough wood, brick, etc...

Eye Light

slide-32
SLIDE 32

Specular Light

Ispecular simulates direct lighting on a

smooth surface

Viewer dependent Plastic, metal, polished wood, etc...

Eye Light

slide-33
SLIDE 33

Shadow Test

Check against other objects to see if point is

shadowed

Eye Shadowing Object

slide-34
SLIDE 34

Reflection

Angle of incidence = angle of reflection ( θI =

θR )

I, R, N lie in the same plane

R = I - 2 (N . I) N

R N I θI θR

slide-35
SLIDE 35

Putting It All Together

Recursive ray evaluation

rayTrace(ray) { hitObject(ray, p, n, triangle); color = object color; if(object is light) return(color); else return(lighting(p, n, color)); }

slide-36
SLIDE 36

Putting It All Together

Calculating surface color

lighting(point) { color = ambient color; for each light if(hitObject(shadow ray)) color += lightcolor * dot(shadow ray, n); color += rayTrace(reflection) * pow(dot(reflection, ray), shininess); return(color); }

slide-37
SLIDE 37

Putting It All Together

The main program

main() {

  • bjects = readObjects ();

image = renderImage(objects); writeImage(image); }

slide-38
SLIDE 38

This is A Good Start

Lighting, Shadows, Reflection are enough

to make some compelling images

Want better lighting and objects Need more speed

slide-39
SLIDE 39

But we prefer something like this

slide-40
SLIDE 40

More Quality, More Speed

Better Lighting + Forward Tracing Texture Mapping Modeling Techniques Motion Blur, Depth of Field, Blurry

Reflection/Refraction

  • Distributed Ray-Tracing

Improving Image Quality Acceleration Techniques

slide-41
SLIDE 41

Refraction

Keep track of medium (air, glass, etc) Need index of refraction (η ) Need solid objects

T N I θI θT

sin(θI) η1 sin(θT) η2 =

Medium 1 (e.g. air) Medium 2 (e.g. water)

slide-42
SLIDE 42

Refraction

slide-43
SLIDE 43

Improved Light Model

Cook & Torrance

  • Metals have different color at angle
  • Oblique reflections leak around corners
  • Based on a microfacet model
slide-44
SLIDE 44

Using “Forward” Ray Tracing

Backward tracing doesn’t handle indirect

lighting too well

To get caustics, trace forward and store

results in texture map.

slide-45
SLIDE 45

Using “Forward” Ray Tracing

slide-46
SLIDE 46

Texture Mapping

Use texture map to add surface detail

  • Think of it like texturing in OpenGL

Diffuse, Specular colors Shininess value Bump map Transparency value

slide-47
SLIDE 47

Texture Mapping

slide-48
SLIDE 48

Parametric Surfaces

More expressive than triangle Intersection is probably slower u and v on surface can be used as texture s,t

slide-49
SLIDE 49

Constructive Solid Geometry

Union, Subtraction, Intersection of solid

  • bjects

Have to keep track of intersections

slide-50
SLIDE 50

Hierarchical Transformation

Scene made of parts Each part made of smaller parts Each smaller part has transformation linking

it to larger part

Transformation can be changing over time -

Animation

slide-51
SLIDE 51

Distributed Ray Tracing

Average multiple rays instead of just one

ray

Use for both shadows, reflections,

transmission (refraction)

Use for motion blur Use for depth of field

slide-52
SLIDE 52

Distributed Ray Tracing

slide-53
SLIDE 53

Distributed Ray Tracing

One ray is not enough (jaggies) Can use multiple rays per pixel -

supersampling

Can use a few samples, continue if they’re

very different - adaptive supersampling

Texture interpolation & filtering

slide-54
SLIDE 54

Acceleration

1280x1024 image with 10 rays/pixel 1000 objects (triangle, CSG, NURBS) 3 levels recursion

39321600000 intersection tests 100000 tests/second -> 109 days! Must use an acceleration method!

slide-55
SLIDE 55

Bounding volumes

Use simple shape for quick test, keep a

hierarchy

slide-56
SLIDE 56

Space Subdivision

Break your space into pieces Search the structure linearly

slide-57
SLIDE 57

Parallel Processing

You can always throw more processors at it.

slide-58
SLIDE 58

Really Advanced Stuff

Error analysis Hybrid radiosity/ray-tracing Metropolis Light Transport Memory-Coherent Ray-tracing

slide-59
SLIDE 59

References

Introduction to Ray-Tracing, Glassner et al,

1989, 0-12-286160-4

Advanced Animation and Rendering

Techniques, Watt & Watt, 1992, 0-201- 54412-1

Computer Graphics: Image Synthesis, Joy

et al, 1988, 0-8186-8854-4

SIGGRAPH Proceedings (All)