Docsity

Ray Casting One - Introduction to Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Ray Casting One - Introduction to Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Lecture 16:

Ray Casting

 So far, you have learned to build a “passive”

renderer

 Input: vertices and geometric shapes

 Output: an image

 What happens when a user wants to manipulate

the objects in the scene?

 Say, a user clicks on an object on screen, how do you

know:

 A. which object the user clicked on?

 B. where on the object the user clicked on?

Motivation

 A ray tracer is a mapping of rays from the

camera (eye) through each pixel to the

objects in the scene

 Each pixel returns either:

 Ray intersection with the nearest object in the scene  No intersection

 Unlike Durer’s method, a typical ray

tracer also takes into account of lighting

(and material) information

 To render a scene, a ray is cast from each

pixel, and the returned value (color) is

recorded.

What is a Ray Tracer?

 There are three parts to a ray tracer:

1. Generating rays

 Shoot a ray from the eye through a sample point on the film plane that corresponds to a pixel  Repeat the process for each pixel

2. Ray-Object intersection

 For each object in the scene, compute their intersection point (if one exists)  Record the closest intersection point to the eye

3. Calculate lighting (i.e. color)

 Use illumination model to determine direct contribution from light sources  (For recursive ray tracer), recursively generate secondary rays that might contribute to the color of the pixel (e.g., reflective surfaces or mirrors need to reflect other objects in the scene)

Ray Tracing Fundamentals

 Ray tracing uses the following pseudocode:

for each sample (pixel) on the film plane

  1. determine the closest object in the scene hit by a ray through that pixel
  2. set the color based on the calculation of the illumination model for the intersected object

 Note the distinctions:

 Ray tracing iterates over PIXELS

 Scan conversion iterates over VERTICES

Ray Tracing vs. Scan Conversion

 Ray Origin

 Let’s look at the geometry in the world space coordinate

 We’ll start the ray from the

camera’s position (eye

point). Call that point P

Step 1: Generating a Ray (Solution 1 – World Coord)

 Shoot a ray from P towards a point on the film plane

(which can be thought of as the UV plane in the camera’s

UVN (or UVW ) space). Call this directional vector d.

 In parametric form, any point along the ray can be

described using this form: P + td , where:

P is the ray’s origin (eye point)  d is the unit vector in the direction of the ray  t is a non-negative real value

Q

 Now that we have the point

Q, can we find this other

point S?

 S = Q + a u + b v

 How do we find a and b?

Step 1: Generating a Ray (Solution 1 – World Coord)

S

S Q

(a, b)

Step 1: Generating a Ray (Solution 1 – World Coord)

S Q

(a, b)

Step 1: Generating a Ray (Solution 1 – World Coord)

Questions?

Step 1: Generating a Ray (Solution 2 – Camera Coord)

 Remember that we need to apply this inverse

matrix to the two points that make up the ray

 The eye point P

 The point on the far plane

 Don’t forget to normalize the resulting ray vector

Step 1: Generating a Ray (Solution 2 – Camera Coord)

Questions?