Top Banner
1 Ray Tracing Ray Tracing Mani Thomas Mani Thomas CISC 440/640 CISC 440/640 Computer Graphics Computer Graphics
44
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

11

Ray TracingRay Tracing

Mani ThomasMani ThomasCISC 440/640CISC 440/640

Computer GraphicsComputer Graphics

Page 2: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

22

Photo-RealismPhoto-Realism

Created by David Derman – CISC 440

Page 3: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

33

Created by Jan Oberlaender – CISC 640

Page 4: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

44

Created by Jan Oberlaender – CISC 640

Page 5: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

55Created by Donald Hyatt http://www.tjhsst.edu/~dhyatt/superap/povray.html

Page 6: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

66

Bunny – A computer animated Bunny – A computer animated short filmshort film

Blue Sky Studios IncA film by Chris Wedge with music by Tom Waits and produced by Nina Rappaport

Page 7: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

77

Introduction - LightIntroduction - Light

Three Ideas about lightThree Ideas about lightLight rays travel in straight linesLight rays travel in straight linesLight rays do not interfere with each other if Light rays do not interfere with each other if

they crossthey crossLight rays travel from light source to the eye, Light rays travel from light source to the eye,

but the physics is invariant under path but the physics is invariant under path reversal (Helmholtz reciprocity)reversal (Helmholtz reciprocity)P. Sen, et al., “Dual Photography”, SIGGRAPH P. Sen, et al., “Dual Photography”, SIGGRAPH

20052005 Novel photographic technique to interchange the lights Novel photographic technique to interchange the lights

and cameras in a sceneand cameras in a scene

Page 8: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

88

Introduction - Ray tracingIntroduction - Ray tracing

What is Ray Tracing?What is Ray Tracing? Ray Tracing is a global Ray Tracing is a global

illumination based illumination based rendering method for rendering method for generating realistic generating realistic images on the computerimages on the computer

OriginatorsOriginators Appel 1968 Appel 1968 Goldstein and Nagel Goldstein and Nagel Whited 1979Whited 1979

Courtesy of Pat Hanrahan, Computer Graphics: Image Synthesis Techniques

Page 9: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

99

Introduction – Ray tracingIntroduction – Ray tracing

Appel Appel Ray CastingRay Casting

Goldstein and Nagel Goldstein and Nagel Scene IlluminationScene Illumination

Whited Whited Recursive ray tracing (reflection and refraction)Recursive ray tracing (reflection and refraction) Forward and Backward Ray tracingForward and Backward Ray tracing

Courtesy of Pat Hanrahan, Computer Graphics: Image Synthesis Techniques

Page 10: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1010

Introduction – Ray tracingIntroduction – Ray tracing

Forward Ray tracingForward Ray tracing Rays from light source Rays from light source

bounce of objects bounce of objects before reaching the before reaching the cameracamera

Computational Computational wastagewastage

Backward Ray tracingBackward Ray tracing Track only those rays Track only those rays

that finally made it to that finally made it to the camerathe camera

Courtesy: Angel

Page 11: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1111

Ray CastingRay Casting

Ray CastingRay Casting visible surfaces of visible surfaces of

objects are found by objects are found by throwing (or casting) throwing (or casting) rays of light from the rays of light from the viewer into the sceneviewer into the scene

Ray TracingRay Tracing Extension to Ray Extension to Ray

castingcasting Recursively cast rays Recursively cast rays

from the points of from the points of intersectionintersection

Courtesy: Angel

Page 12: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1212

Ray castingRay casting

In ray casting, a ray of light is traced in a In ray casting, a ray of light is traced in a backwards direction. backwards direction. We start from the eye or camera and trace the We start from the eye or camera and trace the

ray through a pixel in the image plane into the ray through a pixel in the image plane into the scene and determine what it intersectsscene and determine what it intersects

The pixel is then set to the color values The pixel is then set to the color values returned by the ray.returned by the ray.

If the ray misses all objects, then that pixel is If the ray misses all objects, then that pixel is shaded the background color shaded the background color

Page 13: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1313

Algorithm – Ray castingAlgorithm – Ray casting

Courtesy F.S. Hill, “Computer Graphics using OpenGL”

Page 14: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1414

Ray tracing - overviewRay tracing - overview

Ray casting finds the visible surfaces of objectsRay casting finds the visible surfaces of objects Ray tracing determines what each visible Ray tracing determines what each visible

surface looks likesurface looks like This extra curiosity is quite heavy on your processor This extra curiosity is quite heavy on your processor

But it allows you to create effects that are very But it allows you to create effects that are very difficult or even impossible to do using other difficult or even impossible to do using other methods.methods. ReflectionReflection TransparencyTransparency ShadowsShadows

Courtesy: http://www.geocities.com/jamisbuck/raytracing.html

Page 15: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1515

Ray tracing - overviewRay tracing - overview Ray tracing algorithm is a “finitely” recursive image Ray tracing algorithm is a “finitely” recursive image

renderingrendering First stage: Like ray castingFirst stage: Like ray casting

Shoot a ray from the eye (Primary ray)Shoot a ray from the eye (Primary ray) Determine all the objects that intersect the rayDetermine all the objects that intersect the ray Find the nearest of intersectionsFind the nearest of intersections

Second stage: Second stage: Recurses by shooting more rays from the point of intersection Recurses by shooting more rays from the point of intersection

(Secondary rays)(Secondary rays) Find the objects that are reflected at that pointFind the objects that are reflected at that point Find other objects that may be seen through the object at that pointFind other objects that may be seen through the object at that point Find out light sources that are directly visible from that pointFind out light sources that are directly visible from that point

Repeat the second stage until requiredRepeat the second stage until required

Page 16: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1616

Ray Tracing – exampleRay Tracing – example

Sometimes a ray misses all objectsSometimes a ray misses all objects

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 17: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1717

Ray Tracing – exampleRay Tracing – example

Sometimes a ray hits an objectSometimes a ray hits an object

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 18: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1818

Ray Tracing – exampleRay Tracing – example

Is the intersected point in shadow?Is the intersected point in shadow? ““Shadow Rays” to light sourceShadow Rays” to light source

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 19: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

1919

Ray Tracing – exampleRay Tracing – example

Shadow rays intersect another objectShadow rays intersect another objectFirst intersection point in shadow of the First intersection point in shadow of the

second objectsecond object

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 20: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2020

Ray Tracing – exampleRay Tracing – example

Shadow rays intersect another objectShadow rays intersect another objectFirst intersection point in shadow of the First intersection point in shadow of the

second objectsecond object

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 21: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2121

Ray Tracing - exampleRay Tracing - example

Reflected ray generated at point of Reflected ray generated at point of intersectionintersectionTested with all the objects in the sceneTested with all the objects in the scene

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 22: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2222

Ray Tracing - exampleRay Tracing - example

Local illumination model applied at the Local illumination model applied at the point of intersectionpoint of intersection

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 23: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2323

Ray Tracing – exampleRay Tracing – example

Transparent objectTransparent objectSpawn a transmitted ray and test against all Spawn a transmitted ray and test against all

objects in the sceneobjects in the scene

created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

Page 24: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2424

Requirements for Ray tracingRequirements for Ray tracing Compute 3D ray into the scene for each 2D image pixelCompute 3D ray into the scene for each 2D image pixel Compute 3D intersection point of ray with nearest object Compute 3D intersection point of ray with nearest object

in scenein scene Test each primitive in the scene for intersectionTest each primitive in the scene for intersection Find nearest intersectionFind nearest intersection

Recursively spawn rays from the point of intersectionRecursively spawn rays from the point of intersection Shadow RaysShadow Rays Reflected raysReflected rays Transmitted raysTransmitted rays

Accumulate the color from each of the spawned rays at Accumulate the color from each of the spawned rays at the point of intersectionthe point of intersection

Page 25: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2525

Ray object intersectionRay object intersection

Equation of a rayEquation of a ray ““S”S” is the starting point and is the starting point and “c” “c” is the direction of the is the direction of the

rayray Given a surface in implicit form Given a surface in implicit form F(x,y,z)F(x,y,z)

plane:plane: sphere:sphere: cylinder:cylinder:

All points on the surface satisfy All points on the surface satisfy F(x,y,z)=0F(x,y,z)=0 Thus for ray Thus for ray r(t)r(t) to intersect the surface to intersect the surface The hit time can be got by solvingThe hit time can be got by solving

ttr cS

1,, 222 zyxzyxF

101,, 22 zyxzyxF

0 hittF cS

0trF

ddczbyaxzyxF xn,,

Page 26: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2626

Ray object intersectionRay object intersection

3D Object Intersection: http://www.realtimerendering.com/int/

Page 27: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2727

Ray plane intersectionRay plane intersection

Equation of a rayEquation of a rayEquation of a planeEquation of a plane

n n is the normal to the plane and d is the is the normal to the plane and d is the distance of the plane from the origindistance of the plane from the origin

Substituting and solving for tSubstituting and solving for t

ttr cS

ddczbyaxzyxF xn,,

0

0,,

dt

dzyxFtrtr

cSn

xn

cnSn

cnSn

d

tdt 0

Page 28: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2828

Ray triangle intersectionRay triangle intersection Tomas Möller and Ben Trumbore, “Fast, minimum Tomas Möller and Ben Trumbore, “Fast, minimum

storage ray-triangle intersection”, storage ray-triangle intersection”, Journal of graphics Journal of graphics toolstools, 2(1):21-28, 1997, 2(1):21-28, 1997

Barycentric coordinatesBarycentric coordinates

pp is a point in a triangle with vertices is a point in a triangle with vertices PP00, , PP11, , PP22

If If r(t) r(t) belongs to both the line and trianglebelongs to both the line and triangle

Solve for Solve for (t, u, v)(t, u, v) If If (u, v) (u, v) complies with the restriction, then ray complies with the restriction, then ray r(t)r(t) intersects the intersects the

triangletriangle Using Using t t the intersection point can be easily computedthe intersection point can be easily computed

1,0,1 210 vuvuvuvu PPPp

2101 PPPcS vuvuttr

Courtesy of http://www.lighthouse3d.com/opengl/maths/index.php?raytriint

Page 29: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

2929

Ray triangle intersectionRay triangle intersection

• R. J. Segura, F. R. Feito,”Algorithms to test Ray-triangle Intersection Comparative Study”, WSCG 2001

Courtesy of http://www.lighthouse3d.com/opengl/maths/index.php?raytriint

Page 30: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3030

Ray Sphere intersectionRay Sphere intersection

Implicit form of sphere given center Implicit form of sphere given center (a,b,c)(a,b,c) and and radius radius rr

Intersection withIntersection with r(t) r(t) gives gives By the identityBy the identity

the intersection equation is a quadratic in the intersection equation is a quadratic in “t”“t”

Solving for “t”Solving for “t” Real solutions, indicate one or two intersectionsReal solutions, indicate one or two intersections Negative solutions are behind the eyeNegative solutions are behind the eye If discriminant is negative, the ray missed the sphereIf discriminant is negative, the ray missed the sphere

),,(,,,22cbazyxr cc pppp

22rt c pcS

bababa 2222

2222222 rtctrt ccc pSpScpcS

2222 rct ccc pSpScpSc

Page 31: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3131

Adding shadowsAdding shadows P is not in shadow with respect to P is not in shadow with respect to

LL11

P is in the shadow of the cube P is in the shadow of the cube with respect to Lwith respect to L22

““Self-shadowing” of P with Self-shadowing” of P with respect to Lrespect to L33

““Shadow Feelers”Shadow Feelers” Spawn a ray from P to the light Spawn a ray from P to the light

sourcessources If there is an intersection of the If there is an intersection of the

shadow ray with any object then shadow ray with any object then P is in shadowP is in shadow

NOTE: Intersection should be NOTE: Intersection should be between the point and light between the point and light source and not behind light source and not behind light sourcesource

Courtesy F.S. Hill, “Computer Graphics using OpenGL”

Page 32: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3232

Adding shadowsAdding shadows

““Self-Shadowing”Self-Shadowing” Always an intersection of Always an intersection of

shadow feeler with shadow feeler with object itselfobject itself

Move start point of the Move start point of the shadow ray towards the shadow ray towards the eye by a small amounteye by a small amount

No intersection with No intersection with itselfitself

Courtesy F.S. Hill, “Computer Graphics using OpenGL”

Page 33: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3333

ReflectionReflection

Given surface normal “Given surface normal “nn” and incident ray “” and incident ray “aa” ” find the reflected ray “find the reflected ray “rr””

adapted from F.S. Hill, “Computer Graphics using OpenGL”

nnanna

nnna

nn

na

n

n

n

nam

ˆˆˆ180cosˆ

1ˆˆ

1

2

nnaa

mammamer

ˆˆ2

2

1180

Page 34: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3434

ReflectionReflection

Created by David Derman – CISC 440

Page 35: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3535

ReflectionReflection

Created by David Derman – CISC 440

Page 36: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3636

ReflectionReflection

Created by David Derman – CISC 440

Page 37: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3737

ReflectionReflection

Created by David Derman – CISC 440

Page 38: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3838

RefractionRefraction

Bending of light rays as it crosses Bending of light rays as it crosses interface between media having different interface between media having different refractive indicesrefractive indices

Snell’s LawSnell’s Law

cc11,c,c22 – Refractive – Refractive

indexindex

2211 sinsin cc

Courtesy F.S. Hill, “Computer Graphics using OpenGL”

Page 39: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

3939

RefractionRefraction Estimation the refracted Estimation the refracted

ray ray TT, given , given u u and and N N (unit (unit vectors)vectors)

If we assume that nIf we assume that nii and and nnrr are the refractive are the refractive indices of the medium indices of the medium having the incoming ray having the incoming ray and refracted ray and refracted ray respectivelyrespectively

Let and be the Let and be the corresponding angle of corresponding angle of incidence and refractionincidence and refraction

Let Let k k be a unit vector be a unit vector perpendicular to perpendicular to NN

By Snell’s Law we haveBy Snell’s Law we have rrii nn sinsin

i r

Adapted from Hearn and Baker, “Computer Graphics with openGL”

Page 40: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

4040

RefractionRefraction Decomposing the Decomposing the

incident ray (incident ray (uu))

Decomposing the Decomposing the refracted ray (refracted ray (TT))

Solving for Solving for kk from from uuAdapted from Hearn and Baker, “Computer Graphics with openGL”

nk

nnukku

kkunnuu

ii cossin

nk

nnTkkT

kkTnnTT

rr cossin

nuk ii

cossin

1

Page 41: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

4141

RefractionRefraction Substituting in Substituting in TT

From Snell’s LawFrom Snell’s Law

Solving for Solving for TT

Adapted from Hearn and Baker, “Computer Graphics with openGL”

nunT ii

rr

cos

sin

sincos

r

i

i

r

n

n

sin

sin

nu

nnu

nunT

ir

ir

r

i

rir

i

r

i

ir

ir

n

n

n

n

n

n

n

n

n

n

coscos

coscos

coscos

Page 42: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

4242

Tree of LightTree of Light Contributions of light grows at each contact pointContributions of light grows at each contact point I is the sum of reflected component RI is the sum of reflected component R11, transmitted , transmitted

component Tcomponent T11 and the local component L and the local component L11 Local component is the ambient, diffuse and specular reflections Local component is the ambient, diffuse and specular reflections

at Pat Phh

RR11 is the sum of R is the sum of R33, T, T33 and local L and local L3 3 and so on ad infinitumand so on ad infinitum

Page 43: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

4343

Ray tracing flowRay tracing flow

Figure outreflected/refracted raydirectionand recurse

Local Phongillumination

Adapted from F.S. Hill and CISC 640/440, Fall 2005

Page 44: 1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics.

4444

ReferencesReferences TextbooksTextbooks

F. S. Hill, “Computer Graphics Using OpenGL”F. S. Hill, “Computer Graphics Using OpenGL” Commonly used ray tracing program (completely Commonly used ray tracing program (completely

free and available for most platforms)free and available for most platforms) http://www.povray.org/http://www.povray.org/

Interesting LinksInteresting Links Interactive Ray Tracer – Alyosha EfrosInteractive Ray Tracer – Alyosha Efros

Ray Tracing explainedRay Tracing explained http://www.geocities.com/jamisbuck/raytracing.htmlhttp://www.geocities.com/jamisbuck/raytracing.html http://www.siggraph.org/education/materials/HyperGrhttp://www.siggraph.org/education/materials/HyperGr

aph/raytrace/rtrace0.htmaph/raytrace/rtrace0.htm