CSE45 Computer Graphics Lecture 8: Computer Projection CSE45 Lecture 8: Computer Projection 1
Review In the last lecture We set up a Virtual Camera Position Orientation Clipping planes Viewing angles Orthographic/Perspective We are ready to project! U P d n d f L q w q h d f w h d n L U P CSE45 Lecture 8: Computer Projection
Preview CSE45 Lecture 8: Computer Projection 3 Near plane Film plane Far plane Viewpor t
Preview The perspective view frustum (i.e., a truncated pyramid) is non-trivial to clip against CSE45 Lecture 8: Computer Projection 4
How do you clip? CSE45 Lecture 8: Computer Projection 5
How do you clip? Check against six planes? Project to a film plane and check against near and far planes? An elegant solution that does clipping and also projection together CSE45 Lecture 8: Computer Projection 6
Preview We first transform the frustum to a canonical volume CSE45 Lecture 8: Computer Projection 7
Canonical View Volume X CSE45 Lecture 8: Computer Projection 8
Canonical View Volume X 1 CSE45 Lecture 8: Computer Projection 9
Canonical View Volume {-1,1,1} {-1,1,0} Far Clipping Plane {-1,-1,1} {1,1,1} {1,-1,1} X 1 {1,1,0} {1,-1,0} Near Clipping Plane Projectors (parallel to ) CSE45 Lecture 8: Computer Projection 10
Canonical View Volume Canonical view volume makes things easy: Easy clipping: Clip against the coordinates range X -1<x<1, -1<y<1, 0<z<1 1 CSE45 Lecture 8: Computer Projection 11
Canonical View Volume Canonical view volume makes things easy: Easy clipping: Clip against the coordinates range -1<x<1, -1<y<1, 0<z<1 X 1 Easy projecting: drop the coordinate! (because viewing plane is the X plane, and projectors are parallel to axis) (Xc, c, c) Coordinates in the canonical volume (Xc, c) Projected D coordinates CSE45 Lecture 8: Computer Projection 1
Viewing Transformation The transformation that warps the perspective frustum to the canonical view volume Transforms world coordinates {x w,y w,z w } into canonical coordinates {x c,y c,z c } U L q w P d n {x w,y w,z w } q h {x c,y c,z c } X d f 1 CSE45 Lecture 8: Computer Projection 13
Camera Coordinate System First, let s setup a coordinate system for the camera Origin at the camera Three axes: right (u), straight-up (v), negative look (n) Unit vectors forming an orthonormal, right-hand basis n u v P U L CSE45 Lecture 8: Computer Projection 14
Camera Coordinate System Computing n Opposite to look vector L, normalized n = - L L n L P CSE45 Lecture 8: Computer Projection 15
Camera Coordinate System Computing v Projection of up vector U onto the camera plane, normalized n v P U L CSE45 Lecture 8: Computer Projection 16
Camera Coordinate System Computing v Projection of up vector U onto the camera plane, normalized n v P U L CSE45 Lecture 8: Computer Projection 17
Camera Coordinate System Computing u Cross product of v and n n u v P U L CSE45 Lecture 8: Computer Projection 18
Camera Coordinate System Computing u Cross product of v and n n u v P U L CSE45 Lecture 8: Computer Projection 19
Camera Coordinate System Summary Three axes, computed from look vector L and up vector U: n v U L u,v,n form a camera coordinate system u P CSE45 Lecture 8: Computer Projection 0
Computing Viewing Transformation Two steps Step 1: align camera coordinate system P,u,v,n with world coordinate system O,X,, Step : scale and stretch the frustum to the cuboid CSE45 Lecture 8: Computer Projection 1
Step1 X 1 v n u CSE45 Lecture 8: Computer Projection
Step1 v 1 X n u CSE45 Lecture 8: Computer Projection 3
Step1 n v u 1 X CSE45 Lecture 8: Computer Projection 4
Step 1 First, translate the eye point P to the origin Let P have coordinates (p x,p y,p z ) O (P) CSE45 Lecture 8: Computer Projection 5
Step 1 (cont) Then, rotate the three axes u,v,n to X,, Let s set up the equation to solve for the rotation matrix (R): Note the homogenous coordinates for a vector ends with 0! In matrix form: R u x v x n x 0 u y v y n y 0 u z v z n z 0 0 0 0 1 = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 CSE45 Lecture 8: Computer Projection 6
Step 1 (cont) This is a matrix inversion problem: u x v x n x 0 R = M - 1 u where M = y v y n y 0 u z v z n z 0 0 0 0 1 Since M is an orthonormal matrix: R = M T CSE45 Lecture 8: Computer Projection 7
Step 1 - Done Eye point at origin, looking down negative z axis (v) (n) (P) (u) X 1 CSE45 Lecture 8: Computer Projection 8
Step X 1 CSE45 Lecture 8: Computer Projection 9
Step Some preparations First, make width/height angles to be π/ Non-uniform scaling in X, coordinates q h h h 1 A look down the X axis CSE45 Lecture 8: Computer Projection 30
Step Some preparations First, make width/height angles to be π/ Non-uniform scaling in X, coordinates q h h h 1 A look down the X axis CSE45 Lecture 8: Computer Projection 31
I hate cotangent, arctan, cosecant... Why call arctan? According to wikipedia the arc whose cosine is x the angle whose cosine is x is the same as CSE45 Lecture 8: Computer Projection 3
Step (cont) Some preparations Next, push the far plane from =-d f to =-1 Uniform scaling in all three coordinates S xyz = 1 df 0 0 0 0 1 df 0 0 0 0 1 df 0 0 0 0 1 d f 1 CSE45 Lecture 8: Computer Projection 33
Step (cont) Where we are now: 1 -d n /d f -1-1 A look down the X axis (same picture when looking down ) CSE45 Lecture 8: Computer Projection 34
Step (cont) Perspective transformation Stretching and flipping the truncated pyramid to the cuboid Change range: ([-d n /d f,-1] -> [0,1]) Stretch in X plane: Non-uniform stretching based on z 1-1 1 0 -d n /d f -1 A look down the X axis CSE45 Lecture 8: Computer Projection 35
Homogeneous coordinate revisited is deep and has interesting meanings... https://en.m.wikipedia.org/wiki/homogeneous_coordinates In short (x, y, z, 1) and (x, y, z, ) are the same point. (x, y, z, 1) and (-3x, -3y, -3z, -3) are the same point. CSE45 Lecture 8: Computer Projection 36
Step (cont) Perspective transformation D = 1 0 0 0 0 1 0 0 0 0 1 k- 1 0 0-1 0 k k- 1, where k = d n d f Applying D to homogeneous coordinates: Converting from homogeneous coordinates {x,y,z,w} to Cartesian coordinates (divide x,y,z by w) CSE45 Lecture 8: Computer Projection 37
Step (cont) Perspective transformation 1 -k -1 1 0-1 A look down the X axis CSE45 Lecture 8: Computer Projection 38
Putting Together Translation: Rotation: Scaling: T R S xy, S xyz Perspective transformation: D World-to-camera transformation (v) (P) (n) (u) T, R S xy, S xyz, D X 1 CSE45 Lecture 8: Computer Projection 39
Putting Together Complete viewing transformation to bring a point canonical volume: q' = D S xyz S xy R T q q to the (v) T, R (n) (P) (u) S xy, S xyz, D X 1 CSE45 Lecture 8: Computer Projection 40
Clipping After transformation into the canonical volume, each object will be clipped against 6 cuboid faces. Point clipping: checking coordinates range Edge clipping: computing line/plane intersections We will discuss a D version in next lecture. Triangle clipping: can be done by line/plane intersections CSE45 Lecture 8: Computer Projection 41
Projecting Dropping z coordinate Resulting points have range: -1<=x<=1, -1<=y<=1 X 1 CSE45 Lecture 8: Computer Projection 4
Viewport Transform Get viewport (pixel) coordinates Viewport coordinate {0,0} is at top-left corner (0,0) X 1 (0,b-1) (a-1,0) (a-1,b-1) If the viewport is a pixels wide and b pixels high, what is the pixel coordinates for a projected point {x,y}? CSE45 Lecture 8: Computer Projection 43