an introduction to ray tracing

39
1 An Introduction to An Introduction to Ray Tracing Ray Tracing

Upload: nancy

Post on 06-Jan-2016

162 views

Category:

Documents


1 download

DESCRIPTION

An Introduction to Ray Tracing. Photo-Realism. Introduction. What is Ray Tracing? Ray Tracing is a global illumination based rendering method for generating realistic images on the computer In ray tracing, a ray of light is traced in a backwards direction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: An Introduction to  Ray Tracing

11

An Introduction to An Introduction to Ray TracingRay Tracing

Page 2: An Introduction to  Ray Tracing

22

Photo-RealismPhoto-Realism

Page 3: An Introduction to  Ray Tracing

33

Page 4: An Introduction to  Ray Tracing

44

Page 5: An Introduction to  Ray Tracing

55

Page 6: An Introduction to  Ray Tracing

66

Introduction Introduction

What is Ray Tracing?What is Ray Tracing? Ray Tracing is a global illumination based rendering Ray Tracing is a global illumination based rendering

method for generating realistic images on the method for generating realistic images on the computercomputer

In ray tracing, a ray of light is traced in a backwards In ray tracing, a ray of light is traced in a backwards direction. direction.

We start from the eye or camera and trace the ray through a We start from the eye or camera and trace the ray through a pixel in the image plane into the scene and determine what it pixel in the image plane into the scene and determine what it intersectsintersects

The pixel is then set to the color values returned by the ray.The pixel is then set to the color values returned by the ray. If the ray misses all objects, then that pixel is shaded the If the ray misses all objects, then that pixel is shaded the

background color background color

Page 7: An Introduction to  Ray Tracing

77

OverviewOverview

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

Page 8: An Introduction to  Ray Tracing

88

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

Page 9: An Introduction to  Ray Tracing

99

Algorithm – Ray castingAlgorithm – Ray casting

Page 10: An Introduction to  Ray Tracing

1010

Ray TracingRay Tracing

Sometimes a ray misses all objectsSometimes a ray misses all objects

Page 11: An Introduction to  Ray Tracing

1111

Ray Tracing (contd.)Ray Tracing (contd.)

Sometimes a ray hits an objectSometimes a ray hits an object

Page 12: An Introduction to  Ray Tracing

1212

Ray Tracing (contd.)Ray Tracing (contd.)

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

Page 13: An Introduction to  Ray Tracing

1313

Ray Tracing (contd.)Ray Tracing (contd.)

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

Page 14: An Introduction to  Ray Tracing

1414

Ray Tracing (contd.)Ray Tracing (contd.)

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

Page 15: An Introduction to  Ray Tracing

1515

Ray Tracing (contd.)Ray Tracing (contd.)

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

Page 16: An Introduction to  Ray Tracing

1616

Ray Tracing (contd.)Ray Tracing (contd.)

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

Page 17: An Introduction to  Ray Tracing

1717

Ray Tracing (contd.)Ray Tracing (contd.)

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

Page 18: An Introduction to  Ray Tracing

1818

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 19: An Introduction to  Ray Tracing

1919

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 20: An Introduction to  Ray Tracing

2020

Ray object intersectionRay object intersection

Ray polygon intersectionRay polygon intersectionPlug the ray equation into the implicit Plug the ray equation into the implicit

representation of the surfacerepresentation of the surfaceSolve for Solve for “t”“t”Substitute for Substitute for “t”“t” to find point of intersection to find point of intersectionCheck if the point of intersection falls within Check if the point of intersection falls within

the polygonthe polygon

Page 21: An Introduction to  Ray Tracing

2121

Ray object intersectionRay object intersection

Ray sphere intersectionRay sphere intersection Implicit form of sphere given center Implicit form of sphere given center (a,b,c)(a,b,c) and radius and 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 22: An Introduction to  Ray Tracing

2222

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

Page 23: An Introduction to  Ray Tracing

2323

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

Page 24: An Introduction to  Ray Tracing

2424

ReflectionReflection

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

nnanna

nnna

nn

na

n

n

n

nam

ˆˆˆ180cosˆ

1ˆˆ

1

2

nnaa

mammamer

ˆˆ2

2

1180

Page 25: An Introduction to  Ray Tracing

2525

ReflectionReflection

Page 26: An Introduction to  Ray Tracing

2626

ReflectionReflection

Page 27: An Introduction to  Ray Tracing

2727

ReflectionReflection

Page 28: An Introduction to  Ray Tracing

2828

ReflectionReflection

Page 29: An Introduction to  Ray Tracing

2929

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

Page 30: An Introduction to  Ray Tracing

3030

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

Page 31: An Introduction to  Ray Tracing

3131

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 uu

nk

nnukku

kkunnuu

ii cossin

nk

nnTkkT

kkTnnTT

rr cossin

nuk ii

cossin

1

Page 32: An Introduction to  Ray Tracing

3232

RefractionRefraction Substituting in Substituting in TT

From Snell’s LawFrom Snell’s Law

Solving for Solving for TT

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 33: An Introduction to  Ray Tracing

3333

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 34: An Introduction to  Ray Tracing

3434

Ray tracing flowRay tracing flow

Figure outreflected/refracted raydirectionand recurse

Local Phongillumination

Page 35: An Introduction to  Ray Tracing

3535

Super-samplingSuper-sampling

Ray tracing is a point-sampling processRay tracing is a point-sampling process Take discrete looks at the scene along individual rays Take discrete looks at the scene along individual rays

passing through each pixelpassing through each pixel Reduce aliasing due to this discrete signal Reduce aliasing due to this discrete signal

samplingsampling

Page 36: An Introduction to  Ray Tracing

3636

Super-samplingSuper-sampling Instead of shooting one ray per pixel, shoot four rays through the Instead of shooting one ray per pixel, shoot four rays through the

corners of a pixelcorners of a pixel Color at the pixel is the average of the colors at each cornersColor at the pixel is the average of the colors at each corners

Adaptive super-sampling (Whitted’s approach)Adaptive super-sampling (Whitted’s approach) Compute the intensity variation between the four corners with the Compute the intensity variation between the four corners with the

averageaverage Shoot more rays through corners with higher intensity variationShoot more rays through corners with higher intensity variation Compute final color as a weighted average rather than the regular Compute final color as a weighted average rather than the regular

averageaverage

Page 37: An Introduction to  Ray Tracing

3737

Using ExtentsUsing Extents

Ray tracing is slow, performing the same Ray tracing is slow, performing the same functions.functions.

Most of the time is spent in computing Most of the time is spent in computing intersectionsintersectionsEach ray should be intersected with every Each ray should be intersected with every

object in the sceneobject in the sceneEach ray, spawns out reflected/transmitted Each ray, spawns out reflected/transmitted

rays which have to be interested with the rays which have to be interested with the objects in the sceneobjects in the scene

Page 38: An Introduction to  Ray Tracing

3838

Using ExtentsUsing Extents Extent of an object is a shape that encloses the objectExtent of an object is a shape that encloses the object Compute complicated intersections if and only if the ray Compute complicated intersections if and only if the ray

hits the extenthits the extent Two shapes most commonly used as extentsTwo shapes most commonly used as extents

Sphere – specified by a center and radius (C , r)Sphere – specified by a center and radius (C , r) Box – specified by sides aligned to the coordinate axisBox – specified by sides aligned to the coordinate axis

Page 39: An Introduction to  Ray Tracing

3939

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

http://www.cs.berkeley.edu/~efros/java/tracer/tracer.htmlhttp://www.cs.berkeley.edu/~efros/java/tracer/tracer.html 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