1 of 39

Nima Kalantari

CSCE 441 - Computer Graphics

Ray Tracing (Intro)

Some slides from Ren Ng, Ravi Ramamoorthi, and Scott Schaefer

2 of 39

Rasterization

  • Advantage
    • Fast
  • Disadvantage
    • Hard to render realistic effects

3 of 39

Effects needed for Realism

  • (Soft) Shadows
  • Reflections (Mirrors and Glossy)
  • Transparency (Water, Glass)
  • Interreflections (Color Bleeding)
  • Realistic Materials (Velvet, Paints, Glass)
  • And many more

4 of 39

From Wikipedia

5 of 39

Ray Tracing

  • Follows the physical image formation process
  • Pixel by pixel instead of object by object in rasterization
  • Very slow!
  • Easier to handle different effects

6 of 39

Light Rays

  • Three ideas about light rays
    • Light travels in straight lines
    • Light rays do not interfere with each other
    • Light rays travel from the light sources to the eye

7 of 39

Outline

  • Basic ray tracing
  • Recursive ray tracing
  • Ray object intersection

8 of 39

Ray Casting

  • Appel 1968 - Ray casting
    • Generate an image by casting one ray per pixel
    • Check for shadows by sending a ray to the light

9 of 39

Ray Casting - Generating Eye Rays

  • Pinhole Camera Model

eye point

image plane

light source

eye ray �(starts at eye and goes through pixel)

closest scene�intersection point

note: more intersection points

10 of 39

Ray Casting - Shading Pixels (Local Only)

  • Pinhole Camera Model

eye point

image plane

light source

eye ray �(starts at eye and goes through pixel)

perform shading calculation here to compute color of pixel (e.g. Phong model)

N

P

L

11 of 39

Local Shading

 

12 of 39

Ray Casting - Shading Pixels (no shadows)

  • Pinhole Camera Model

eye point

image plane

light source

eye ray �(starts at eye and goes through pixel)

perform shading calculation here to compute color of pixel (e.g. Phong model)

N

P

L

13 of 39

Shadows

  • Cast a virtual ray to each light source
  • If ray hits an opaque object before the light, then omit contribution of that light

14 of 39

Ray Casting – Shadows

  • Pinhole Camera Model

eye point

image plane

light source

eye ray �(starts at eye and goes through pixel)

perform shading calculation here to compute color of pixel (e.g. Phong model)

N

P

L

15 of 39

Illumination without shadow

 

16 of 39

Illumination with shadow

 

 

17 of 39

Outline

  • Basic ray tracing
  • Recursive ray tracing
  • Ray object intersection

18 of 39

Recursive Ray Tracing

  • “An improved Illumination �model for shaded display” �T. Whitted, CACM 1980

  • Time:
    • VAX 11/780 (1979) 74m
    • PC (2006) 6s
    • GPU (2012) 1/30s

Spheres and Checkerboard, T. Whitted, 1979

19 of 39

Recursive Ray Tracing - Reflection

eye point

image plane

light source

20 of 39

Recursive Ray Tracing - Reflection

eye point

image plane

N

R

light source

Mirror ray�(specular reflection)

21 of 39

Reflection

  • Mirror-like/Shiny objects

Surface

 

22 of 39

Recursive Ray Tracing - Reflection

eye point

image plane

light source

23 of 39

Recursive Ray Tracing - Reflection

eye point

image plane

light source

Shadow rays

24 of 39

Refraction

  • Bending of light caused by different speeds of light in different medium
  • Each (semi-)transparent object has an index of refraction ni or velocity of light ci
  • Use Snell’s law to find

refracted vector

Image taken from http://hyperphysics.phy-astr.gsu.edu/hbase/geoopt/refr2.html

25 of 39

Snell’s Law

 

 

 

Surface

 

 

 

 

 

c=speed of light in vacuum

26 of 39

Recursive Ray Tracing – Reflection & Refraction

eye point

image plane

light source

27 of 39

Recursive Ray Tracing – Reflection & Refraction

eye point

image plane

light source

Truncate at finite depth!

28 of 39

Recursive Ray Tracing

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Truncate at finite depth!

+

 

 

+

 

+

29 of 39

Recursive Ray Tracing

For each pixel

    • Trace the ray, find intersection

    • Trace Shadow Ray(s) to all light(s)
      • Color = ka
      • Color += if visible -> illumination model; if not visible -> 0 ;

    • Trace Reflected Ray
      • Color += reflectivity * Color of reflected ray

30 of 39

Recursive Ray Tracing – Reflection

0

1

eye point

image plane

light source

2

31 of 39

Outline

  • Basic ray tracing
  • Recursive ray tracing
  • Ray object intersection

32 of 39

Ray Equation

unit direction

origin

“time”

point along ray

Ray equation:

Example:

Ray is defined by its origin and a direction vector

33 of 39

Ray Intersection With Sphere

Ray:

Sphere:

Solve for intersection:

34 of 39

Plane Equation

Plane is defined by normal vector and a point on plane

Example:

Plane Equation:

normal vector

any point

all points on plane

35 of 39

Ray Intersection With Plane

Ray equation:

Plane equation:

Solve for intersection

Check:

36 of 39

Ray Intersection With Triangle

  • Triangle is in a plane
    • Ray-plane intersection
    • Test if hit point is inside triangle

37 of 39

Ray Intersection With Triangle Mesh

  • Simple idea: just intersect ray with each triangle
  • Simple, but slow

38 of 39

Möller Trumbore Algorithm

Why care about performance?

39 of 39

Ray Tracing vs Rasterization

for each pixel

for each primitive

color the pixel

for each primitive

for each pixel

color the pixel

Offline*

Movies, Animations

Real-Time

Games