Computer Graphics Lecture 6 View Projection Taku Komura 1
Overview 1. View transformation 2. Rasterisation
Implementation of viewing. Transform into camera coorinates. Perform projection into view volume or screen coorinates. Clip geometr outsie the view volume. Remove hien surfaces (next week) 3
Transformations vmproj Mc w Mw l vl
View Transformation (from lecture 2) Computer Graphics Inf4/MSc We want to know the positions in the camera coorinate sstem vw Mw c vc Point in the camera coorinate Point in the worl coorinate Camera-to-worl transformation -1 v Mw c vw Mc w vw Lecture 4 2/1/9
View Projection We want to create a picture of the scene viewe from the camera Two sorts of projection Parallel projection Perspective projection 6
Mathematics of Viewing We nee to generate the transformation matrices for perspective an parallel projections. The shoul be 4x4 matrices to allow general concatenation. An there s still 3D clipping an more viewing stuff to look at. 7
Parallel projections (Orthographic projection) Specifie b a irection of projection, rather than a point. Objects of same sie appear at the same sie after the projection 8
Parallel projection. 1 1 M orth Orthographic Projection onto a plane at. x p x, p,. 9 1 1 1 1 1 1 x x
Perspective Projection Specifie b a center of projection an the focal istance (istance from the ee to the projection plane) Objects far awa appear smaller, closer objects appear bigger 1
Projection Matrix Here we will follow the projection transform metho use in OpenGL The camera facing the irection
Perspective projection simplest case. Centre of projection at the origin, Projection plane at -. : focal istance Projection Plane. P(x,,) x P p (x p, p,-) 12
Perspective projection simplest case. P(x,,) x x p x x p p ; triangles : From similar x P(x,,) P p (x p, p,-) P(x,,) p x x x p p / ; /
Perspective projection. [ ] [ ] T x 1. x 1 x T p p. T The transformation can be represente as a M per 1 1 1-1/ 4x4 matrix : 14
Perspective projection. [ ] T p x P M P W Z Y X P 1 1 projecte point Represent the general 15 [ ] [ ] T T per p x W Z Y X P M P / 1-1/ 1 1
Perspective projection. P [ x ] p / Dropping W to come back to 3D: T Trouble with this formulation : Centre of projection fixe at the origin. X W, Y W, Z W x /, /, 16
Alternative formulation. P(x,,) x x p P(x,,) p 17 Projection plane at Centre of projection at 1 ) / ( ; 1 ) / ( Multipl b ; triangles : From similar + + + + + + x x x x x p p p p
Alternative formulation. x x p P(x,,) p P(x,,) Projection plane at, Centre of projection at Now we can allow M per 1 1-1/ 1 18
Problem After projection, the epth information is lost We nee to preserve the epth information for hien surface remove uring rasteriation 19
3D View Volume Computer Graphics Inf4/MSc The volume in which the visible objects exist For orthographic projection, view volume is a box. For perspective projection, view volume is a frustum. The surfaces outsie the view volume must be clippe
Canonical View Volume We can transform the frustum view volume into a normalie canonical view volume using the iea of perspective transformation Much easier to clip surfaces an calculate hien surfaces
Transforming the View Frustum Let us efine parameters (l,r,b,t,n,f) that etermines the shape of the frustum The view frustum starts at -n an ens at -f, with <n<f The rectangle at -n has the minimum corner at (l,b,-n) an the maximum corner at (r,t,-n) 22
Transforming View Frustum into a Canonical view-volume The perspective canonical view-volume can be transforme to the parallel canonical view-volume with the following matrix: < < 23 matrix: + + + < < 1 2 2 2 ) ](, [ n f fn n f n f b t b t b t n l r l r l r n P then f n f n If p
Final step. Divie b W to get the 3-D coorinates Don t flatten ue to hien surface calculations. 3D Clipping The Canonical view volume is efine b: -1 x 1, -1 1, -1 1 Simpl nee to check the (x,,) coorinates an see if the are within the canonical view volume 24 24
Example + + + < < 1 2 2 2 ) ](, [ n f fn n f f b n t b t b t n l r l r l r n P then f n f n If p 1 How oes ABC look like after the projection?
Overview 1. View transformation 2. Rasterisation
Rasteriation Now, all the vertices are in the screen coorinates Nee to ecie how to colour the pixels accoring to the geoemetr of the polgons, triangles We have one this for lines alrea Let s o it for polgons 27
How shoul we o it? Easier to just hanle triangles like OpenGL Polgons without intersections Divie into triangles first 28
Polgon ecomposition into triangles. Now that we have an insie test, we can convert polgons to triangles. Triangles simple, convex an planar. P P7 P6 Simple for convex polgons. P5 P4 Concave more ifficult. P1 P2 P3
Polgon ecomposition Test all vertices to check the are outsie of ABC. Test one ege at a time to reject vertices earl B D C Vertex D fails test. A
Polgon ecomposition If all vertices outsie store triangle, remove vertex an procee with next leftmost vertex. If a vertex is insie, form new triangle with leftmost insie vertex an point A, procee as before. B D Test ABD in same manner as before, C A
Filling in Triangles Scan line algorithm Filling in the triangle b rawing horiontal lines from top to bottom Barcentric coorinates Checking whether a pixel is insie / outsie the triangle
Triangle Rasteriation Consier a 2D triangle with vertices p, p1, p2. Let p be an point in the plane. We can alwas fin a, b, c such that p p1 (α,β,γ) αp+βp1 +γp2 p2
barcentric coorinates We will have if an onl if p is insie the triangle. We call the barcentric coorinates of p. p p1 (α,β,γ) αp+βp1 +γp2 p2
Computing the baricentric coorinates of the interior pixels The triangle is compose of 3 points p (x,), p1 (x1, 1), p2(x2,2) (α,β,γ) : barcentric coorinates Onl if <α,β,γ<1, (x,) is insie the triangle Depth can be compute b αz + βz1 +γz2 Can o the same thing for color, normals, textures 35
Bouning box of the triangle First, ientif a rectangular region on the canvas that contains all of the pixels in the triangle (excluing those that lie outsie the canvas). Calculate a tight bouning box for a triangle: simpl calculate pixel coorinates for each vertex, an fin the minimum/maximum for each axis 36
Scanning insie the triangle Once we've ientifie the bouning box, we loop over each pixel in the box. Next we convert these into barcentric coorinates for the triangle being rawn. Onl if the barcentric coorinates are within the range of [,1], we plot it 37
Interpolation b Barcentric Coorinates The great thing of barcentric coorinates is that we can use it to interpolate attributes (colour, epth, normal vectors, texture coorinates) at the triangle vertices c1 c2 (α,β,γ) αc1+βc2 +γc3 c3
Exercise
Reaing for View Transformation Fole et al. Chapter 6 all of it, Particularl section 6.5 Introuctor text, Chapter 6 all of it, Particularl section 6.6 Akenine-Moller, Real-time Renering Chapter 3.5 Baricentric coorinates www.cs.caltech.eu/courses/cs171/barcentric.pf 4