7.2 Ray Tracing Hao Li http://cs420.hao-li.com 1 Motivation: - - PowerPoint PPT Presentation

7 2 ray tracing
SMART_READER_LITE
LIVE PREVIEW

7.2 Ray Tracing Hao Li http://cs420.hao-li.com 1 Motivation: - - PowerPoint PPT Presentation

Fall 2018 CSCI 420: Computer Graphics 7.2 Ray Tracing Hao Li http://cs420.hao-li.com 1 Motivation: Reflections 2 Motivation: Depth of Field 3 Local Illumination Object illuminations are independent No light scattering between objects


slide-1
SLIDE 1

CSCI 420: Computer Graphics

Hao Li

http://cs420.hao-li.com

Fall 2018

7.2 Ray Tracing

1

slide-2
SLIDE 2

Motivation: Reflections

2

slide-3
SLIDE 3

Motivation: Depth of Field

3

slide-4
SLIDE 4

Local Illumination

  • Object illuminations are independent
  • No light scattering between objects
  • No real shadows, reflection, transmission
  • OpenGL pipeline uses this

4

slide-5
SLIDE 5

Global Illumination

  • Ray tracing (highlights, reflection, transmission)
  • Radiosity (surface inter reflections)
  • Photon mapping
  • Precomputed Radiance Transfer (PRT)

5

slide-6
SLIDE 6

Object Space

  • Graphics pipeline: for each object, render
  • Efficient pipeline architecture, real-time
  • Difficulty: object interactions (shadows, reflections, etc.)

6

slide-7
SLIDE 7

Image Space

  • Ray tracing: for each pixel, determine color
  • Pixel-level parallelism
  • Difficulty: very intensive computation, usually off-line

7

slide-8
SLIDE 8

First idea: Forward Ray Tracing

  • Shoot (many) light rays from each light source
  • Rays bounce off the objects
  • Simulates paths of photons
  • Problem: many rays will
  • miss camera and not 


contribute to image!

  • This algorithm is not


practical

8

slide-9
SLIDE 9

Backward Ray Tracing

  • Shoot one ray from camera through each

pixel in image plane

9

slide-10
SLIDE 10

Generating Rays

10

slide-11
SLIDE 11

Generating Rays

  • Camera is at (0,0,0) and points in the negative z-direction
  • Must determine coordinates of image corners in 3D

11

slide-12
SLIDE 12

Generating Rays

12

image plane center

  • f projection

(COP) field of view angle (fov) ray

x y z x y z side view frontal view h w aspect ratio = w / h

slide-13
SLIDE 13

Generating Rays

13

image plane COP field of view angle (fov)

x y z side view side view

image plane

x y z

f = 1

y = 0 z = 0

y = tan(fov/2) z = −1

y = − tan(fov/2) z = −1

slide-14
SLIDE 14

Generating Rays

14

h w x y z frontal view a = aspect ratio = w / h

x = −a tan(fov/2) y = tan(fov/2) z = −1 x = −a tan(fov/2) y = − tan(fov/2) z = −1

x = a tan(fov/2) y = tan(fov/2) z = −1

x = a tan(fov/2) y = − tan(fov/2) z = −1

x = 0 y = 0 z = −1

slide-15
SLIDE 15

Determining Pixel Color

  • 1. Phong model (local as before)
  • 2. Shadow rays
  • 3. Specular reflection
  • 4. Specular transmission

Steps (3) and (4) require recursion.

15

slide-16
SLIDE 16

Shadow Rays

  • Determine if light “really” 


hits surface point

  • Cast shadow ray from 


surface point to each light

  • If shadow ray hits 

  • paque object, no 


contribution from 
 that light

  • This is essentially


improved diffuse 
 reflection

16

light source

scene

  • bject 2

scene

  • bject 1

image plane ray n shadow ray (blocked) light source camera

slide-17
SLIDE 17

Phong Model

  • If shadow ray


can reach 
 to the light, 
 apply a standard 
 Phong model

17

light source

scene

  • bject

image plane ray n shadow ray (unblocked) light source camera v l

slide-18
SLIDE 18

Where is Phong model applied 
 in this example?
 Which shadow rays are blocked?

18

slide-19
SLIDE 19

Reflection Rays

  • For specular component of illumination
  • Compute reflection ray (recall: backward!)
  • Call ray tracer recursively to determine color

19

slide-20
SLIDE 20

Angle of Reflection

20

  • Recall: incoming angle = outgoing angle
  • .
  • Compute only for surfaces that are reflective

r = 2(l · n)n − l

slide-21
SLIDE 21

Reflections Example

21

www.yafaray.org

slide-22
SLIDE 22

Transmission Rays

  • Calculate light transmitted through surfaces
  • Example: water, glass
  • Compute transmission ray
  • Call ray tracer recursively to determine color

22

slide-23
SLIDE 23

Transmitted Light

  • Index of refraction is speed of light,

relative to speed of light in vacuum

  • Vacuum: 1.0 (per definition)
  • Air: 1.000277 (approximate to 1.0)
  • Water: 1.33
  • Glass: 1.49
  • Compute t using Snell’s law
  • = index for upper material
  • = index for lower material

23

sin(ul) sin(ut) = ηt ηl = η ηl ηt

slide-24
SLIDE 24

Translucency

  • Most real objects are not transparent,


but blur the background image

  • Scatter light on other side of surface
  • Use stochastic sampling


(called distributed ray tracing)

24

slide-25
SLIDE 25

Transmission + Translucency Example

25

www.povray.org

slide-26
SLIDE 26

The Ray Casting Algorithm

26

  • Simplest case of ray tracing
  • 1. For each pixel (x,y), fire a ray from COP through (x,y)
  • 2. For each ray & object, calculate closest intersection
  • 3. For closest intersection point p
  • Calculate surface normal
  • For each light source, fire shadow ray
  • For each unblocked shadow ray, evaluate local Phong

model for that light, and add the result to pixel color

  • Critical operations
  • Ray-surface intersections
  • Illumination calculation
slide-27
SLIDE 27

Recursive Ray Tracing

  • Also calculate specular component
  • Reflect ray from eye on specular surface
  • Transmit ray from eye through transparent surface
  • Determine color of incoming ray by recursion
  • Trace to fixed depth
  • Cut off if contribution

below threshold

27

slide-28
SLIDE 28

Ray Tracing Assessment

  • Global illumination method
  • Image-based
  • Pluses
  • Relatively accurate shadows, reflections, refractions
  • Minuses
  • Slow (intersection computations)
  • Aliasing
  • Inter-object diffuse reflections require many bounces

28

slide-29
SLIDE 29

Raytracing Example I

29

www.yafaray.org

slide-30
SLIDE 30

Raytracing Example II

30

www.povray.org

slide-31
SLIDE 31

Raytracing Example III

31

www.yafaray.org

slide-32
SLIDE 32

Raytracing Example IV

32

www.povray.org

slide-33
SLIDE 33

Summary

  • Ray Casting
  • Shadow Rays and Local Phong Model
  • Reflection
  • Transmission
  • Next lecture: Geometric queries

33

slide-34
SLIDE 34

http://cs420.hao-li.com

Thanks!

34