11.07.2015 Views

and y

and y

and y

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Midterm ReviewWen-Chieh (Steve) LinDepartment of Computer Science


Administration•Assignment 1 due on 10/31 11:59 PM•Midterm exam on 11/6 (Monday)–Lecture slides–Chapter 3 excluding 3.6 & 3.8–Chapter 6, 7, 8–Chapter 11 excluding 11.3 & 11.4–Chapter 12.1-12.2–Angel, Chapter 6.1-6.5, Chapter 7.3-7.5DCP4516 Introduction to Computer Graphics 2


Topics we have learned so far•Graphics pipeline•Raster algorithms•Intensities <strong>and</strong> colors•Transformation•Viewing <strong>and</strong> projection•Shading•Texture mapping•ClippingMay not be reviewed todayDCP4516 Introduction to Computer Graphics 3


Graphics Pipeline•OpenGL pipelinePrimitives+ materialpropertiesRotateTranslateScaleIs itvisible?3D to 2DConvert topixelsDisplayDCP4516 Introduction to Computer Graphics 4


Rasterization (Scan Conversion)•Final step in pipeline•From screen coordinates (float) to pixels (int)•Writing pixels into frame bufferDCP4516 Introduction to Computer Graphics 5


Raster Algorithms•2D graphics primitives–Line drawing–Circle drawing•Area filling–Polygons•AntialiasingDCP4516 Introduction to Computer Graphics 6


Line-Drawing Algorithms•Start with line segment in windowcoordinates with integer values for endpointsy = mx + hym xDCP4516 Introduction to Computer Graphics 7


“Good”Discrete Lines•No gaps in adjacent pixels•Pixels close to ideal line•Consistent choices; same pixels in samesituations•Smooth looking•Even brightness in all orientations•Same line for P 0 P 1 as for P 1 P 0DCP4516 Introduction to Computer Graphics 8


Digital Differential Analyzer (DDA)Algorithm•For each x plot pixel at closest y•Along scan line Δx = 1For(x=x1; x


Using Symmetry•Use for 1 ≥m ≥0–For m > 1, swap roles of x <strong>and</strong> y–For each y, plot closest xDCP4516 Introduction to Computer Graphics 10


Bresenham’s Algorithm•DDA requires one floating point addition per step.•Bresenham’s algorithm eliminates all floating pointoperations•Consider only 1 ≥m ≥0–Other cases by symmetry•Assume pixel centers are at half integers•If we start at a pixel that has been written, there areonly two c<strong>and</strong>idates for the next pixelDCP4516 Introduction to Computer Graphics 11


Key to Bresenham Algorithm•“Reasonable assumptions”have reduced theproblem to making a binary choice at eachpixel:NE (next)(Previous)E (next)DCP4516 Introduction to Computer Graphics 12


C<strong>and</strong>idate Pixels•1 ≥m ≥0c<strong>and</strong>idatesLast pixelDCP4516 Introduction to Computer Graphics 13


Go NE if M is below the linexx 1y1NEQideal lineypreviousMmidpoint( x 1 , y E12)DCP4516 Introduction to Computer Graphics 14


Go E if M is above the lineNE( x 1,y 1)Mmidpoint1( x 1 , y 2)ideal line( x,y)previousEQ( x 1 , y)DCP4516 Introduction to Computer Graphics 15


Decision Variable d•Define a logical decision variable d•linear in form•incrementally updated (with addition)•tells us whether to go E or NEDCP4516 Introduction to Computer Graphics 16


Recall that for 1 ≥m ≥0 <strong>and</strong> x 1 > x 0•f(x,y) = (y 0 –y 1 )x + (x 1 –x 0 )y + x 0 y 1 –x 1 y 0 = 0Above line: consider f(x,+∞)f(x,y) > 0Below linef(x,y) < 0DCP4516 Introduction to Computer Graphics 17


Bresenham’s Algorithmy = y0For x=x0 to x1 dodraw(x,y)If f(x+1, y+0.5) < 0 theny = y + 1f(x+1,y+0.5) < 0DCP4516 Introduction to Computer Graphics 18f(x+1,y+0.5) > 0


Bresenham’s Algorithm (cont.)•Speed up by replacing function evaluationwith incremental update•f(x,y) = (y 0 –y 1 )x + (x 1 –x 0 )y + x 0 y 1 –x 1 y 0 = 0•f(x+1, y+1) = f(x, y) + (y 0 –y 1 ) + (x 1 –x 0 )•f(x+1, y) = f(x, y) + (y 0 –y 1 )DCP4516 Introduction to Computer Graphics 19


Bresenham’s Algorithm (cont.)y = y0d = f(x0+1, y0+0.5)For x=x0 to x1 dodraw(x,y)If d< 0 theny = y + 1elsed = d + (x1-x0) + (y0-y1)d = d + (y0-y1)DCP4516 Introduction to Computer Graphics 20f(x+1,y+0.5) < 0f(x+1,y+0.5) > 0


Bresenham’s Algorithm (cont.)y = y0d = f(x0+1, y0+0.5)For x=x0 to x1 dodraw(x,y)If d< 0 theny = y + 1elsed = d + (x1-x0) + (y0-y1)d = d + (y0-y1)Now, we want to remove thelast floating point operationin the code!DCP4516 Introduction to Computer Graphics 21


Bresenham’s Algorithm (cont.)•2*d = 2*f(x0+1, y0+0.5)•f(x 0 +1,y 0 +0.5) = (y 0 –y 1 ) (x 0 +1) + (x 1 –x 0 )(y 0 +0.5)+ x 0 y 1 –x 1 y 0 = 0•2f(x 0 +1,y+0.5) = 2(y 0 –y 1 ) (x 0 +1) + (x 1 –x 0 )(2y 0 +1)+ 2x 0 y 1 –2x 1 y 0 = 0DCP4516 Introduction to Computer Graphics 22


Code for Bresenham’s Algorithmy = y0d = 2*(y0–y1)(x0+1) + (x1–x0)(2*y0+1) + 2*(x0*y1–x1*y0)For x=x0 to x1 dodraw(x,y)If d< 0 theny = y + 1elsed = d + 2*(x1-x0) + 2*(y0-y1)d = d + 2*(y0-y1)DCP4516 Introduction to Computer Graphics 23


Other cases for line drawing•m=0; m=1 trivial cases•0 > m > -1 flip about x-axis•m > 1 flip about x = yDCP4516 Introduction to Computer Graphics 24


Circle-drawing Algorithmfor each x, yif | x 2 + y 2 –r 2 |


Midpoint Circle Algorithm•Can we utilize the similar idea inBresenham’s line-drawing algorithm ?–Check only the next c<strong>and</strong>idates–Use symmetry <strong>and</strong> simple decision rulesDCP4516 Introduction to Computer Graphics 26Symmetry of a Circle


Midpoint Circle Algorithm (cont.)f(x,y) = x 2 + y 2 - R 2f(x,y) > 0 => point outside circlef(x,y) < 0 => point inside circleP k = f circ (x k + 1, y k –½)DCP4516 Introduction to Computer Graphics 27


Midpoint Circle Algorithm (cont.)•Given the starting point (0,r), the computation ismore efficient.P 0 = 5/4 –rAt each x position,if(pk < 0)elsethe next point is (x k+1 , y k )p k+1 = p k + 2x k+1 + 1the next point is (x k+1 , y k -1)p k+1 = p k + 2x k+1 + 1 –2y k+1DCP4516 Introduction to Computer Graphics 28


2D Polygon Filling•Inside or Outside are not obvious–It’s not obvious when the polygon intersects itself.DCP4516 Introduction to Computer Graphics 29


Concave vs. Convex•We prefer dealing with “simpler”polygons.•Convex (easy to break into triangles)θ< 180 o θ > 180 oconvexconcaveDCP4516 Introduction to Computer Graphics 30


Filling Convex Polygons•Find top <strong>and</strong> bottom vertices•List edges along left <strong>and</strong> right sides•For each scan line from top to bottom–Find left <strong>and</strong> right endpoints of span, xl <strong>and</strong> xr–Fill pixels between xl <strong>and</strong> xr–Can use Bresenham’s algorithm to update xl <strong>and</strong>xrxlxrDCP4516 Introduction to Computer Graphics 31


Concave Polygons: Odd-Even Test•Approach 1: odd-even test•For each scan line–Find all scan line/polygon intersections–Sort them left to right–Fill the interior spans between intersections•Parity rule: inside afteran odd number of crossingsDCP4516 Introduction to Computer Graphics 32


Concave Polygons: Winding Rule•Approach 2: winding rule•Orient the lines in polygon•For each test line (not passing a vertex)CE–Winding number = right-hdd –left-hdd crossings–Interior if winding number non-zeroTest lineABD0+1+0+1+0=2Starting from A:0+0+0+1+0=1DCP4516 Introduction to Computer Graphics 3311 2 11 1


Even-odd Rule vs. Winding Rule•Different only for self-intersecting polygons121 11 1Even-odd ruleWinding ruleDCP4516 Introduction to Computer Graphics 34


Aliasing•Artifacts created during scan conversion•Inevitable (going from continuous to discrete)•Aliasing (name from digital signal processing):we sample a continuous image at grid points•Effects–Jagged edges–Moiré patternsDCP4516 Introduction to Computer Graphics 35


Sampling <strong>and</strong> Reconstruction•An image is a 2D array of discrete samplesfrom real-world continuous signalDCP4516 Introduction to Computer Graphics 36


Sampling <strong>and</strong> Aliasing•Artifacts due to undersampling or poorreconstruction•Formally, high frequencies masquerading as low•e.g. high frequency line as low freq jaggiesDCP4516 Introduction to Computer Graphics 37


(Spatial) AliasingDCP4516 Introduction to Computer Graphics 38


(Spatial) Aliasing•Jaggies probably biggest aliasing problemDCP4516 Introduction to Computer Graphics 39


Moiré Patterns due to Bad DownsamplingDownsampled without filteringOriginal ImageDCP4516 Introduction to Computer Graphics 40Downsampled after filtering


More AliasingDCP4516 Introduction to Computer Graphics 41


Antialiasing for Line Segments•Use area averaging at boundary•bottom is aliased, magnified•top is antialiased, magnifiedDCP4516 Introduction to Computer Graphics 42


Antialiasing by Supersampling•Traditionally for off-line rendering•Render, say, 3x3 grid of mini-pixels•Average results using a filter•Can be done adaptively–Stop if colors are similar–Subdivide at discontinuitiesDCP4516 Introduction to Computer Graphics 43


Supersampling Example•Other improvements–Stochastic sampling (avoiding repetition)–Jittering (perturb a regular grid)DCP4516 Introduction to Computer Graphics 44


Temporal Aliasing•Sampling rate is frame rate (30 Hz for video)•Example: spokes of wagon wheel in movie•Possible to supersample <strong>and</strong> average•Fast-moving objects are blurred•Happens automatically in video <strong>and</strong> movies–Exposure time (shutter speed)–Memory persistence (video camera)–Effect is motion blurDCP4516 Introduction to Computer Graphics 45


Intensities <strong>and</strong> Colors•Gamma correction•Color models–RGB–CMYK–HSV•Compositing–RGBA–Alpha blendingDCP4516 Introduction to Computer Graphics 46120green˚cyanblue240˚1.0black0.0VyellowmagentaH0˚redS


Gamma Correction•Monitors are nonlinear with respect to input•Adjust intensities based on an approximatenonlinear model: input intensitydisplayed intensity = ( max intensity ) a γ•Gamma correct inputa'a1DCP4516 Introduction to Computer Graphics 47


How to Determine Gamma?•Adjust input intensity of grey pixels until theintensities of checkerboard pixels are halfwaybetween black <strong>and</strong> white0.5 aadjust aln 0.5ln aDCP4516 Introduction to Computer Graphics 48


RGB Color Space: Additive Color•Form a color by adding amounts of threeprimaries: Red (R), Green (G), Blue (B)•CRTs, projection systems, positive filmDCP4516 Introduction to Computer Graphics 49


CMY Color Space: Subtractive Color•Form a color by filtering white light with:–Cyan (C), Magenta (M), <strong>and</strong> Yellow (Y) filters–Printing, Negative filmR + G = YG + B = CB + R = MY = W - BC = W - RM = W - GDCP4516 Introduction to Computer Graphics 50


Complementary Colors Add to Graybluemagenta(1,0,1)blue (0,0,1 )white(1,1,1)cyan(0,1,1)red(1,0,0)yellow(1,1,0)green(0,1,0)DCP4516 Introduction to Computer Graphics 51


HSV Color Space•Introduced by AlbetMunsell, late 1800s•Hue: Color•Saturation: strength of acolor–Neutral gray has 0 saturation•Value: Intensity of lightemanating from image120green˚cyanblue240˚1.0black0.0VyellowmagentaH0˚redSDCP4516 Introduction to Computer Graphics 52


Compositing•Frame buffer–Simple color model: R, G, B; 8 bits each–-channel A, another 8 bits•Alpha determines opacity, pixel-by-pixel–= 1: opaque–= 0: transparent•Blend translucent objects during rendering•Achieve other effects (e.g., shadows)DCP4516 Introduction to Computer Graphics 53C = C f + (1-C b


Transformations <strong>and</strong> Matrices•Transformations are functions•Matrices are function representations•Matrices represent linear transformations•2x2 Matrices ≡2D Linear transformation•Linear transformation Def : T ( ax y ) aT ( x) T ( y), for scalar a <strong>and</strong> vectors x <strong>and</strong> y.2 x2 Matrices2 D Linear Transf'sDCP4516 Introduction to Computer Graphics 54


DCP4516 Introduction to Computer Graphics 55Basic 2D TransformationsBasic 2D Transformations•Translation•Scaling•Rotationyxtyytxxtxxyxttyxyxysys xxyxx Sx 00yxssyxyxcossinsincosyxyyxxx Rxcossinsincosyxyx


Basic 2D Transformations (cont.)•Shear1aSh x0 1x y x yay10Sh yb 1x ybxxySh x10tanx x y tan 1 y y DCP4516 Introduction to Computer Graphics 56


Geometric View of Shear in xSh x10ytanx x y tan 1 y y y tanΦΦxxDCP4516 Introduction to Computer Graphics 57 57


Affine Transformation•A function F is affine if it is linear plus atranslation–Thus the 1-D transformation y = mx + b is not linear,but affine–Similarly for a translation <strong>and</strong> rotation of acoordinate system–Affine transformations preserve lines•= rigid transformation + shearing + scalingDCP4516 Introduction to Computer Graphics 58


Homogeneous Coordinates•Translation is not linear--how to represent it as amatrix?•Trick: add extra coordinate to each vectorxy1 10 0tx x tyy1 1 •This extra coordinate is the homogeneouscoordinate, or w010DCP4516 Introduction to Computer Graphics 59


Homogeneous Coordinates•When extra coordinate isused, vector is said to berepresented inhomogeneous coordinates•The associatedtransformation matricesHomogeneousTransformations•Drop extra coordinate aftertransformation (project tow=1)xy1x ff 0x112112220 x y y 1 fftx x tyy1 1 y , for 0DCP4516 Introduction to Computer Graphics 60


Homogeneous 2D Transformations•The basic 2D transformations becomeTranslate: Scale: Rotate:100010tx ty1 sx00001•Any affine transformation can be expressed as acombination of these.•We can combine homogeneous transforms bymultiplication.•Now any sequence of translate/scale/rotate operationscan be collapsed into a single homogeneous matrix0sy0cos sin 0sincos00 0 1DCP4516 Introduction to Computer Graphics 61


Composite Transformations•Matrix multiplicationisn’t commutative!DCP4516 Introduction to Computer Graphics 62


Windowing (Viewport) Transformation•[a, A] x [b, B] [c, C] x [d, D]•Translate(-a, -b)•Scale•Translate(c, d)M100010CccAad 0100D dB b0010010010ab1 DCP4516 Introduction to Computer Graphics 63


Basic 3D Transformations•3-D transformations are very similar to the 2-Dcase•Homogeneous coordinate transforms require 4x4matrices•Scaling <strong>and</strong> translation matrices are simply:100001000010txtytz1 DCP4516 Introduction to Computer Graphics 64S000x0Sy0000Sz00001


3D Rotation Matrices•Rotation is a bit more complicated in 3-D•More possible axes of rotation•e.g., rotate about z-axis: only x <strong>and</strong> ycoordinate changeRotate-z(Φ) =cossin 0 0sin 0cos000100001DCP4516 Introduction to Computer Graphics 65


3D Rotation Matrices about x- <strong>and</strong> y- axesRotate-x(Φ) =10000cossin00sincos00001Rotate-y(Φ) =cos0sin 00100sin0cos00001DCP4516 Introduction to Computer Graphics 66


Properties of Rotation Matrices•Rotation matrices are orthonormal–Rows/Columns are mutually orthonormal–Rows/Columns form a Cartesian coordinate•Geometrically, R -1 (θ) = R(-θ)•Algebraically, R -1 (θ) = R T (θ)–Prove by yourself that R T (θ)R(θ) = R(θ)R T (θ) = Iusing orthonormality of R•R -1 (θ) = R(-θ) = R T (θ)DCP4516 Introduction to Computer Graphics 67


Arbitrary 3D Rotations•Can we construct an arbitrary 3D rotationusing basic rotation matrices Rx() Ry() Rz()?z+θ aαyxDCP4516 Introduction to Computer Graphics 68


Transforming Normal Vectors•If we transform normals like points•We need a different rule to transformnormals.DCP4516 Introduction to Computer Graphics 69


Normals Transform Like PlanesA planen pn( a,b,c )IfTopnp0isfindnnTTnp( nTT(nMpax byTisIp( MTptheMtheMto0,1equation11equationtransform)Tczplanetransform ed,answer,M ) p)( Mp )Mdwherehowdofor1TforpointpointpointtoDCP4516 Introduction to Computer Graphics 70nnnormal,0 cansomeTTab c d ,p x y z 1disshouldononbethenmagicplaneplanetransformwrittenoffset.transform ?:ininplaneoriginaltransformespacedspace


Global vs. Local Coordinate System•Need to h<strong>and</strong>le multiple coordinate systems•A “canonical”coordinate system is usuallydesignated as the frame-of-reference for allother coordinates–Global coordinate–World coordinate–Frame of reference•The others are calledlocal coordinatesDCP4516 Introduction to Computer Graphics 71


Global vs. Local Coordinate System•x, y, u, v, o, e are all vectors in global systemp ( xp,yp)oxpxypyIn global coord. (x p ,y p )p ( up,vp)eupuvpvIn local coord. (u p ,v p )xp 10 xe0upy 0p0 1 y eu v vp1 0 0 1 11 Tup u 1 0 xe xp T v p v0 1 yeyp1 00 100 1 1 DCP4516 Introduction to Computer Graphics 72


Think about 3D case ….•Given two coordinate frames, how do yourepresent a vector specified in one frame inthe other frame? xp upZYwDCP4516 Introduction to Computer Graphics 73XePvuyz1ppuvw1ppp ??vw1ppxyz1ppp


ViewingGiven geometry in the world coordinate system,how do we get it to the display?•Transform to camera coordinate system•Transform (warp) into canonical view volume•Clip•Project to display coordinates•RasterizeDCP4516 Introduction to Computer Graphics 74


Viewing <strong>and</strong> Projection•Our eyes collapse 3-D world to 2-D retinal image(brain then has to reconstruct 3D)•In CG, this process occurs by projection•Projection has two parts:–Viewing transformations: camera position <strong>and</strong> direction–Perspective/orthographic transformation: reduces 3-D to 2-D•Use homogeneous transformationsDCP4516 Introduction to Computer Graphics 75


Viewing Transformation: Camera Control•All we need is a single translation <strong>and</strong> angleaxisrotation (orientation), but...•Good animation requires good cameracontrol--we need better control knobs•Translation knob - move to the lookfrompoint•Orientation can be specified in several ways:–specify camera rotations–specify a lookat point (solve for camera rotations)DCP4516 Introduction to Computer Graphics 76


A Popular View Specification Approach•Focal length, image size/shape <strong>and</strong> clipping planesare in the perspective transformation•In addition:–lookfrom: where the focal point (camera) is–lookat: the world point to be centered in the image•Also specify camera orientation about the lookfromlookfataxisDCP4516 Introduction to Computer Graphics 77


Implementing lookat/lookfrom/vupviewing scheme•Translate by lookfrom, bring focal point toorigin•Rotate lookfrom - lookat to the z-axis withmatrix R:–w = (lookfrom-lookat) (normalized) <strong>and</strong> z = [0,0,1]–rotation axis: a = (w × z)/|w × z|–rotation angle: cosθ= w•z <strong>and</strong> sinθ= |w × z|•Rotate about z-axis to get vup parallel to they-axisDCP4516 Introduction to Computer Graphics 78


It’s not so complicated…yxzvuplookfromyxzyxSTART HEREwzTranslate LOOKFROMto the originRotate the view vector(lookfrom - lookat) ontothe z-axis.yMultiply by the projection matrix<strong>and</strong> everything will be in thecanonical camera positionDCP4516 Introduction to Computer Graphics 79zRotate about z to bring vup to y-axisx


Rotate Camera Frame•Alternatively, we can view these tworotations as a single rotation that aligns u-vw-axesto x-y-z-axes!yvxzww: lookat –lookfromv: view up directionu = v x wx Ruy Rvz RwxuyzuuxR yzuuuxvyzvvxyzzwxwwyvvvxyz100www1010xxx0x0Ry 1zuvwyyyuvwuuuzzzuvwxyzvvvxyzwww DCP4516 Introduction to Computer Graphics 80


DCP4516 Introduction to Computer Graphics 81Viewing TransformationViewing Transformation•Put translation <strong>and</strong> rotation together100010001000100011000000ewwwevvveuuueeewwwvvvuuuvzzyxyzyxxzyxzyxzyxzyxzyxRM tMXYZeuvwP11ppppppzyxwvuM vworld coordinatelocal coordinate


Orthographic Projection•When the focal point is at infinity the rays areparallel <strong>and</strong> orthogonal to the image plane•When xy-plane is the image plane (x,y,z) -> (x,y,0)front orthographic viewFImageWorldDCP4516 Introduction to Computer Graphics 82


Orthographic Projection•Map orthographic viewing cube to thecanonical view volume•3D window transformation•[l, r] x [b, t] x [f, n] [-1, 1]x[-1, 1]x[-1,1]DCP4516 Introduction to Computer Graphics 83


Orthographic Projection (cont.)•3D window transform (last class)•[l, r] x [b, t] x [f, n] [-1, 1]x[-1, 1]x[-1,1]xyzcanonicalcanonicalcanonical1•z canonical2 rl 0 0 002t b00is ignoredl r0 01 0 0 2b t0 00 1 0 22 n f0 0 0 1 n f20 10 0 0 1xyz1DCP4516 Introduction to Computer Graphics 84


Canonical View Volume to Screen•If y-axis of screen coord. points downward•[-1,1] x [-1, 1] [-0.5, n x -0.5] x [n y -0.5, -0.5]xyzpixelpixelpixel10 0010nnxy1nx2 2102 1 00ny200100100100x0y1canonicalcanonical1translationscalereflectionDCP4516 Introduction to Computer Graphics 85


DCP4516 Introduction to Computer Graphics 86Orthographic Projection MatrixOrthographic Projection Matrix•Put everything together10002100201020011000020000200002100001002102021002fntbrlfnbtlrnnnnyyxxM o11zyxzyxcanonicalpixelpixelM o


Orthographic Projection SummaryGiven 3D geometry (a set of points a)•Compute view transformation M v•Compute orthographic projection M o•Compute M = M o M v•For each point a i , compute p = Ma iMnx20000ny2000010n 2x12 rlny102 0 01 002t b00002n f00100001001000010l r2b t2n f21xuxvxw0yyyuvw0zzzuvw0xyz1eeeDCP4516 Introduction to Computer Graphics 87


Perspective Projection of a Point•View plane or image plane - a plane behind thepinhole on which the image is formed–sees anything on the line (ray) through the pinhole F–a point W projects along the ray through F to appear atI (intersection of WF with image plane)IImageFWorldWDCP4516 Introduction to Computer Graphics 88


A Simple Perspective Camera•Canonical case:–camera looks along the z-axis (toward negative z-axis)–focal point is the origin–image plane is parallel to the xy-plane at distance d–We call d the focal length, mainly for historical reasonsImage planeCenter of projectionDCP4516 Introduction to Computer Graphics 89


Geometry Eq. for Perspective Projection•Diagram shows y-coordinate, x-coordinate is similar•Point (x,y,z) projects tody szyd d( x,y,d )z zview planeye: eye positiong: gaze directionedgy szDCP4516 Introduction to Computer Graphics 90


Perspective Projection Matrix•Projection using homogeneous coordinates:–transform (x,y,z) to d d( x,y,d )z zd0000d0000d10xdx0y dy 0zdz 01z•2-D image point:–discard third coordinateDivide by 4 th coordinate(the “w”coordinate)d d( x,y,d )z z–apply viewport transformation to obtain physical pixelcoordinatesDCP4516 Introduction to Computer Graphics 91


Perspective Projection Matrix•Projection using homogeneous coordinates:–transform (x,y,z) to d d( x,y,d )z zd0000d0000d10xdx0y dy 0zdz 01z•2-D image point:–discard third coordinateDivide by 4 th coordinate(the “w”coordinate)d d( x,y,d )z z–apply viewport transformation to obtain physical pixelcoordinatesDCP4516 Introduction to Computer Graphics 92


View Volume <strong>and</strong> View Frustum•Pyramid in space defined by focal point <strong>and</strong>window in the image plane•Defines visible region of space•Pyramid edges are clippingplanes–Near <strong>and</strong> far clippingplanes–Field of viewDCP4516 Introduction to Computer Graphics 93


Map Perspective View Volume toOrthographic View Volume•Map [x,y,n] to [nx/z, ny/z, n]•Map [x,y,f] to [nx/z, ny/z, f]M p10000100n00fn1n00f0DCP4516 Introduction to Computer Graphics 94


Projection Matrix is not unique•M p is not uniquex' hx xy' hy y M p hM pz' hz z 1 h 1M pnMp10n000100n00fn1n00f0 n 0 0 00n00n00f100nf0DCP4516 Introduction to Computer Graphics 95


Perspective Projection SummaryGiven 3D geometry (a set of points a)•Compute view transformation M v•Map perspective to orthographic M p•Compute orthographic projection M o•Compute M = M o M p M v•For each point a i , compute p = Ma iDCP4516 Introduction to Computer Graphics 96


Hidden Surface Elimination•Backface culling•BSP tree•Z-buffer (next class)DCP4516 Introduction to Computer Graphics 97


Back Face Culling: Object SpacevnvznnDCP4516 Introduction to Computer Graphics 98nvv


Back Face Culling: Object SpaceVisible:vn 0vzn n vzUtah School of Computing 99


Creating a BSP tree201201335b4b 4f 4b5f5b4f5f4 -> 4f,4bDCP4516 Introduction to Computer Graphics 100


Back-to-Front Render2 0 5b 1 4f 3 5f 4b20120135b4b 4f 4b5f35b4f5fDCP4516 Introduction to Computer Graphics 101


z-Buffer Algorithm•The z or depth buffer–stores the depth of the closest object at each pixelfound so far•As we render each polygon, compare the depth ofeach pixel to depth in z buffer–If less, place the shade of pixel in the color buffer <strong>and</strong>update z bufferDCP4516 Introduction to Computer Graphics 102


Integer Z-buffer•If B bins are used for depth range (n, f)•Bin size △z = (n-f)/B•Smaller △z is desirable–Depth of two objects are indistinguishable if △z islarger than the difference between their real z-values–Increase B–Move n <strong>and</strong> f closerDCP4516 Introduction to Computer Graphics 103


Bin size for z-buffer in world space•Bin size in the world space increases asdepth increases•Objects farther away is more likely to beindistinguishable in depth (same integer z-values)zw2zwfnzz w =fz maxwfzn•Maximize n <strong>and</strong> minimize f for small △z wDCP4516 Introduction to Computer Graphics 104

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!