<<

Planar Geometric Projections Planar ⩴ project onto a plane (vs. planetarium, e.g.)

Geometric ⩴ projectors are straight lines EECS 487: Interactive (vs. curved lines in , e.g.) from n to n-1 dimensions

Lecture 13: Euclidean geometry describes shapes “as they are” • Planar Geometric Projections • properties of objects that are unchanged • by rigid motions: lengths, angles, parallel lines • projection describes objects “as they appear” • Projections in OpenGL • lengths, angles, parallel lines become “distorted” when we look at objects

Projection System Taxonomy of Common elements: Planar Geometric Projections • Center of Projection (COP) Planar Geometric Projections (for perspective projection)/ Direction of Projection (DOP) (for , ≈COP at ∞) Perspective Parallel • Projection/view/picture/image plane (PP) Projection Projection • Projectors/sightlines One-point Oblique Orthographic Parallel Two-point Cavalier Axonometric Multiview Three-point Cabinet Isometric top, bottom, General front, back, Dimetric left, right Parallel Perspective Trimetric Lozano-Perez01 Perspective Multiview Axonometric Orthographic Orthographic Axonometric: • is not parallel to any coordinate plane • projection direction perpendicular to projection plane

Isometric: • preserves lengths 3 • projection plane parallel to one along principal axes coordinate plane (project onto • principal axes make the same angle with plane by dropping coordinate • preserves ratios, each other (120º) perpendicular to plane) but not angles ( not visible) • projection direction perpendicular • parallel lines remain parallel

to projection plane is considered 120º 120º • good for exact measurements an affine transform (CAD, architecture) 120º James07

Parallel Orthographic Projections Orthographic Projection

View volume defined by left, right, bottom, top, near, and far planes: ⎡ 1 0 0 ⎤ ⎢ ⎥ P = ⎢ 0 1 0 ⎥ ⎢ 0 0 0 ⎥ ⎣ ⎦

Are we done? Yes, but we’ve lost depth (z) information, can’t do: Map it to cvv: • hidden surface removal • lighting, etc. Need to preserve z dimension! map view volume to canonical view volume

Akenine-Möller & Haines 02 Shirley02 Orthographic Projection Setup Orthographic Projection From an arbitrary axis-aligned Simple case: view volume axis-aligned with world bounding box to canonical view volume coordinate system • translate and scale: • the view volume is in negative z, n > f

More generally, the view RTR3 volume is not axis-aligned What would the T and S matrices be? ⎡ 2 l + r ⎤ ⎡ 2 ⎤ ⎡ l + r ⎤ with world CS (it will always ⎢ 0 0 − ⎥ ⎢ 0 0 0 ⎥ 1 0 0 − r − l r − l r − l ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 2 ⎥ be axis-aligned with eye CS): ⎢ 2 b + t ⎥ ⎢ 2 ⎥ 0 0 − 0 0 0 ⎢ b + t ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 0 1 0 − ⎥ Po = ST = t − b t − b S = t − b T = 2 ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 2 n + f ⎥ ⎢ 2 ⎥ n + f 0 0 − 0 0 0 ⎢ 0 0 1 − ⎥ ⎢ n − f n − f ⎥ ⎢ n − f ⎥ ⎢ 2 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣⎢ 0 0 0 1 ⎦⎥ ⎣⎢ 0 0 0 1 ⎦⎥ ⎣ 0 0 0 1 ⎦ Shirley02

Orthographic Projection and Perspective Projection Viewing Transform Objects appear smaller as distance from From an arbitrary viewing center of projection (eye of observer) increases volume to canonical view volume (perspective foreshortening) ⇒ looks more realistic • translate eye to origin (human eyes naturally see things in perspective) • transform to eye coordinate system • apply orthographic projection Preserves: • lines (collinearity) M world −>canonical = • incidence ⎡ 2 l + r ⎤ (“lies on”, intersects) ⎢ 0 0 − ⎥ r − l r − l ⎡ ⎤ ⎡ ⎤ • cross ratio ⎢ ⎥ ux uy uz 0 1 0 0 −ex ⎢ 2 b + t ⎥ ⎢ ⎥ ⎢ ⎥ 0 0 v v v 0 0 1 0 −e ⎢ − ⎥ ⎢ x y z ⎥ ⎢ y ⎥ Does not always preserve parallel lines: t − b t − b ⎢ ⎥ ⎢ ⎥ w w w 0 ⎢ 0 0 1 −e ⎥ ⎢ 2 n + f ⎥ ⎢ x y z ⎥ ⎢ z ⎥ • lines parallel to projection plane remain parallel 0 0 − ⎢ ⎥ ⎢ ⎥ ⎢ n − f n − f ⎥ ⎣ 0 0 0 1 ⎦ ⎣ 0 0 0 1 ⎦ • ⎢ ⎥ lines not parallel to projection plane converge to a single ⎣⎢ 0 0 0 1 ⎦⎥ point on the horizon called the (vp) M M eye→canonical world→eye Shirley02 The Cross Ratio Classes of Perspective Projection For the 4 sets of 4 collinear points in the figure, the cross-ratio for one-point: projection plane parallel to one corresponding points has the same value (can permute the point coordinate plane (to two coordinate axes, ordering) one coordinate axis cuts projection plane)

p4 p2 − p1 p4 − p3 two-point: projection plane parallel to one coordinate axis (two coordinate axes cut p p3 p4 − p1 p3 − p2 1 p 2 projection plane) ⎡ x ⎤ ⎢ i ⎥ ⎢ yi ⎥ pi = ⎢ z ⎥ ⎢ i ⎥ ⎢ 1 ⎥ ⎣ ⎦

p3 − p1 p4 − p2 p1 − p3 p4 − p2

p3 − p2 p4 − p1 p1 − p2 p4 − p3

deMenthon Seitz08 James07

Classes of Perspective Projection Projective Geometry in 2D Consider lines and points in P three-point: projection plane We extend to 3D to simplify dealing with infinity not parallel to any coordinate • origin o out of P, at a distance = 1 from P axis (three coordinate axes cut projection plane) To each point m in P we can associate a single ray p = (x1, x2, x3) To each line l in P we can associate a single plane (A, B, C)

• the equation of line L in projective geometry is Ax1 + Bx2 + Cx3 = 0

x3 Duell (A, B, C ) = L p = (x1, x2, x3) P m l

o x1 Hulsey James07 x2 deMenthon Homogeneous Coordinates Perspective Divide How do we “land” back from the projective world to The ray p = (x1, x2, x3) and (λx1, λx2, λx3) are the same and are mapped to the same point m in P the 2D Cartesian world of the plane? • p is the coordinate vector of m, • for point, consider the intersection of ray p = (λx1, λx2, λx3) (x1, x2, x3) its homogeneous coordinates with the plane x3 = 1 λ = 1/x3, m = (x1 / x3, x2 / x3, 1) The planes (A, B, C) and (λA, λB, λC) are the same • for line, intersection of plane Ax + Bx + Cx = 0 with the l P 1 2 3 and are mapped to the same line in plane x = 1 is line l = Ax + Bx + C = 0 • L is the coordinate vector of l, 3 1 2

(A, B, C) its homogeneous coordinates x3 x3 L = (A, B, C) p = (x1, x2, x3) Called “perspective divide” L = (A, B, C) p = (x1, x2, x3) Point p’ is on line L if L•p’ = 0 p’ P P m For the mathematically m l inclined, or studying l computer vision: what’s (A, B, C) the geometric interpretation (A, B, C ) o o of x3 = 0? x1 x1 x2 deMenthon x2 deMenthon

Projective Geometry 3D Projective Geometry

Two lines always meet at a single point, and two points These concepts generalize naturally to 3D always lie on a single line Projective geometry does Homogeneous coordinates not differentiate between • projective 3D points have four coordinates: p = (x, y, z, w) (0, 0, 1) = (0, 0, 2) = … parallel and non-parallel lines (7, 1, 1) = (14, 2, 2) = … Points and lines are dual of (4, 5, 1) = (8, 10, 2) = … Projective transformations each other • represented by 4×4 matrices To return from homogeneous coordinates to Cartesian w = 1 coordinates, divide by x3 (w)

w = 2 deMenthon, Durand08 Seitz08 Vanishing Points Perspective Projection What happens to two parallel lines that are not parallel to the projection plane? Given the coordinates of the orange point The parametric equation for find the coordinates of the green point y a line is: ⎡ ⎤ ⎡ ⎤ px vx y' y ⎢ ⎥ ⎢ ⎥ tanθ = = ⎢ py ⎥ ⎢ vy ⎥ l = p + tv = + t d z y ⎢ p ⎥ ⎢ v ⎥ ⎢ z ⎥ ⎢ z ⎥ y' yd z y’ = z θ ⎣⎢ 1 ⎦⎥ ⎣⎢ 0 ⎦⎥ e g Is perspective projection simply: d view plane After perspective transform: (x, y, z, 1) (xd/z, yd/z, d, 1), ⎡ p + tv ⎤ At the limit, with t∞, we get x x d T ⎡ ' ⎤ ⎡ ⎤ ⎢ ⎥ then map to screen by throwing z p px + tvx p + tv a point! [(vx/vz)d, (vy/vz)d, 1] ⎢ x ⎥ ⎢ ⎥ ⎢ z z ⎥ ' p + tv after ⎢ ⎥ away the z-coordinate: (xd/z, yd/z, 1)? ⎢ p y ⎥ = ⎢ y y ⎥ ⎯p⎯ersp⎯ectiv⎯e→ py + tvy divide ⎢ d ⎥ ⎢ ⎥ ⎢ (p + tv ) / d ⎥ p + tv ⎣ w ⎦ ⎣⎢ z z ⎦⎥ ⎢ z z ⎥ Each set of parallel lines ⎢ 1 ⎥ ! ⎣ ⎦ intersect at a vanishing point

Perspective Projection Matrix Projection System Setup The coordinate system Projecting (x, y, z, 1) (xd/z, yd/z, d, 1) and throwing away d does not preserve the depth information The eye (e) (x’, y’, d, 1) • acts as the focal point and COP (x, y, z, 1) Instead want P such that: • placed at the origin ⎡ d ⎤ • looking down (g) along the e g ⎢ x ⎥ ⎡ x ⎤ z negative z-axis (axis of projection) ⎢ ⎥ ⎢ ⎥ perspective y ⎢ d ⎥ divide P⎢ ⎥ → y ⎢ z ⎥ ⎢ z ⎥ The screen ⎢ ⎥ preserve the relative • lies in the projection plane What does it mean for w=1? ⎢ 1 ⎥ z' depth information of ⎣ ⎦ ⎢ ⎥ • ⟘ to the z-axis,to the x-y plane What does it mean for w>1? ⎢ 1 ⎥ each point ⎣ ⎦ • located at distance d from the eye What is the homogeneous Just like orthographic projection, we need to map • d is a.k.a. the focal length coordinate (HC) when projecting from 3D to 2D? the view volume to a CVV instead of a 2D plane Perspective Projection View Frustum From Frustum to CVV View volume (frustum: truncated pyramid): • defined by (left, right, top, bottom, near, far) clipping planes • near (n) and far (f ) distances along –z-axis, both negative numbers, n > f View volume

• nothing nearer than n will be drawn avoid numerical problems during rendering, such as divide by 0 perspective orthographic • nothing further than f will be drawn projection, including projection avoid low depth precision for distant objects perspective divide To preserve relative depth information, we must map the frustum to a CVV instead of a 2D plane

RTR3

Perspective Projection Matrix ⎡ x ⎤ ⎡ x d z ⎤ Perspective Projection Matrix ⎢ ⎥ ⎢ ⎥ y yd z Want projection matrix P such that: P⎢ ⎥ → ⎢ ⎥ Second attempt: for a more generic matrix, ⎢ z ⎥ ⎢ z' ⎥ grab the depth info from the point itself: ⎢ 1 ⎥ ⎢ ⎥ What should P be? ⎣ ⎦ ⎣ 1 ⎦ • we’re projecting from 3D to 2D (not 4D to 3D), ⎡ d 0 0 0 ⎤⎡ x ⎤ ⎡ xd ⎤ ⎡ x d z ⎤ ⎢ ⎥ use the HC of the projected point to store its depth ⎢ ⎥⎢ y ⎥ ⎢ yd ⎥ 0 d 0 0 ⎢ ⎥ ⎢ ⎥ after ⎢ yd z ⎥ info (i.e., the “real” HC in 3D to 2D projection) Pp = ⎢ ⎥ = ⎯p⎯ersp⎯ectiv⎯e→ 0 0 d 0 z ⎢ zd ⎥ divide ⎢ ⎥ • first attempt: ⎢ ⎥⎢ ⎥ d ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 0 1 0 ⎦⎣ 1 ⎦ z 1 ⎡ d 0 0 0 ⎤⎡ x ⎤ ⎡ xd ⎤ ⎡ x d z ⎤ ! ⎣ ⎦ ⎣ ⎦ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥ 0 d 0 0 y yd after yd z Pp = ⎢ ⎥⎢ ⎥ = ⎢ ⎥ ⎯⎯⎯⎯→ ⎢ ⎥ Are we done? 0 0 d 0 perspective ⎢ ⎥⎢ z ⎥ ⎢ zd ⎥ divide ⎢ d ⎥ ⎢ ⎥ • the projected x-, y-, and HC are correct already, but after ⎢ 0 0 0 z ⎥⎢ 1 ⎥ ⎢ z ⎥ 1 ! ⎣ ⎦⎣ ⎦ ⎣ ⎦ ⎣ ⎦ perspective divide, all depths mapped to d! Any problem? • 3rd row of matrix must be tweaked to preserve relative depth info (z’) Perspective Projection Matrix Perspective Projection Matrix Frustum Rectangular box For the 3rd row of P: Let d = n ⎡ x ⎤ ⎡ x n z ⎤ ⎢ ⎥ ⎢ ⎥ • want a and b such that: y ⎢ yn z ⎥ Want:!P⎢ ⎥ → ! ⎡ x ⎤ ⎡ x ⎤ ⎡ x ⎤ ⎡ x n f ⎤ ⎢ z ⎥ ⎢ z' ⎥ ⎢ ⎥ The 1st and 2nd rows of P are correct ⎢ ⎥ ⎢ ⎥ ⎢ y ⎥ ⎢ ⎥ ⎢ ⎥ y y ⎢ ⎥ ⎢ yn f ⎥ rd ⎣ 1 ⎦ 1 P⎢ ⎥ → ⎢ ⎥!and!P → already, for the 3 row (third attempt): ! ⎣ ⎦ ⎢ n ⎥ ⎢ n ⎥ ⎢ f ⎥ ⎢ f ⎥ • the computation of z’ does not rely on x and y, ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 1 ⎦ ⎣ 1 ⎦ 1 ⎢ 1 ⎥ set the first two numbers of the row to 0 ! ⎣ ⎦ ⎣ ⎦ • we can use the remaining two numbers to • or, for z=n, a+b/z = n and for z=f, a+b/z = f compute z’, let them be unknowns a and b for now: for!z = n : !a + b n = n,!a = n − b n ⎡ ⎤ for!z = f : !a + b f = f , ⎡ n 0 0 0 ⎤⎡ x ⎤ ⎡ xn ⎤ x n z ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ ⎥ substituting!for!a:!(n − b n) + b f = f nf 0 n 0 0 y yn after yn z Pp = ⎢ ⎥⎢ ⎥ = ⎢ ⎥ ⎯⎯⎯⎯→ ⎢ ⎥ perspective b n − f = f − n nf ,!b = −nf ⎢ 0 0 a b ⎥⎢ z ⎥ ⎢ az + b ⎥ divide ⎢ a + b z ⎥ ( ) ( ) ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣⎢ 0 0 1 0 ⎦⎥ 1 z 1 substituting!for!b:!a = n − (−nf ) n,!a = n + f ! ⎣ ⎦ ⎣ ⎦ ⎣⎢ ⎦⎥ !

Perspective Divide Perspective Foreshortening Then divide by the homogenous coordinate What is the effect of perspective divide squeezing the frustum into a rectangular box on the shape of objects?

⎡ xn z ⎤ ⎡ n 0 0 0 ⎤⎡ x ⎤ ⎡ nx ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ yn z ⎢ 0 n 0 0 ⎥ y ny ⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ perspective = ⎯⎯div⎯ide ⎯→⎢ nf ⎥ ⎢ 0 0 n + f −nf ⎥⎢ z ⎥ ⎢ (n + f )z − nf ⎥ ⎢ n + f − ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥ ⎢ z ⎥ ⎣ 0 0 1 0 ⎦⎣ 1 ⎦ z ⎣ ⎦ ⎢ 1 ⎥ ⎣ ⎦

Note how n/z conveniently cancels the negative signs out After perspective divide, an object further away Shirley02 appears to be smaller than an equal-size object nearby Curless08 ⎡ nx z ⎤ From Frustum to CVV Losing Depth Precision ⎡ x ' ⎤ ⎢ ⎥ ny z ⎢ y' ⎥ ⎢ ⎥ Now reposition and scale the rectangular box Recall that after perspective divide we have: ⎢ ⎥ = ⎢ fn ⎥ ⎢ z' ⎥ ⎢ n + f − ⎥ ⎢ ⎥ ⎢ z ⎥ ⎣ 1 ⎦ ⎡ 2 r + l ⎤ ⎢ 1 ⎥ ⎢ 0 0 − ⎥ ⎣ ⎦ r − l r − l As a consequence of perspective foreshortening, ⎢ ⎥ ⎡ n 0 0 0 ⎤ ⎢ 2 t + b ⎥ z’ is not linearly related to z: 0 0 − ⎢ 0 n 0 0 ⎥ P = STP = P P = ⎢ t − b t − b ⎥ ⎢ ⎥ p o ⎢ ⎥ ⎢ 0 0 n + f −nf ⎥ ⎢ 2 n + f ⎥ 0 0 − ⎢ 0 0 1 0 ⎥ nf ⎢ n − f n − f ⎥ ⎣ ⎦ z' = n + f − ⎢ ⎥ z 0 0 0 1 ⎣⎢ ⎦⎥ nf Δz z2 ⎡ 2n l + r ⎤ Δz' ≈ ;!Δz ≈ Δz' ⎢ 0 0 ⎥ z2 fn Assume viewing transform has been ⎢ r − l l − r ⎥ ⎢ 2n b + t ⎥ max !Δz!is!when!z = f done, so after perspective divide 0 0 n → 0 = ⎢ t − b b − t ⎥ f (not shown) we’re only dealing with ⎢ ⎥ At!z = f ,!Δz = Δz',!as!n → 0, ⎢ n + f 2nf ⎥ n axis-aligned viewing volume 0 0 Redbook10 ⎢ n − f f − n ⎥ near!the!far!plane!(f ),!Δz → ∞!but!must!be!covered!by ⎢ ⎥ 0 0 1 0 ⎣⎢ ⎦⎥ !the!same!Δz'!as!smaller!Δz!that!are!closer!to!n See also http://www.songho.ca/opengl/gl_projectionmatrix.html

Losing Depth Precision Losing Depth Precision Δz1 Δz2

Δz’2, f

As a consequence of perspective foreshortening, far=100

z’ is not linearly related to z: as z gets closer to f, Δz’2, f the same amount of Δz’ must represent larger Δz Δz’1, n For example: let n = 10, f = 90,

Δz’1, n for z1 = 10, z’1 = 10 Δz1 = 1 for z2 = 11, z’2 = 18.182 Δz’1= 8.182 . . . RTR3 z 89, z’ 89.888 z 1 for k-1 = k-1 = Δ k-1 = Implication of the non-linear mapping: for zk = 90, z’k = 90 Δz’k-1= 0.112 • information on the far plane loses precision z-buffer punch through or z-fighting • distances closer to origin are exaggerated Effect is ameliorated if n set further from origin Akeley07 z-Buffer Quantization

z-values stored as non-negative integers Integers are represented in b (=16 or 32) bits, giving a range of B (= 2b) values {0, 1, 2, . . . , B-1} Floating point z’-values are discretized into integer bins: Δz’ = (f−n)/B, so for example for n = 10, f = 90, both z1 = 89, z’1 = 100−(900/89) = 89.888 and z2 = 90, z’2 = 100−(900/90) = 90 are both discretized to z’ = 90 Moral of the story: choose n as far away from origin as possible and f as near as possible (to reduce Δz’)