34
CS 428: Fall 2009 Introduction to Computer Graphics Computer Graphics Raytracing 11/18/2009 1 Andrew Nealen, Rutgers, 2009

CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

CS 428: Fall 2009

Introduction to

Computer GraphicsComputer Graphics

Raytracing

11/18/2009 1Andrew Nealen, Rutgers, 2009

Page 2: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

“Forward” ray tracingFrom the light sources

� Simulate light transport one ray at a time� Simulate light transport one ray at a time

� Rays start from lights + bounce around the scene

� Some hit the camera (extremely few!)

� Very expensive to compute

� Under-sampling! So: nobody does this ☺

11/18/2009 2Andrew Nealen, Rutgers, 2009

Page 3: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

“Backward” ray tracingFrom the eye

� Use ray casting from camera to scene� Use ray casting from camera to scene

� Much faster (all rays say something about image)

� An approximation

� Use known lighting models (diffuse, specular, etc)

� No caustics, inter-object reflection

� (Can be fixed/combined with other techniques…)11/18/2009 3Andrew Nealen, Rutgers, 2009

Page 4: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Raytracing

� Albrecht Dürer „Der zeichner des liegenden

weibes“, 1538

Impression of Velo von Alberti (1404 –1472)

Sorry, but thanks to an

extremely antiquated and

lame attitude w.r.t.

male/female nudity, this

part of the image is not

shown.

11/18/2009 4Andrew Nealen, Rutgers, 2009

Page 5: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� Turner Whitted 1979: Model for Integrating

� Reflection

� Refraction

� Visibility� Visibility

� Shadows

� (Basic) raytracing simulates the light transport

and adheres to the rules of ideal reflection

and refraction

11/18/2009 5Andrew Nealen, Rutgers, 2009

Page 6: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracingAssumptions

� Point light sources

� Materials

� Diffuse mit specular component (Phong model)

� Light transport� Light transport

� Occluding objects (Umbras, but no penumbras)

� No light attenuation

� Only specular light transport between surfaces

(Rays are only followed along directions of ideal

reflection)

11/18/2009 6Andrew Nealen, Rutgers, 2009

Page 7: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracingTurner Whitted [1979]

11/18/2009 7Andrew Nealen, Rutgers, 2009

Page 8: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracingExamples

� Raytracing ist extremely suitable for scenes with many mirroring and transparent (refracting) surfaces

11/18/2009 8Andrew Nealen, Rutgers, 2009

Page 9: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� Synthetic camera

� Defined by an eye point and image (view) plane in

world coordinates

� The image plane is an array of pixels, with the � The image plane is an array of pixels, with the

same resolution as the resulting image

11/18/2009 9Andrew Nealen, Rutgers, 2009

Page 10: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� Rays are cast into the scene from the eye

point through the pixels

11/18/2009 10Andrew Nealen, Rutgers, 2009

Page 11: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� If the ray intersects with more than one

object, then the nearest intersection is drawn

� Otherwise, draw the background color

11/18/2009 11Andrew Nealen, Rutgers, 2009

Page 12: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� If a ray intersects with an object, then

additional rays are cast from the point of

intersection to all light sources

11/18/2009 12Andrew Nealen, Rutgers, 2009

Page 13: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� If these “shadow feelers“ intersect with an

object, then the first intersection point is in

shadow

11/18/2009 13Andrew Nealen, Rutgers, 2009

Page 14: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� If the object is reflective, a reflected ray

(about the surface normal) is cast into the

scene

11/18/2009 14Andrew Nealen, Rutgers, 2009

Page 15: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� If the object is transparent, a refracted ray

(about the surface normal) is cast into the

scene

11/18/2009 15Andrew Nealen, Rutgers, 2009

Page 16: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Recursive raytracing

� New rays are generated for reflection,

transmission (refraction) and shadow feelers

� Rays are parameters of

a recursive functionS

11/18/2009 16Andrew Nealen, Rutgers, 2009

a recursive function

� Detects all visible surfaces

intersected by rays,

shades them, and returns

the result (= color)

S

S

S

eyepixel

Page 17: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Lighting model

� Lighting on a surface is combined of

� Ambient +

� Diffuse +

� Specular (highlights and reflection) +� Specular (highlights and reflection) +

� Transmitted (refracted)

� Equivalent to the Phong-model plus contributions from reflected and refracted rays

11/18/2009 17Andrew Nealen, Rutgers, 2009

Page 18: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

� Lsum = LPhong + rrLr + rtLt

� Lr is the luminance of the reflected ray

� Lt is the luminance of the transmitted ray

� rr is the reflectance (in [0,1]) for ideal reflection

Lighting model

� rr is the reflectance (in [0,1]) for ideal reflection

� rt is the reflectance (in [0,1]) for ideal transmission

11/18/2009 18Andrew Nealen, Rutgers, 2009

R = -E+2(N·E)N

Page 19: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Rays

� Data structure

� Point of origin p + direction d

� Parametric equation

� If d is normalized, t is distance from p to p+td

Andrew Nealen, Rutgers, 2009 11/18/2009 19

Page 20: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Camera setup

Andrew Nealen, Rutgers, 2009 11/18/2009 20

Page 21: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Camera setup

Aspect ratio r = W/H

Andrew Nealen, Rutgers, 2009 11/18/2009 21

Aspect ratio r = W/H

Determine W and H

from θθθθ and r

N n

Page 22: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Intersecting rays with objects

� Object representation?

� Implicit equations make intersections easier

� Surface is a set of points that satisfy

F(x,y,z) = 0F(x,y,z) = 0

� Example: sphere at the origin with radius 1

F(x,y,z) = x2 + y2 + z2 -1

� As opposed to its explicit representation

Andrew Nealen, Rutgers, 2009 11/18/2009 22

Page 23: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Intersecting rays with objects

� Normal vector to an implicit surface

� For the previous example of a sphere

F(x,y,z) = x2 + y2 + z2 -1

n(x,y,z) = [2x, 2y, 2z]T

Andrew Nealen, Rutgers, 2009 11/18/2009 23

Page 24: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Intersecting rays with objects

� Given a ray (p,d)

� Intersection points found by solving

F(p+td) = 0 for t

� Quadratic in t for F(x,y,z) = x2 + y2 + z2 -1

Andrew Nealen, Rutgers, 2009 11/18/2009 24

http://en.wikipedia.org/wiki/Quadratic_equation

Page 25: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

� Implicit equation becomes more complex

� although sphere is still fairly easy

� Transform the ray

with M-1

What if object is not at origin?

with M-1

Andrew Nealen, Rutgers, 2009 11/18/2009 25

Page 26: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

� Implicit equation becomes more complex

� although sphere is still fairly easy

� Transform the ray

with M-1

What if object is not at origin?

with M-1

� Transform back the intersection point(s)

� t is the same in both (don’t normalize M-1d)

� In other words, solve

F(M-1p + t(M-1d)) = 0

Andrew Nealen, Rutgers, 2009 11/18/2009 26

Page 27: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Transforming intersection

� Point

� Normal

Andrew Nealen, Rutgers, 2009 11/18/2009 27

Page 28: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Transforming intersection

� Why (M-1)T for normals?

� Given a vector vo in the tangent plane

then

no ∙ vo = 0 (orthogonal)no ∙ vo = 0 (orthogonal)

noT vo = 0

noT (M-1 M) vo = 0

((M-1)T no)T M vo = 0

Andrew Nealen, Rutgers, 2009 11/18/2009 28

vwnwT = 0

Page 29: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Lighting recap

Andrew Nealen, Rutgers, 2009 11/18/2009 29

Page 30: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Shadows

� Check if anything is

between light and

intersection point

(ip) that would (ip) that would

block light

� Send a ray from ip to

each light to check if light illuminates ip

� Light blocked, tint = 0, otherwise tint = 1

� Will modify later for transparency

Andrew Nealen, Rutgers, 2009 11/18/2009 30

Page 31: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Shadows

� Ray cannot start at ip due to rounding errors

� When finding intersections, use a minimum

acceptable value of t to be some eps > 0

Andrew Nealen, Rutgers, 2009 11/18/2009 31

Page 32: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Ideal reflection

� Mirror reflection by law of reflection

� The incident and reflected ray form the same

angle with the surface normal

� The incident and reflected ray and surface normal � The incident and reflected ray and surface normal

all lie in the same plane

� In polar coordinates:

� For view ray l and (normalized) normal n

r = -l + 2 (l · n) n

θ θr i= and φ φ π

r i= +

11/18/2009 32Andrew Nealen, Rutgers, 2009

Page 33: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Ideal reflection

Geometry of

Reflection law

Geometry of

refraction law

r

θi θr

θ1

θ2

Medium 1

Medium 2

l nr

11/18/2009 33Andrew Nealen, Rutgers, 2009

Page 34: CS 428: Fall 2009 Introduction to Computer Graphics · 2009. 11. 18. · “Backward” ray tracing From the eye Use ray casting from camera to scene Much faster (all rays say something

Ideal reflectionTotal reflection

� Transition from optically dense to less dense

material n2 < n1

� Rays refracted away from the surface normal

� There exists an incident angle θT with refraction � There exists an incident angle θT with refraction

angle of 90º

� Once θT is exceeded

� All light reflected on the

boundary between media

� Total reflection

sin .θT

n

n= 2

1

θT

Medium 1

Medium 2

11/18/2009 34Andrew Nealen, Rutgers, 2009