Ray Tracing Sung-Eui Yoon ( ) Course URL: - - PowerPoint PPT Presentation

ray tracing
SMART_READER_LITE
LIVE PREVIEW

Ray Tracing Sung-Eui Yoon ( ) Course URL: - - PowerPoint PPT Presentation

CS380: Computer Graphics Ray Tracing Sung-Eui Yoon ( ) Course URL: http://sglab.kaist.ac.kr/~sungeui/CG/ Class Objectives Understand overall algorithm of recursive ray tracing Ray generations I ntersection tests and


slide-1
SLIDE 1

CS380: Computer Graphics

Ray Tracing

Sung-Eui Yoon (윤성의)

Course URL: http://sglab.kaist.ac.kr/~sungeui/CG/

slide-2
SLIDE 2

2

Class Objectives

  • Understand overall algorithm of recursive

ray tracing

  • Ray generations
  • I ntersection tests and acceleration methods
  • Basic sampling methods
slide-3
SLIDE 3

3

Various Visibility Algorithm

  • Scan-line algorithm; briefly touched before
  • Z-buffer
  • Ray casting, etc.
slide-4
SLIDE 4

4

Ray Casting

  • For each pixel, find closest object along

the ray and shade pixel accordingly

  • Advantages
  • Conceptually simple
  • Can be extended to handle global

illumination effects

  • Disadvantages
  • Renderer must have access to entire retained model
  • Hard to map to special-purpose hardware
  • Less efficient than rasterization in terms of utilizing spatial

coherence

slide-5
SLIDE 5

5

Recursive Ray Casting

  • Ray casting generally dismissed early on

because of aforementioned problems

  • Gained popularity in when

Turner Whitted (1980) showed this image

  • Show recursive

ray casting could be used for global illumination effects

slide-6
SLIDE 6

6

Ray Casting and Ray Tracing

  • Trace rays from eye into scene
  • Backward ray tracing
  • Ray casting used to compute visibility at

the eye

  • Perform ray tracing for arbitrary rays

needed for shading

  • Reflections
  • Refraction and transparency
  • Shadows
slide-7
SLIDE 7

7

Basic Algorithms of Ray Tracing

  • Rays are cast from the eye point through

each pixel in the image

From kavita’s slides

slide-8
SLIDE 8

8

Shadows

  • Cast ray from the intersection point to each

light source

  • Shadow rays

From kavita’s slides

slide-9
SLIDE 9

9

Reflections

  • I f object specular, cast secondary reflected

rays

From kavita’s slides

slide-10
SLIDE 10

10

Refractions

  • I f object tranparent, cast secondary

refracted rays

From kavita’s slides

slide-11
SLIDE 11

11

An Improved Illumination Model [Whitted 80]

  • Phong model
  • Whitted model
  • S and T are intensity of light from reflection

and transmission rays

  • Ks and Kt are specular and transmission

coefficient

    

numLights 1 j n j s j s j j d j d j a j a r

) ) R V ( I k ) L N ( I k I (k I

s

ˆ ˆ ˆ ˆ

T k S k )) L N ( I k I (k I

t s 1 j j j d j d j a j a r

    

 e_Lights num_Visibl

ˆ ˆ

slide-12
SLIDE 12

12

An Improved Illumination Model [Whitted 80]

T k S k )) L N ( I k I (k I

t s numLights 1 j j j d j d j a j a r

     

ˆ ˆ

Computing reflection and transmitted/refracted rays is based on Snell’s law (refer to Chapter 13.1)

slide-13
SLIDE 13

13

Ray Tree

eye s0 b a d c f e s1 s2 eye a b s0 e f s2 c b s1 R T R R T T

slide-14
SLIDE 14

14

Overall Algorithm of Ray Tracing

  • Per each pixel, compute a ray, R

Def function RayTracing (R)

  • Compute an intersection against objects
  • I f no hit,
  • Return the background color
  • Otherwise,
  • Compute shading, c
  • General secondary ray, R’
  • Perform c’ = RayTracing (R’)
  • Return c+ c’
slide-15
SLIDE 15

15

Ray Representation

  • We need to compute the first surface hit

along a ray

  • Represent ray with origin and direction
  • Compute intersections of objects with ray
  • Return the closest object

p (t)

  • td

     p  d 

slide-16
SLIDE 16

16

Generating Primary Rays

l  d 

slide-17
SLIDE 17

17

Generating Secondary Rays

  • The origin is the intersection point p0
  • Direction depends on the type of ray
  • Shadow rays – use direction to the light source
  • Reflection rays – use incoming direction and

normal to compute reflection direction

  • Transparency/ refraction – use snell’s law
slide-18
SLIDE 18

18

Intersection Tests

Go through all of the objects in the scene to determine the one closest to the origin of the ray (the eye). Strategy: Solve of the intersection of the Ray with a mathematical description of the

  • bject
slide-19
SLIDE 19

19

Simple Strategy

  • Parametric ray equation
  • Gives all points along the ray as a function of

the parameter

  • I mplicit surface equation
  • Describes all points on the surface as the zero

set of a function

  • Substitute ray equation into surface

function and solve for t

p (t)

  • td

     ) p ( f   ) d t

  • (

f    

slide-20
SLIDE 20

20

Ray-Plane Intersection

  • I mplicit equation of a plane:
  • Substitute ray equation:
  • Solve for t:

n p d      n (o td) d        t(n d) d n o d n o t n d                

slide-21
SLIDE 21

21

Generalizing to Triangles

  • Find of the point of intersection on the plane

containing the triangle

  • Determine if the point is inside the triangle
  • Barycentric coordinate method
  • Many other methods

v1 v2 v3 p

slide-22
SLIDE 22

22

Barycentric Coordinates

  • Points in a triangle have positive

barycentric coordinates:

v1 v2 v3 p

) ( ) (

2 1

v v v v v p             

2 1

) 1 ( v v v p             

2 1

v v v p           1      

,where v0 v1 v2

p 

slide-23
SLIDE 23

23

Barycentric Coordinates

  • Points in a triangle have positive

barycentric coordinates:

  • Benefits:
  • Barycentric coordinates can be used for interpolating

vertex parameters (e.g., normals, colors, texture coordinates, etc)

v1 v2 v3 p

2 1

v v v p           1      

,where

slide-24
SLIDE 24

24

Ray-Triangle Intersection

  • A point in a ray intersects with a triangle
  • Three unknowns, but three equations
  • Compute the point based on t
  • Then, check whether the point is on the

triangle

  • Refer to Sec. 4.4.2 in the textbook for the detail

equations

v1 v2 v3 p

) ( ) ( ) (

2 1

v v v v v t p             

slide-25
SLIDE 25

25

Robustness Issues

  • False self-intersections
  • One solution is to offset the origin of the ray

from the surface when tracing secondary rays Secondary ray

slide-26
SLIDE 26

26

Pros and Cons of Ray Tracing

Advantages of Ray Tracing:

  • Very simple design
  • I mproved realism over

the graphics pipeline Disadvantages:

  • Very slow per pixel calculations
  • Only approximates full global illumination
  • Hard to accelerate with special-purpose H/ W
slide-27
SLIDE 27

27

Acceleration Methods

  • Rendering time for a ray tracer depends on the

number of ray intersection tests per pixel

  • The number of pixels X the number of primitives in the scene
  • Early efforts focused on accelerating the ray-
  • bject intersection tests
  • More advanced methods required to make ray

tracing practical

  • Bounding volume hierarchies
  • Spatial subdivision
slide-28
SLIDE 28

28

Bounding Volumes

  • Enclose complex objects within a simple-to-

intersect objects

  • I f the ray does not intersect the simple object then its contents

can be ignored

  • The likelihood that it will strike the object depends on how

tightly the volume surrounds the object.

Potentially tighter fit, but with higher computation

slide-29
SLIDE 29

29

Hierarchical Bounding Volumes

  • Organize bounding volumes as a tree
  • Each ray starts with the root BV of the tree

and traverses down through the tree

r         

slide-30
SLIDE 30

30

Spatial Subdivision

Idea: Divide space in to subregions

  • Place objects within a subregion into a list
  • Only traverse the lists of subregions that the ray

passes through

  • “Mailboxing” used to avoid multiple test with
  • bjects in multiple regions
  • Many types
  • Regular grid
  • Octree
  • BSP tree
  • kd-tree
slide-31
SLIDE 31

31

Kd-tree: Example

slide-32
SLIDE 32

32

Kd-tree: Example

slide-33
SLIDE 33

33

Kd-tree: Example

slide-34
SLIDE 34

34

Example

slide-35
SLIDE 35

35

Kd-tree: Example

What about triangles overlapping the split?

slide-36
SLIDE 36

36

Kd-tree: Example

slide-37
SLIDE 37

37

Split Planes

  • How to select axis & split plane?
  • Largest dimension, subdivide in middle
  • More advanced:
  • Surface area heuristic
  • Makes large difference
  • 50% -100% higher overall speed
slide-38
SLIDE 38

38

Median vs. SAH

(from [Wald04])

slide-39
SLIDE 39

39

Ray Tracing with kd-tree

  • Goal: find closest hit with scene
  • Traverse tree front to back

(starting from root)

  • At each node:
  • I f leaf: intersect with triangles
  • I f inner: traverse deeper
slide-40
SLIDE 40

40

Other Optimizations

  • Shadow cache
  • Adaptive depth control
  • Lazy geometry loading/ creation
slide-41
SLIDE 41

41

Distributed Ray Tracing [Cook et

  • al. 84]
  • Cook et al. realized that ray-tracing, when

combined with randomized sampling, which they called “jittering”, could be adapted to address a wide range of rendering problems:

slide-42
SLIDE 42

42

Soft Shadows

  • Take many samples from area light source

and take their average

  • Computes fractional visibility leading to

penumbra

slide-43
SLIDE 43

43

Antialiasing

  • The need to sample is problematic because

sampling leads to aliasing

  • Solution 1: super-sampling
  • I ncreases sampling rate, but does not completely eliminate

aliasing

  • Difficult to completely eliminate aliasing without prefiltering

because the world is not band-limited

slide-44
SLIDE 44

44

Antialiasing

  • Solution 2: distribute the samples randomly
  • Converts the aliasing energy to noise which is less
  • bjectionable to the eye

Instead of casting one ray per pixel, cast several sub- sampling. Instead of uniform sub- sampling, jitter the pixels slightly off the grid.

slide-45
SLIDE 45

45

Jittering Results for Antialiasing

2x2 sub-sampling

slide-46
SLIDE 46

46

Depth-of-Field

  • Rays don’t have to all originate from a single point.
  • Real cameras collects rays over an aperture
  • Can be modeled as a disk
  • Final image is blurred away from the focal plane
  • Gives rise to depth-of-field effects
slide-47
SLIDE 47

47

Depth of Field

lens image plane focal plane

slide-48
SLIDE 48

48

Depth of Field

  • Start with normal eye ray and find

intersection with focal plane

  • Choose jittered point on lens and trace line

from lens point to focal point

lens focal plane

slide-49
SLIDE 49

49

Motion Blur

  • Jitter samples through time
  • Simulate the finite interval that a shutter is
  • pen on a real camera
slide-50
SLIDE 50

50

Motion Blur

slide-51
SLIDE 51

51

Complex Interreflection

  • Model true reflection behavior as described by a full

BRDF

  • Randomly sample rays over the hemisphere, weight

them by their BRDF value, and average them together

  • This technique is called “Monte Carlo I ntegration”
slide-52
SLIDE 52

52

Related Courses

  • CS580: Advanced Computer Graphics
  • Focus on rendering techniques that generate

photo-realistic images

  • CS482: I nteractive Computer Graphics
  • I nteractive global illumination implemented by

rasterization approaches

  • Techniques used in recent games
  • I ’ll teach it at Fall of 2015