ray tracing in the real world backwards ray tracing
play

Ray Tracing in the real world Backwards Ray Tracing Light is - PDF document

Computer Graphics as Virtual Photography real camera photo Photographic Photography: Ray Tracing Basics I scene (captures processing print light) processing camera Computer 3D tone synthetic model Graphics: models image


  1. Computer Graphics as Virtual Photography real camera photo Photographic Photography: Ray Tracing Basics I scene (captures processing print light) processing camera Computer 3D tone synthetic model Graphics: models image reproduction (focuses simulated lighting) Ray Tracing in the real world Backwards Ray Tracing  Light is emitted from light source Turner Whitted  Bounces off of the environment  Light rays are traced backward from the eye (center of projection), through a  Assumptions viewing plane, into scene to see what it  Light travels in straight rays hits.  Path of light changes based on object interaction.  Can simulate using basic geometry.  The pixel is then set to the color values  Some light will reach and be focused by returned by the ray. camera onto film plane.  This color is a result of the object hit by  Lots of light will not! the ray.  In image synthesis, we are only interested in the light that does Ray Tracing - Basics  Insert Cheesy Ray Tracing Movie Here Sometimes you don’t hit an object 1

  2. Ray Tracing - Basics Ray Tracing - Basics  If you do hit an object, additional rays are spawned and sent into world to determine color at intersection point  Shadow ray  Reflected ray  Transmitted ray Sometimes you do Ray Tracing - Basics Ray Tracing - Basics  Shadow ray  Shadow ray  Ray spawned toward each light source to see if point is in shadow. Ray Tracing Ray Tracing  Reflective Ray  Transmitted ray 2

  3. Recursive Ray Tracing Ray Tracing  Ray Tracing incorporates into a single framework:  Hidden surface removal  Shadow computation  Reflection of light  Refraction of light  Global Specular Interaction  Extremely elegant and compact Ray Tracing Basics Ray Tracing Assignment  Basic Ray Tracing -- Example  For Checkpoint 2:  Trace rays through camera model  Using ray tracing for visible surface determination.  Questions -- Break Whitted Introducing Ray Ray Tracing through the Camera  Use mathematical description of a ray  Issues and objects to determine intersection.  Ray Geometry  Parametric representation of a ray:  Object-Ray Intersection  Origin of ray, P o = (x o ,y o ,z o )  Projection  Direction D = (dx, dy, dz)  Ray ( ω ) = P o + ω D  If D is normalized, then ω will be the distance from origin of the ray. 3

  4. Ray-Object Intersection Ray-Sphere Intersection  Most of the computation in ray tracing  The Sphere is determining ray object-intersection  A sphere can be defined by:  When a ray intersects an object, we  Center ( x c , y c , z c )  Radius r need to know:  Equation of a point ( x s , y s , z s ) on a sphere:  Point of intersection  Normal of surface at point of intersection 2 2 2 2 ( x x ) ( y y ) ( z z ) r � + � + � = s c s c s c Ray-Sphere Intersection Ray-Sphere Intersection  Using the Quadratic Formula  Ray - Sphere Intersection  Substituting ray equation for ( x s , y s , z s ) 2 − − B ± B 4 AC  We get: ω = A ω 2 + B ω + C = 0 2 A  where 2 2 2 A = dx + dy + dz  Note: ω must be positive, otherwise the B = 2 ( dx ( x − x ) + dy ( y − y ) + dz ( z − z )) intersection is BEHIND the origin of the ray o c o c o c 2 2 2 2 C = ( x − x ) + ( y − y ) + ( z − z ) − r o c o c o c Ray-Sphere Intersection Ray-Sphere Intersection Note: If D is normalized  If B 2 – 4C is: < 0 – no real root, no intersection A = dx 2 + dy 2 + dz 2 = 1 and = 0 – one root, ray intersects at sphere’s surface > 0 – two roots, ray goes through sphere. − ± 2 − B B 4 C ω = 2 Use least positive root 4

  5. Ray-Sphere Intersection Ray-Plane Intersection  A plane can be defined by:  Once we found a ω i for the point of  A normal vector and a point on the plane intersection, the actual point is:  It has the equation  (x i , y i , z i ) = (x 0 + dx * ω i , y 0 + dy * ω i , z 0 + dz * ω i )  The normal at the point of intersection is: Ax + By + Cz + F = 0  (x n , y n , z n ) = ((x i - x c )/r, (y i - y c )/r, (z i - z c )/r)  where P n = (A, B, C) gives the normal and if  (We divide by r to normalize!) normalized (A 2 + B 2 + C 2 = 1) , F will the shortest distance to the plane from the origin of world. Ray-Plane Intersection Ray-Plane Intesection  If ( P n • D ) is  Ray - Plane Intersection  For plane with equation:  0 – then ray is parallel to plane, no intersection Ax + By + Cz + F = 0  If ω is  Plug in equation for ray and we get  < 0 – then the ray intersects behind the − ( Ax + By + Cz + F ) origin of the ray…ignore! ω = o o o = − ( P • P + F ) /( P • D ) n 0 n  > 0 – calculate the point of intersection + + Adx Bdy Cdz Ray-Plane Intersection Ray-Polygon Intesection  Find the plane in which the polygon  Once we found a ω i for the point of  sits intersection, the actual point is:  Find the point of intersection between  (x i , y i , z i ) = (x 0 + dx * ω i , y 0 + dy * ω i , z 0 + dz * ω i ) the ray and the plane  And we already have the normal at the  If point of intersection is found, see if point of intersection is: it lies within the boundaries of the  P n = (A, B, C) polygon. 5

  6. Ray-Polygon Intersection Ray-Polygon Intersection  Find the point of intersection between the ray  Find the plane in which the polygon sits and the plane  A plane can be defined by:  Done previously  A normal vector and a point  See if point of intersection lies within the  And has the equation boundaries of the polygon. Ax + By + Cz + F = 0  One algorithm:  Draw line from P i to each polygon vertex  where P n = (A, B, C) gives the normal and if normalized  Measure angles between lines (A 2 + B 2 + C 2 = 1), F will give the shortest distance to  Recall: ( A • B ) = | A || B | cos θ the plane from the origin of the world.  If sum of angles between lines is 360°, polygon contains P i Other Intersections Ray Tracing through the Camera  To add other geometric primitives to  Issues your ray tracer  Ray Geometry  Must mathematically derive the point of  Object-Ray Intersection intersection between a ray and geometric  Projection primitive.  Questions? Projection Ray Tracing through a camera  Set up your scene   Determine position / orientation of objects in  scene.  Spawn a ray and send into scene   Define ray direction (remember to normalize)   Check for closest intersection   Calculate and return color   Display or save final image  6

  7. Introducing Ray Graphics Pipeline  Use mathematical description of a ray and objects to determine intersection. 3D Object 3D World 3D Eye 3D Eye 2D Eye 2D Screen Coordinates Coordinates Coordinates Coordinates Coordinates Coordinates  Parametric representation of a ray: Object Viewing 3D Clipping Projection Window to Viewport  Origin of ray, P o = (x o ,y o ,z o ) Transformation Transformation Mapping  Direction D = (dx, dy, dz)  Ray ( ω ) = P o + ω D  If D is normalized, then ω will be the distance from origin of the ray. Graphics Pipeline Camera Transformations  (u x ,u y ,u z ) are u u u  -eye• u  coordinates of unit u x y z 3D Object 3D World 3D Eye 3D Eye 2D Eye 2D Screen   vector w.r.t. world space Coordinates Coordinates Coordinates Coordinates Coordinates Coordinates v v v -eye• v   x y z M =  Similar for v, n, -eye• n   n n n Object Viewing 3D Clipping Projection Window to Viewport  ( eye ) is the origin of x y z Transformation Transformation Mapping   view space w.r.t world 0 0 0 1   space  If ups are aligned, simply use negative eye location values in the fourth column Projection Spawning rays through camera  Note: Projection not required as this will be  Coordinate spaces done as part of the ray tracing process  Can do in camera space or world space  Camera space P p � � � � u x  Must transform all objects/lights to camera � � � � P p space � v � � y � M =  World space P p � � � � n z  Must transform initial rays to world space � � � � 1 1 � � � � 7

  8. Projection in Camera Space Converting to World Space  The role of cameras can be described as projecting a 3D scene onto a 2D plane P p � � � � x u � � � � P p y v � � M 1 � � � = P p � � � � z n � � � � 1 1 � � � � Inverting a 4x4 Matrix Tips – World Space  Need only transform the location of 1 st “pixel”  Code samples from location on image plane and dx, dy, and dz as  Graphics Gems you move across and down the plane  Ken Perlin  Available on Web  Will link on DIARY Tips – Calculating Color Displaying your image  Find point of intersection  You don’t really need the full power of a 3D API to do ray tracing  Good Safety tip – only consider intersections if they occur past the image  Just need the ability to write color values plane. to pixels  If intersection  Some of the matrix operation routines may be helpful.  Return color  Of object 8

Recommend


More recommend