25
Ray Tracing Jerry Sui Adam Conner

Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

  • View
    226

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Ray Tracing

Jerry Sui Adam Conner

Page 2: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part I – Introduction to Ray Tracing

Final Product

Page 3: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part I – Introduction to Ray Tracing

1. Trace the rays backward from the viewpoint through each pixel and into the scene (reverse direction of light propagation).

2. Find intersection point that is closest to eye.

3. Compute color at intersection.

Ray Tracing is global lighting model.

Page 4: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part I – Introduction to Ray TracingCast rays into the scene:

Ray: a point (xo, yo, zo) and the direction (unit vector)

Page 5: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part II – Ray-object Intersection

1. Whether there is an intersection (with object surface).

2. If yes, give me the distance between viewpoint and the point of intersection (so that we can calculate the position of the intersection point).

---Find intersection that is closest to the viewpoint.

Page 6: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part II – Ray-object Intersection

Ray-plane intersection:

ax + by + cz + d = 0

n = (a, b, c)Intersection with X-axis: -d/aIntersection with Y-axis: -d/bIntersection with Z-axis: -d/c

Page 7: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part II – Ray-object Intersectionvd = (xd, yd, zd) direction vector (unit); pd = po + tvd

a(xo + txd) + b(yo + tyd) + c(zo + tzd) + d = 0

Solve: t = -(axo+byo+czo+d) / (axd+byd+czd)

= -(n po + d) / n vd

po

n

vd

pd

Page 8: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part II – Ray-object Intersection

Sphere, Box…etc.

Most of the work in ray tracing goes into calculation of intersections between rays and surfaces.

Calculations of some ray-object intersections could be pretty hard.

Page 9: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

The color at the intersection point depends on

Lights in scene

Material properties of the object.

Page 10: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at IntersectionIllumination:

Phong reflection model

Reflection

Transmition (refraction) light

Shadow

need recursion

Page 11: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Phong reflection model:Diffuse:

• Calculated using the diffuse component of the light source.

Ambient• Calculated using the ambient light in the scene.

Specular reflection• Calculated by taking the dot product of the reflection ray with

the rays direction vector, and raise the result to a power.

Page 12: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Reflection:Mirror-like object reflection

Outside phong reflection model

Recursive; additional secondary rays generated for each intersection

• Secondary ray acts as primary ray, which may in turn generate additional secondary rays.

• Primary ray: ray shot out from the viewpoint.• Secondary ray: any ray the is not a primary ray.

Page 13: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Page 14: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Transmission (refraction):

I

T

n

2

1

1

2

η

η

θsin

θsin

Snell’s Law:

Page 15: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at IntersectionTransmission:

Ncosθ Msinθ T 22

1

1

sinθ

N IM

c

Nθcos)N I(sinθ

sinθ T 21

1

2 c

1

2

2

1

sinθ

θsin

η

η η

)1(η1θsinη1θsin1θcos 21

21

222

22 c

Page 16: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

)Nθcos(η ηI T 21-c

Nθcos)N I(sinθ

sinθ T 21

1

2 c

Page 17: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at IntersectionTransmission:

Absorbency Coefficient:

DRe absorbency

nedcolorRetur absorbency finalColor

e = 2.718… (base of natural logarithm)

R: transparency factor (0, 1)

D: distance the ray travelled.

Page 18: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Anti-aliasing:

Shoot multiple rays through a pixel (to different position inside a pixel), and then average the colors returned by the rays. That is the final color of the pixel.

Page 19: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Shadows:

Given an intersection, shoot a ray to each light source and trace it to see if it intersects with anything along the way.

If the shadow ray makes it to the light source, then the intersection is not in the shadow of that light. Otherwise, it is.

Page 20: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Page 21: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Shadows:Area Lights:

• Area light can be seen as if it is comprised of multiple point lights.

• Each point light within an area light gives off a fraction of the total light for the area light.

• When calculating shadows from area light, each intersection point fires a ray for each part of the area light. For each of these rays which fails to reach the area light, the sum of those fractions of light represent the shadow at the intersection point cast from the area light.

Page 22: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Page 23: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part III – Color at Intersection

Shadows:

Soft Shadows (noise):

• Eliminate banding

• Done by using multiple shadow rays for each area light grid position, each with random offset.

Page 24: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Part IV – Future Research Possibilities

Optimization (acceleration)

Distributed computing

Better illumination model

Real-time ray tracing

……

Page 25: Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product

Picture Time