Virtual Cameras & Their Matrices J.Tumblin-Modified, highly edited SLIDES from: Ed Angel Professor Emeritus of Computer Science University of New Mexico 1
What is Projection? Any operation that reduces dimension (e.g., 3D to 2D) Orthographic Projection Perspective Projection
V U N Center of Projection (Camera Origin) Image Plane ( Splits the Universe )
Perspective Projection z = not allowed (what happens to points on plane z =?) Operation well-defined for all other points
The View Frustum
Vertex Stream WebGL: Vertex Position Pipeline gl.modelview gl.projection model + model view + view transformation transformation projection transformation HTML-5 Canvas divide: x/w, y/w, z/w 4D 3D The CVV clipping ViewPort transformation gl.viewport(llx, lly width,height) (in pixels) 6
Notes KEEP our four-dimensional homogeneous coordinates throughout all transforms by MODEL, VIEW, and PROJECTION matrix: - All are nonsingular - All default to identity matrices (CVV sets limits) Delay final perspective-divides until the end - Important for hidden-surface removal: we NEED depth information to draw pixels! - Efficient : FP division == expensive to compute E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 7
WebGL: Vertex Position Pipeline Wher do these matrices fit into the SceneGraph? MODEL (jointed objects) VIEW (camera-positioning) PROJECTION (lens-like) VIEWPORT (screen) group4 CVV t1 HTML-5 Canvas t group1 t2 group2 t7 group3... t3 t4 obj1 obj5 obj2 group3 8
WebGL: Vertex Position Pipeline RECALL: in scene graphs, Vertices & values move upwards, transform calls move downwards Project A: CVV == World drawing axes (group) CVV HTML-5 Canvas group4 t1 t group1 t2 t7 group3... t3 group2 t4 obj1 obj5 obj2 group3 9
WebGL: Vertex Position Pipeline RECALL: in scene graphs, Vertices & values move upwards, transform calls move downwards CVV HTML-5 Canvas Viewport Project A: CVV == World drawing axes (group) World CAM View Projection Project B: Viewport output HTML Canvas CVV output Viewport input Lens Axes CVV input Camera Axes Lens Input group4 t group1 t1 t2 group2 group3... t7 t3 t4 obj2 group3 World Coords Camera Axes 1 obj1 obj5
Simple Perspective Consider a simple point-perspective image with the COP at the origin, the near clipping plane at z = -1, and a 9 degree field of view determined by the planes x = z, y = z E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 11
Simple Perspective Consider a simple point-perspective image with the COP at the origin, the near clipping plane at z = -1, and a 9 degree field of view determined by the planes x = z, y = z E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 12
Orthographic Camera Simple Orthographic Projection Matrix: re-scale a rectangular volume in CAM coords to fit within the CVV gl.ortho(left,right,bottom,top,near,far) E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 13
Step 1: Orthogonal Matrix Two steps: - Translate the camera s frustum center to the origin T(-(left+right)/2, -(bottom+top)/2, (near+far)/2)) - Scale to have sides of length 2 (to match the CVV) S(2/(left-right),2/(top-bottom),2/(near-far)) P = ST = 2 right left 2 top bottom 2 near far right left right left top bottom top bottom far near far near 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 14
Clipping & Display: Put it into the CVV! Keep 3D clipping simple, fixed and fast Don t form different clipping volumes for each kind of frustum, lens or camera! Instead, map them all into the CVV become orthogonal projections to screen One camera one matrix One camera type One function E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 15
Simple Perspective Consider a simple point-perspective image with the COP at the origin, the near clipping plane at z = -1, and a 9 degree field of view determined by the planes x = z, y = z E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 16
(Naïve) Perspective Matrix Simple projection matrix in homogeneous coordinates M = 1 1 1 1 Trouble! matrix ignores near clipping plane, and CVV sets far plane by default to +1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 17
One Weird Trick to fix it (perfectionists hate it ) N = 1 1 α β 1 after perspective division, the point at (x, y, z, 1) becomes x = x/z y = y/z Z = -(az+b)/z Choose a and b carefully E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 18
Generalize to fix it: N = 1 1 α β 1 after perspective division, the point (x, y, z, 1) goes to x = x/z y = y/z Z = -(az+b)/z Could it span -1 to +1 (as x,y might)? could we fit it into the CVV? E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 19
Pseudo-Depth : Picking a and b If we pick a = b = near far far near 2near far near far the near plane is mapped to z = 1 the far plane is mapped to z =-1 and the sides are mapped to x = 1, y = 1 Hence the viewing frustum fills the CVV exactly! E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 2
Normalization Transformation distorted object projects correctly original clipping volume original object new clipping volume E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 21
Posing the Camera AWKWARD: Define position in WORLD coords 22
END E. Angel and D. Shriener: Interactive Computer Graphics 6E Addison-Wesley 212 23
Normalization and Hidden-Surface Removal Although our pseudo-depth may SEEM weirdly arbitrary, it ensures monotonic depth: if z 1 > z 2 in the original clipping volume, then inside the CVV we always have z 1 > z 2 Thus hidden surface removal still works fine based on CVV s z value However pseudo-depth DISTORTS distances. It compresses far-away depths, expands nearby ones; z = -(az+b) /z Tiny znear? Giant zfar? Expect coarse depth quantization! E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 24
Set z = Step 2: Final Projection (perspective) Equivalent to the homogeneous coordinate transformation M orth = 1 1 1 Hence, general orthogonal projection in 4D is P = M orth ST E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 25