Overview: Ray Tracing & The Perspective Projection Pipeline Lecture #2 Thursday, August 28 2014 About this Lecture! This is an overview.! Think of it as a quick tour moving fast.! Some parts, e.g. math, go by quickly.! We will come back and spend more time.! Why a quick tour?! Context is key and comes first! 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 2
Two Approaches to Graphics! Common starting point:! Create a scene model in world coordinates.! Place a synthetic camera in the scene.! Typically made by combining local models.! Approach #1: Projective Pipeline! Move model into camera coordinates.! Project vertices onto the image plane.! Fill in other pixels (fragment processing). 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 3 Approaches (II)! Approach #2: Ray Tracing! Rays project from pixels into the world model.! Rays intersect objects.! Pass back appearance (illumination) to pixels.! More commonalities! Calculate pixel values for images.! Still have to map image onto screen/printer/etc.! Sometimes called the Workstation Transform 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 4
The Projection Pipeline (in more detail, with cartoons) Step #0: The starting point We start with a set of 3D object models. Most models are polygonal. Every model has its own coordinate frame. Step #1: The model transform Puts every object into a single global coordinate system (frame). e.g. place the teapot on the TV set. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 5 The Projection Pipeline (II) Step #2: The Viewing Transform Converts data from the 3D world coordinate system to a camera-centered (and camera-oriented) 3D coordinate system Note: at this point projection pipeline and ray tracing may start diverging. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 6
The Projection Pipeline (III) Field of View Step #3: Clipping The step eliminates all vertices (data points) falling outside the field of view of your synthetic camera 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 7 The Projection Pipeline (IV) Step #4: Projection This step projects 3D data points onto a 2D image plane, according to the camera parameters (e.g. focal length) 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 8
The Perspective Pipeline (V) Step #5: Rasterization Play connect the dots (well, vertices) to form line segments and closed polygons (collectively, fragments) 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 9 The Perspective Pipeline (VI) Step #6: Fragment Processing This is where surfaces are shaded and hidden surfaces are removed. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 10
The Projection Pipeline (VII) Step #7: Workstation Transform Moves the data from the 2D image plane coordinate system to the 2D coordinate system of your display device Note: this is where the projective pipeline and ray tracing come back together. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 11 Ray Tracing (the alternative) Step #0: The starting point We start with a set of 3D object models. Most models are polygonal. Every model has its own coordinate frame. Step #1: The model transform Puts every object into a single global coordinate system (frame). e.g. place the teapot on the TV set 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 12
Ray Tracing (II) Step #2: 3D Camera model The image plane (representing film or a CCD/ CMOS chip) is a plane located in the 3D world model. This step calculates the 3D position of every pixel on that plane. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 13 Ray Tracing (III) Step #3: Ray Casting Send a ray through every pixel, intersect rays with objects in the world model. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 14
Ray Tracing (IV) Step #4: Diffuse Reflection Calculate rays from surface intersection points to light sources; calculate diffuse reflection and shadows. Source: http://morawietz.me/ 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 15 Ray Tracing (V) L S N S R V C θ θ Q Step #5: Specular & Translucent Reflections Calculate rays in the direction of specular and translucent reflections; recursively calculate appearance 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 16
Ray Tracing (VI) ( ( ) + ki l (( 2N ( N L) L) V ) n ) I = KI l N L l l Relax, we will come back to this properly later. Step #6: Sum reflections, store in pixel Add together diffuse, specular and translucent reflections, store resulting (R,G,B) value in pixel 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 17 Ray Tracing (VII) Step #7: Workstation Transform Moves the data from the 2D image plane coordinate system to the 2D coordinate system of your display device Note: at this last step is where the projective pipeline and ray tracing approaches converge 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 18
Projection Pipeline vs Ray Tracing! Projection Pipeline:! Fast (currently real-time)! Current standard (e.g. video games)! SOA: OpenGL 3.0! Ray Tracing:! More realistic (e.g. inter-reflections)! Getting faster (e.g. Pov-Ray)! Future hardware will make it real-time 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 19 Recent Tour-de-Force http://www.youtube.com/watch?v=h5mrrelxy-w 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 20
Course Plan! Objective: Understand image creation! Assignment 1: Cast a ray! Global coordinates emphasis on basics.! Ray intersection calculations.! Assignment 2: Reference frames! Add proper and distinct coordinate systems! and relate them to each other. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 21 Course Plan (II)! Assignment #3: Better lighting and models! Extend modeling to support complexity! Add multi-bounce lighting! Add richer material properties! Assignment #4: Motion and Transparency! See through objects - refraction! Put things in motion short animations Disclaimer: This is a plan, not a contract, the exact nature of the programming assignments will change. 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 22
A Quick Peak at Modeling Vertices, Polygons and setting up to start geometry in earnest. The Ubiquitous Polygonal Mesh! A surface patch is often a polygon in 3D! 3 or more vertices! Each vertex is an (x, y, z) triple! Vertices are supplied in order! Boundary of polygon goes from vertex #1 to vertex #2 to vertex #N, and back to vertex #1! All vertices must be co-planar! Polygon must be convex 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 24
For Example! A simple (4-vertex) polygon in 3D (0,1,0) (1,1,0) (0,0,0) (1,0,0) 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 Slide 25 Common Mistakes! Order of vertices:! Non co-planar vertices: z x y The polygons above have the same vertices in a different order! The 4th vertex is not in the plane defined by the 1 st three! 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 Slide 26
Surfaces: Connected Polygons! A mesh surface is then just a set of nonoverlapping polygons that share vertices and edges Triangle Strip Quad Mesh http://groups.csail.mit.edu/graphics/classes/6.837/f98/talecture/ 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 Slide 27 Surfaces generally not planar! Although every polygon in the mesh must be.! Patches form a locally linear approximation to a curved surface. Permission to use requested from Daniel Rypl at the Czech Technical University in Prague (8/22/12) 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 28
Meshes as Matrices! A mesh is a set of N 3D vertices! Represented as a 3 N matrix! Each column is a vertex " x 1 x 2 x 3 L x N % $ ' M = $ y 1 y 2 y 3 L y N ' # $ z 1 z 2 z 3 L z N &'! With an index vector to show which vertices belong to which polygon! E.g. ((1,2,3), (2,3,4), ) 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 Slide 29 A Touch of Reality?! How many polygons?! Why make them?! Quote from Wired article:! Animating a Blockbuster: How Pixar Built Toy Story 3 Bobby Podesta, supervising animator of Toy Story 3, has been with Pixar since 1997 and, like most animators, considers himself an actor. My job is to convince you that the stack of polygons on the screen is actually alive, he says. Link to Story: http://www.wired.com/magazine/2010/05/process_pixar/ 8/28/14 Ross Beveridge & Bruce A. Draper, 2014 30