Chap 3 Viewing Pipeline Reading: Angel s Interactive Computer Graphics, Sixth ed. Sections 4.~4.7 Chap 3 View Pipeline, Comp. Graphics (U) CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Outline View parameters setting Projection in OpenGL Simple perspective/parallel projection Perspective-projection matrix View volume clipping Chap 3, View Pipeline (CG-U) 2 CGGM Lab.,CS Dept.,NCTU, Jung Hong Chuang
Viewing Pipeline Review.. View projection View transform View-Volume Clipping in homogeneous space Window-viewport mapping Chap 3, View Pipeline (CG-U) 3 CGGM Lab.,CS Dept.,NCTU, Jung Hong Chuang
A Practical Viewing System Review.. Users specify Parameters for view coordinate system A camera position C a viewing direction vector N an upvector V. View volume information Projection type A view plane distance d (= near clipping plane distance), and a far clipping plane distance f. A view window on the view plane Chap 3, View Pipeline (CG-U) 4 CGGM Lab.,CS Dept.,NCTU, Jung Hong Chuang
Viewing Parameters Review.. -n View coordinate system World coordinate system Here, without near and far clipping planes Chap 3, View Pipeline (CG-U) 5 CGGM Lab.,CS Dept.,NCTU, Jung Hong Chuang
OpenGL Setting for viewing system - In OpenGL, glulookat() function alters the model-view matrix glulookat(eyex,eyey,eye,atx,aty,at,upx,upy,up) By default a camera at the origin of the word frame pointing in the - direction the model-view matrix is initially an identity matrix. Chap 3, View Pipeline (CG-U) 6 CGGM Lab.,CS Dept.,NCTU, Jung Hong Chuang
OpenGL Setting for viewing system -2 Look-at function Eyepoint eye, specified in the world frame, determines VRP At point at, specified in the world frame Up vector up glulookat(eyex,eyey,eye,atx,aty,at,upx,upy,up) Defines the model-view matrix glmatrixmode(gl_modelview) glloadidentity(); glulookat(eyex,eyey,eye,atx,aty,at,upx,upy,up) Chap 3, View Pipeline (CG-U) 7 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang
OpenGL Setting for viewing system -3 Derive (u,v,n) defined in world coor. sys. n = eye - at Negative of viewing direction N v: view up vector up if up is perpendicular to n u = v x n up may not be perpendicular to n v = up - its projection in direction of n, or First do u = up x n, then v=n x u Chap 3, View Pipeline (CG-U) 8 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang
OpenGL Setting for viewing system -4 Chap 3, View Pipeline (CG-U) 9 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang
OpenGL Specifying projection information Properties of camera focal length of lens or the sie of the film plane, i.e., angle of view. Projection parameters Projection type View frustum View plane distance Window or angle of view Front and back clipping plane distances near (>), far (>) Chap 3, View Pipeline (CG-U) CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang
Viewing Pipeline - Review.. View transform Tview world coord. sys. -> view coord. sys. For simpler and faster clipping and projection Chap 3, View Pipeline (CG-U) CGGM Lab.,CS Dept.,NCTU, Jung Hong Chuang
Viewing Pipeline - 2 Review.. View transform View transform matrix T view [ x v, y v, v, ] = Tview [x w, y w, w, ] T T view can be written as T view = B T, where T(-C) translates the world coordinate origin to C. B rotates any vector expressed in the world coordinate system into the view coordinate system by mapping (u,v,n) to (e,e 2,e 3 ). Chap 3, View Pipeline (CG-U) 2 CGGM Lab.,CS Dept.,NCTU, Jung Hong Chuang
Chap 3, View Pipeline (CG-U) 3 CGGM Lab.,CS Dept., NCTU, Jung Hong Chuang Viewing Pipeline - 3 View transform : maps the eye to (,,) y x y x eye eye eye T eye eye eye T T
Chap 3, View Pipeline (CG-U) 4 CGGM Lab., CS Dept., NCTU, Jung Hong Chuang Viewing Pipeline - 4 View transform So are orthonormal,,and, Since to ( ) to (), to ( ), : maps y x y x y x y x y x y x y y y x x x n n n v v v u u u B n n n v v v u u u B n v u n v u n v u n v u B,, n,, v,, u B
Viewing Pipeline - 5 Review.. View projection view coord. sys. -> screen coord. sys. Convert view volume to normalied view volume and then do orthogonal projection Why and How? - Mapping view volume to normalied view volume. Easy view-volume clipping and projection, and Standard sied window. - Chap 3, View Pipeline (CG-U) 5 CGGM Lab., CS Dept., NCTU, Jung Hong Chuang
Projection normaliation - Eye coordinate system: right-handed system Viewing direction: - Normalied device coord.: left-handed system Viewing direction: + Chap 3, View Pipeline (CG-U) 6 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Projection normaliation -2 = Perspective projection Orthogonal projection of the distorted object Chap 3, View Pipeline (CG-U) 7 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Projection normaliation -3 Projection normaliation Converts all projections into orthogonal projection by distorting the objects such that the orthogonal projection of the distorted objects is the same as the desired projection of the original objects. Converting view volume to normalied view volume, followed by the orthogonal projection Reasons Easy for view volume clipping Normaliation let us clip against a simple cube regardless of type of projection Chap 3, View Pipeline (CG-U) 8 CGGM Lab., CS Dept.,NCTU Jung Hong Chuang
Projection normaliation -4 Reasons Easy for view volume/back-face culling The nonsingular homogeneous transformation retains meaningful depth value along the projectors that is necessary for HSR. Rather than derive a different projection matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume, allowing us to use standard transformations in the pipeline Chap 3, View Pipeline (CG-U) 9 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Projection normaliation -5 Reasons This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping Delay final projection until end Important for hidden-surface removal to retain depth information as long as possible Chap 3, View Pipeline (CG-U) 2 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Projection normaliation -6 Perspective projection is broken into two parts Perspective transformation + perspective division (back to 3D) Converts the view volume to a normalied view volume, called canonical view volume Objects are distorted in a manner that yields the desired projection through the second step. Orthogonal projection of the distorted objects Need to make sure Correct projection Meaningful depth Chap 3, View Pipeline (CG-U) 2 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Projection normaliation -7 Perspective transformation = Perspective projection = Perspective transform + perspective division + orthographic projection Perspective projection Orthogonal projection of the distorted object Chap 3, View Pipeline (CG-U) 22 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Simple perspective projection (w/o view volume) - In 3D: x x y y p p p d d d -d x y p p xd yd -d d is the distance from eye to view plane Nonlinear!! No matrix form!! -d -d Chap 3, View Pipeline (CG-U) 23 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Simple perspective projection (w/o view volume) -2 Perspective projection Preserves lines, but it is nonlinear, not affine No meaningful depth is preserved Can actually decompose the perspective projection into perspective projection (in 3D) = perspective transform (linear, in homo. coord.) + perspective division + orthographic proj. [Here, depth is still not preserved!!!] Chap 3, View Pipeline (CG-U) 24 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Chap 3, View Pipeline (CG-U) 25 CGGM Lab., CS Dept., NCTU Jung Hong Chuang Simple perspective projection (w/o view volume) -3 Perspective transform M : in homo. coord. Perspective division (de-homogeniation) / / y x d Mp d y x q d d yd y xd x p p p
What we are going to do? First derive the perspective transform matrix for a right view volume Show that it does the same projection as the original perspective projection It converts the right view volume to a normalied view volume It preserves a meaningful depth Extend the result to general perspective view volumes Chap 3, View Pipeline (CG-U) 26 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation - For a right view volume specified by Eyepoint: (,, ), view plane at =-n Planes: x=±, y=±, =-n, =-f (f>n) (symmetric, 45 o ) View window (-n, -n,- n), (n, n, -n) Assuming near plane distance n = view plane distance d Consider the nonsingular matrix N ' n n (-n,-n,-n) (n,n,-n) α, β unspecified (but nonero), used to transfer the near and far clipping planes to =- and = Chap 3, View Pipeline (CG-U) 27 CGGM Lab., CS Dept., NCTU Jung Hong Chuang =-n =-f
Perspective normaliation transformation -2 Apply N to point p=[x y ] T, we obtain p =[x y w ] T : x' nx, y' ny, ', After dividing by w, we have nx x ny y" " " Consider only (x, y ), w' this is the same as the simple perspective projection!! (Note that n=d) And has a meaningful depth!!!! Chap 3, View Pipeline (CG-U) 28 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -3 Chap 3, View Pipeline (CG-U) 29 CGGM Lab., CS Dept., NCTU Jung Hong Chuang Orthographic projection of distorted objects = Perspective projection of original objects! If we apply an orthographic projection along - axis to N, we obtain a simple perspectiveprojection matrix. ' n n n n N M orth view plane at =-d Don t care so is value!!!,,
Perspective normaliation transformation -4 Apply the above projection to p, we have p' M orth N' p nx ny x y p p nx ny This is exactly the result of a simple perspective projection for view plane at =-n So, Perspective projection = perspective transformation N + orthographic projection M orth Chap 3, View Pipeline (CG-U) 3 CGGM Lab.,CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -5 N is nonsingular and does the following x= ± is transformed to planes x = ±n (by putting x= ± in x =-nx/) y= ± is transformed to planes y = ±n (by putting y= ± in y =-ny/) =-n and =-f are transformed by N to the planes that are perpendicular to -axis, and and will be chosen such that ( n) " ( n) ( f ) " ( f ) Chap 3, View Pipeline (CG-U) 3 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Chap 3, View Pipeline (CG-U) 32 CGGM Lab., CS Dept., NCTU Jung Hong Chuang Perspective normaliation transformation -6 If we select the transformed clipping planes become, respectively, " ) ( ) ( " " ) ( ) ( " f f n n n f fn n f n f 2 This choice Preserves the depth order Normalies the -values within near and far planes to [-,]
Perspective normaliation transformation -7 By concatenating S(,,) to N', we have n n N S, N', n n With N, the view volume will be convertedto the canonical volume and a point p [ x, y,,] will be transformed to p' x" Np [ x, so the projectedpoint and depth are x, y,, ], y" y, " view Chap 3, View Pipeline (CG-U) 33 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang
Perspective normaliation transformation -8 - + ( x, y, ) ( nx, ny, ) Chap 3, View Pipeline (CG-U) 34 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang
Perspective normaliation transformation -9 Chap 3, View Pipeline (CG-U) 35 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang ),, ( ny nx ),, ( y x,), ( n n S,), ( n n S + +
Perspective normaliation transformation - The mapping " ( ) is nonlinear but preserves the ordering of depths, i.e., if > 2 in the original view volume, then < 2 : Since the original " ( Note that : In eye coord.: In NDC :, if ) and view volume and 2 is in front of "is in front of are depthsof Chap 3, View Pipeline (CG-U) 36 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang 2 " 2 2 2, two points 2 " within
Perspective normaliation transformation - Eye coordinate system: right-handed system Viewing direction: - Normalied device coord.: left-handed system Viewing direction: + See OpenGL projection matrix at http://www.songho.ca/opengl/gl_projectionmatrix.html Chap 3, View Pipeline (CG-U) 37 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -2 - = -f 2 = -n +x 2 + = +x = - + - Z > Z 2 Z < Z 2
Perspective normaliation transformation -3 Hidden surface removal works if we first apply the normaliation transformation However, the formula " ( ) implies that the distances are distorted by the normaliation which can cause numerical problems especially if the near distance is small Chap 3, View Pipeline (CG-U) 39 CGGM Lab.,CSIE Dept.,NCTU Jung Hong Chuang
Perspective normaliation transformation -4 Chap 3, View Pipeline (CG-U) 4 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -5 Properties of perspective transformation N Preserves lines and flatness. Preserves in-between-ness If a point inside an object, the transformed point will be inside the transformed object. Preserves depth order with its pseudo-depth. Warps objects such that the orthographic projection of the warped object = perspective projection of the original one. Warps the view volume to the canonical view volume Chap 3, View Pipeline (CG-U) 4 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -6 N transforms the right view volume to the canonical view volume (after perspective division), and an orthographic projection in the transformed volume yields the same image as does the perspective projection (Consider only x, y-value). N is called perspective transformation matrix. - + Chap 3, View Pipeline (CG-U) 42 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -7 For an asymmetric, not right view volume (whose face planes are not x=±, y=±), we need to do a shear transformation H and a scaling S before applying N. Chap 3, View Pipeline (CG-U) 43 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -8 The shear transformation H shears the point (( l r)/ 2, ( b t) / 2, n) to (,, n) by l r x' x 2, y' n that is, H (cot,cot) y b t 2 n l r H 2n b t, 2n Since <, (l+r)/(2n) must be < when (l+r)< to make a move to the right. (l+r)/(2n) must be > when (l+r)> to make a left move. Chap 3, View Pipeline (CG-U) 44 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -9 Review of shear transformation x' y' ' x y y cot shear the point to (,, n (( l r)/ 2, ( b t) / 2, n) ) Since for -n, ( l r) / 2 cot cot ( l r) / n 2 l r 2n Chap 3, View Pipeline (CG-U) 45 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -2,n Sheared by ( l r) / 2 n l r, n 2 n Chap 3, View Pipeline (CG-U) 46 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -2 The scaling transformation S Scale the sheared view volume defined by x ( r l) 2( n), y ( t b) 2( n), f, n to a symmetric-right view volume ( x, y ) without changing the near and far planes. Scaling matrix (derived using 4 corners of the window on the near plane) S 2n r l, 2n t b, Positive scaling factors!! Chap 3, View Pipeline (CG-U) 47 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -22 Scaled by x min x 2 max min n, n Scale factor: divide by (r-l)/2, then multiply by n n Scaled by x min x 2 max min r l, n 2 Chap 3, View Pipeline (CG-U) 48 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Perspective normaliation transformation -23 Projection matrix is P NSH Precisely the projection matrix that OpenGL creates when glufrustum() is executed. P NSH Chap 3, View Pipeline (CG-U) 49 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Chap 3, View Pipeline (CG-U) 5 CGGM Lab., CS Dept., NCTU Jung Hong Chuang Perspective normaliation transformation -24 2 ) ( 2 2 n f fn n f f b n t b t b t n l r l r l r n NSH P
Another derivation of N - from pseudo-depth Simple perspective transformation xn yn transforms ( x, y, ) to (,, n) A pseudo-depth is desired No depth!! Has a meaningful depth function with the same denominator as x and y, and hence apply the same transformation matrix. so try transforms ( x, y, ) to xn (, yn, ) for some and Chap 3, View Pipeline (CG-U) 5 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Another derivation of N -2 from pseudo-depth For the transformation transforms ( x, y, ) to xn (, yn We choose and such that the pseudo-depth varies between - and. Depth=- for =-n, Depth= for =-f, ) for some and ( f n) f n, f 2 fn n Chap 3, View Pipeline (CG-U) 52 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
OpenGL Canonical view volume Canonical view volume A cube whose center is at the origin of the window coordinate and whose faces are given by 6 planes: x=, -, y=, -, =, -. Canonical view volume is the default in OpenGL (result of glfrustum() and glortho()), or obtained by glmatrixmode(gl_projection); glloadidentity(); glortho(-.,., -.,., -.,.); =-. is the near plane =. is the far plane Chap 3, View Pipeline (CG-U) 53 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
OpenGL Perspective projection - For general symmetric view volume gluperspective(fovy, aspect, near, far) Produces a projection matrix that converts the symmetric view volume to the symmetric-right one by a scaling transformation S, and to a canonical view volume by a N. Produces P = NS Chap 3, View Pipeline (CG-U) 54 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
OpenGL Perspective projection -2 view plane aspect = w/h Chap 3, View Pipeline (CG-U) 55 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
OpenGL Perspective projection -3 For asymmetric volume glfrustum(l, r, b, t, n, f) Produces a projection matrix that converts the asymmetric view volume to the symmetric-right one by a shear transformation H followed by a scaling transformation S, and to a canonical view volume by a N Produces P = NSH Chap 3, View Pipeline (CG-U) 56 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Orthogonal projections - What is the projection matrix? Move the center of the specified view volume to the center of the canonical view volume by T( ( xmax xmin ) / 2, ( ymax ymin ) / 2, ( max min Scale the sides by S( 2/( xmax xmin ),2/( ymax ymin ),2/( max min )) ) / 2) Chap 3, View Pipeline (CG-U) 57 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Orthogonal projections -2 Projection matrix P ST x max 2 x min y max 2 y min 2 far near xmax xmin x max xmin ymax ymin y max ymin far near far near Chap 3, View Pipeline (CG-U) 58 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
OpenGL Orthogonal projections - OpenGL provides only orthographic projection glortho(xmin, xmax, ymin, ymax, near, far) Parameters are identical to those of glfrustum() max min max Z max = -far min = -near min Chap 3, View Pipeline (CG-U) 59 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
OpenGL Orthogonal projections -2 Converting general view volume defined by glortho(xmin, xmax, ymin, ymax, near, far); Produces a projection matrix that transforms the view volume to the canonical view volume. Vertices inside (outside) the original view volume are transformed by the projection matrix to the vertices inside (outside) the canonical view volume.,-) (-,-, Chap 3, View Pipeline (CG-U) 6 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
OpenGL Projection normaliation OpenGL Clip coordinates (homogeneous): has depth Normalied device coord. (3D): has depth Window coordinates (2D): has no depth Projection in OpenGL Part : results in a projection matrix. Followed a perspective division to convert vertices to normalied device coordinates. Part 2: do nothing, neglect. Converts to window coordinates. Chap 3, View Pipeline (CG-U) 6 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Projection normaliation Oblique projection Not available in OpenGL. Characteried by the angle between the projector and the view plane. Assuming that Near and far planes parallel to the view plane Other faces parallel to the projector s direction. Chap 3, View Pipeline (CG-U) 62 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Chap 3, View Pipeline (CG-U) 63 CGGM Lab., CS Dept., NCTU Jung Hong Chuang Oblique projection Projection matrix - Consider the top and side view cot tan cot tan : p p p p p y y y y x x x x P Shearing
Oblique projection Projection matrix -2 tan( ) x x p p tan x cot( ) tan( ) x cot( ) x p x cot x x p Shearing Note that : cot( ) tan( ) cot( ) tan Chap 3, View Pipeline (CG-U) 64 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Chap 3, View Pipeline (CG-U) 65 CGGM Lab., CS Dept., NCTU Jung Hong Chuang Oblique projection Projection matrix -3 For view volume with unit length and origin as center P can be broken into two matrices M orth is orthographic projection, H() is a shear matrix cot cot ), ( cot cot H M P orth
Oblique projection Projection matrix -4 M orth Chap 3, View Pipeline (CG-U) 66 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Oblique projection Projection matrix -5 For general oblique projection A shear of the object by H(θ,Φ) A translation and a scaling (convert the sheared view volume to the canonical view volume) An orthographic projection Projection matrix P M orth S T H(, ) Chap 3, View Pipeline (CG-U) 67 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
View volume clipping - Clip against canonical view volume? It is parameter free, uses only - and. Planes are aligned with coordinate axes. Why in homogeneous space? Clipping in HS isn t completely necessary, but it makes the clipping clean, fast, and simple, at almost no cost. Done after perspective division Signs of x (or y, ) and w are lost. Can tell only if x and w have the same or opposite signs. Chap 3, View Pipeline (CG-U) 68 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
View volume clipping -2 Situations that necessitate clipping in HS involve Particular transformation of objects or the construction of rational surfaces such that the point has a negative w, even the point is in front of the eye. Clipping in 3D is correct only when w> In HS: two clip regions A (w>) & B ( w<) Negate points with w< and clip all against A. Chap 3, View Pipeline (CG-U) 69 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
Chap 3, View Pipeline (CG-U) 7 CGGM Lab., CS Dept., NCTU Jung Hong Chuang View volume clipping -2 Uses Cyrus-Beck clipper (a topic in Chap. 4) ) (, ) ( ) (, ) ( ) (, ) ( view volume : the canonical or outside of inside is, where ),,,, ( point A a To test if w w w w y w w y y w w y x w w x x w w x w w y x a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
Viewing Pipeline Summary View projection View transform View-Volume Clipping in homogeneous space Window-viewport mapping Chap 3, View Pipeline (CG-U) 7 CGGM Lab., CS Dept., NCTU Jung Hong Chuang
View Projection -3 Shear scaling Mapping view volume to normalied view volume. Easy view-volume clipping and projection, and Standard sied window. Comp. Graphics (U), Chap 3 View Pipeline 72 CGGM Lab., CS Dept., NCTU Jung Hong Chuang