230 likes | 511 Views
Projection Matrices. Mohan Sridharan Based on slides created by Edward Angel. Objectives. Derive the projection matrices used for standard OpenGL projections. Introduce oblique projections. Introduce projection normalization. Projection Normalization.
E N D
Projection Matrices Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics
Objectives • Derive the projection matrices used for standard OpenGL projections. • Introduce oblique projections. • Introduce projection normalization. CS4395: Computer Graphics
Projection Normalization • Convert all projections to orthogonal projections with the default view volume. • The same pipeline of operations for all types of projections • Clip against simple cube regardless of type of projection. • Simplifies clipping because sides of the object are aligned with coordinate axes. • Delay final projection until end: important for hidden-surface removal. CS4395: Computer Graphics
Projection Normalization • Work in 4D using homogeneous coordinates. • Convert all projections into orthogonal projections: • Distort objects such that the orthogonal projection of distorted objects is the same as desired projection of original objects. • Concatenation of normalization matrix (for distortion) and orthogonal projection matrix yields desired homogeneous coordinate matrix. CS4395: Computer Graphics
Pictorial Representation CS4395: Computer Graphics
Pipeline View Stay in 4D coordinates for both the modelview and projection transformations (nonsingular transformations). modelview transformation projection transformation perspective division 4D 3D nonsingular clipping projection 3D 2D against default cube CS4395: Computer Graphics
Orthogonal Normalization glOrtho(left,right,bottom,top,near,far) Normalization find transformation to convert specified clipping volume to default. CS4395: Computer Graphics
Orthogonal Matrix • Two steps: • Move center to origin: T(-(left + right)/2, -(bottom + top)/2, (near + far)/2)) • Scale to have sides of length 2: S(2/(right-left), 2/(top-bottom), 2/(near-far)) P = ST = CS4395: Computer Graphics
Final Projection • Set z =0 • Equivalent to the homogeneous coordinate transformation: • General orthogonal projection in 4D: Morth = P = MorthST CS4395: Computer Graphics
Oblique Projections • The OpenGL projection functions cannot produce general parallel projections such as: • However the cube it appears to have been sheared. • Oblique Projection = Shear + Orthogonal Projection! CS4395: Computer Graphics
General Shear side view top view CS4395: Computer Graphics
Shear Matrix • For x-y shear (z values unchanged): • Projection matrix: • General case: • See Section 5.8. H(q,f) = P = MorthH(q,f) P = MorthSTH(q,f) CS4395: Computer Graphics
Equivalency CS4395: Computer Graphics
Effect on Clipping • Projection matrix P = STH transforms the original clipping volume to the default clipping volume. object top view z = 1 DOP DOP x = -1 x = 1 far plane z = -1 clipping volume distorted object (projects correctly) near plane CS4395: Computer Graphics
Simple Perspective • Consider a simple perspective : COP at origin, the near clipping plane at z = -1, and a 90o field of view determined by planes: x =z, y = z. CS4395: Computer Graphics
Perspective Matrices • Simple projection matrix in homogeneous coordinates: • This matrix is independent of the far clipping plane. M = CS4395: Computer Graphics
Generalization (Section 5.9) • Perspective normalization matrix: • After perspective division, the point (x, y, z, 1) goes to: • Orthogonal projection to the desired point regardless of • and . N = CS4395: Computer Graphics
Picking a and b • If we pick: • The near plane is mapped toz = -1 • The far plane is mapped toz =1 • The sides are mapped tox = 1, y = 1 • The new clipping volume is the default volume. a = b = CS4395: Computer Graphics
Normalization Transformation original clipping volume distorted object projects correctly original object new clipping volume CS4395: Computer Graphics
Normalization and Hidden-Surface Removal • The perspective projection matrices are chosen such that if z1 > z2 in the original clipping volume then for the transformed points: z1’ > z2’ • Thus hidden surface removal works if the normalization transformation is applied first. • However, the formula z’’ = -(a + b/z) implies that the distances are distorted by the normalization which can cause numerical problems if the near distance is small. CS4395: Computer Graphics
OpenGL Perspective • Function glFrustum allows for an un-symmetric viewing frustum (although gluPerspective does not). CS4395: Computer Graphics
OpenGL Perspective Matrix • The normalization in glFrustum requires an initial shear to form a right viewing pyramid, followed by a scaling to get the normalized perspective volume. Finally, the perspective matrix needs only a orthogonal transformation: • See Section 5.9.2. P = NSH N = previously defined perspective matrix shear and scale CS4395: Computer Graphics
Recap: Why do we do it this way? • Normalization allows for a single pipeline for both perspective and orthogonal viewing. • Stay in 4D homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading. • Simplifies clipping. CS4395: Computer Graphics