Ray Tracing CPSC 453 Fall 2018 Sonny Chan Ray Tracing A method - - PowerPoint PPT Presentation

ray tracing
SMART_READER_LITE
LIVE PREVIEW

Ray Tracing CPSC 453 Fall 2018 Sonny Chan Ray Tracing A method - - PowerPoint PPT Presentation

Ray Tracing CPSC 453 Fall 2018 Sonny Chan Ray Tracing A method for synthesizing images of virtual 3D scenes. Image Capture Devices Which one shall we use? Goal: Simulate a Camera Obscura! Spheres & Checkerboard Turner Whitted,


slide-1
SLIDE 1

Ray Tracing

CPSC 453 – Fall 2018 Sonny Chan

slide-2
SLIDE 2

Ray Tracing

A method for synthesizing images

  • f virtual 3D scenes.
slide-3
SLIDE 3

Image Capture Devices

Which one shall we use?

slide-4
SLIDE 4

Goal: Simulate a Camera Obscura!

slide-5
SLIDE 5
slide-6
SLIDE 6

“Spheres & Checkerboard”

Turner Whitted, 1979

slide-7
SLIDE 7

Whitted Ray Tracing

  • “An improved illumination

model for shaded display”

  • T. Whitted, SIGGRAPH 1979
  • 512 × 512 image
  • Rendered on VAX 11/780
  • 74 minutes compute time
  • How fast would your

computer render this today?

[image courtesy of P . Hanrahan, Stanford University]

slide-8
SLIDE 8
slide-9
SLIDE 9

The Ray Tracing Algorithm

  • For every pixel or position on your image, do
  • 1. ray generation: where am I looking?
  • 2. ray intersection: do I see something?
  • 3. shading: what colour is it?
slide-10
SLIDE 10

Ray Generation

slide-11
SLIDE 11
slide-12
SLIDE 12

virtual image plane

slide-13
SLIDE 13

[from photojojo.com]

slide-14
SLIDE 14

Let’s see how we might

generate those rays

slide-15
SLIDE 15
slide-16
SLIDE 16

Ray Generation

r(t) = e + t(s − e)

slide-17
SLIDE 17
slide-18
SLIDE 18

Ray Intersection

What do we see?

slide-19
SLIDE 19

Ray Intersection

  • For every object we have in our scene, we need a way to

determine whether or not we can see it

  • Usually amounts to solving an equation of one variable
  • We will examine three key intersection tests today:
  • spheres
  • planes
  • triangles
slide-20
SLIDE 20

spheres

slide-21
SLIDE 21
slide-22
SLIDE 22

Ray-Sphere Intersection

||p − c|| = R (p − c) · (p − c) − R2 = 0 r(t) = o + td (r(t) − c) · (r(t) − c) − R2 = 0 (o + td − c) · (o + td − c) − R2 = 0 A ray: A sphere: Intersection:

Solve for t…

  • d

c R

slide-23
SLIDE 23

planes

slide-24
SLIDE 24
slide-25
SLIDE 25

Ray-Plane Intersection

A ray: A plane: Intersection: r(t) = o + td (p − q) · ˆ n = 0

Solve for t…

(r(t) − q) · ˆ n = 0 (o + td − q) · ˆ n = 0

  • d

q ˆ n

slide-26
SLIDE 26

triangles

slide-27
SLIDE 27

How might we test

intersection of a ray and a triangle?

slide-28
SLIDE 28

Barycentric Coordinates

p0 p1 p2 f(u, v) = (1 − u − v)p0 + up1 + vp2 u

v

w

(.6, .4, 0) (.3, .2, .5)

slide-29
SLIDE 29

Another Interpretation

Ratio of (signed) areas of triangles:

u = A1 A v = A2 A

f(u, v) = (1 − u − v)p0 + up1 + vp2

A = 1

2(p1 − p0) × (p2 − p0)

p0 p1

(.3, .2, .5)

p2

A0 A1 A2

slide-30
SLIDE 30

A Direct Approach for Intersection

r(t) = o + td  −d p1 − p0 p2 − p0     t u v   = o − p0

A ray: A triangle: Rearrange terms:

f(u, v) = (1 − u − v)p0 + up1 + vp2

  • + td = (1 − u − v)p0 + up1 + vp2

Ray-triangle intersect:

Solve for t, u, and v…

slide-31
SLIDE 31

Cramer’s Rule

  • Given a set of linear equations in matrix form
  • Write the determinant of the matrix
  • Then the solutions are

 a b c     x y z   = d det(a, b, c) =

  • a1

b1 c1 a2 b2 c2 a3 b3 c3

  • x = det(d, b, c)

det(a, b, c) y = det(a, d, c) det(a, b, c) z = det(a, b, d) det(a, b, c)

slide-32
SLIDE 32

A Direct Approach for Intersection

 −d p1 − p0 p2 − p0     t u v   = o − p0 e1 = p1 − p0, e2 = p2 − p0, s = o − p0   t u v   = 1 det(−d, e1, e2)   det(s, e1, e2) det(−d, s, e2) det(−d, e1, s)  

Our equation: Applying Cramer’s rule: where

Check that t > 0 and u, v, u+v are within [0,1] interval!

slide-33
SLIDE 33

Ray-Object Intersection Tests

  • Now we know how to draw spheres, planes, and

triangles in perspective with a ray tracer!

  • What else can we do?
slide-34
SLIDE 34

[from photojojo.com]

slide-35
SLIDE 35

I think we need some shading…

What we’ve got now… and what we really want!

slide-36
SLIDE 36

Shadows & More

slide-37
SLIDE 37
slide-38
SLIDE 38

What happens if we have more than one light?

slide-39
SLIDE 39
slide-40
SLIDE 40

How do we get these nice, soft shadows?

slide-41
SLIDE 41

Depth of Field

Can we ray trace it?

slide-42
SLIDE 42
  • bject

image

slide-43
SLIDE 43

The Ray Tracing Algorithm

  • For every pixel position on your image:
  • 1. Generate a parametric viewing ray.
  • 2. Test for intersection against each object in your

scene.

  • What happens if it intersections more than one object?
  • 3. Determine the colour to be carried back on the ray
  • Trace shadow ray(s) to obtain shadow effect
slide-44
SLIDE 44

Things to Remember

  • Ray tracing is a relatively simple way for us to synthesize

images of a 3D scene in perspective

  • simulates the optics of a pinhole camera
  • We need to devise a ray-object intersection for each kind
  • f object geometry in the scene
  • Some effects like shadows are relatively easy to compute
  • Soft shadows and depth of field are possible if you’re

willing to wait!