Some Tutoral about the Project Lecture 6 Rastersaton, Antalasng, Texture Mappng, I have already covered all the topcs needed to fnsh the 1 st practcal Today, I wll brefly explan how to start workng on t. I have already provded you a program to mport an obj fle. 2 Steps Apply transformatons to all vertces Prepare the frame buffer and Z-buffer For each trangle Project t to the screen space Fnd the 2D boundng box For each pxel n the boundng box Check f t s nsde the trangle by computng ts barycentrc coordnates If yes, use barycentrc coordnates to compute the depth and colour at the pxel If (depth < zbuf[pxel]) { framebuffer[pxel] = colour zbuf[pxel] = depth } Export the frame buffer data nto a PPM fle 3 For each pxel n the boundng box Check f t s nsde the trangle by computng ts barycentrc coordnates If yes, use barycentrc coordnates to compute the depth and colour at the pxel z = αz1 + β z2 + γ z3 c = αc1 + β c2 + γ c3 If (z < zbuf[pxel]) { framebuffer[pxel] = colour zbuf[pxel] = c } Computng the barcentrc coordnates of the nteror pxels The trangle s composed of 3 ponts p (y), p1 (x1, y1), p2(x2,y2) Ant-alasng Texture mappng Today Common texture coordnates mappng Texture coordnates (α,β,γ) : barycentrc coordnates Only f <α,β,γ<1, (y) s nsde the trangle Depth can be computed by αz + βz1 +γz2 Can do the same thng for color, normals, textures 5 6 1
Rastersaton Converts the vertex nformaton output by the geometry ppelne nto pxel nformaton needed by the vdeo dsplay Ant-alasng Z-buffer Texture mappng Bump mappng Transparent objects Drawng lnes Ant-alasng Alasng: dstorton artfacts produced when representng a hgh-resoluton sgnal at a lower resoluton. Ant-alasng : technques to remove alasng 7 Alased polygons (jagged edges) Ant-alased polygons 8 Nyqust Lmt Screen-based Ant-alasng Each pxel s subdvded (sub-sampled) nto n regons, and each sub-pxel has a color; Compute the average color value The sgnal frequency (fsgnal) should be no greater than half the sample frequency (fsample) fsgnal <=.5 fsample In the top, fsgnal =.8 fsample -> cannot reconstruct the orgnal sgnal In the bottom fsgnal =.5 fsample -> the orgnal sgnal can be reconstructed by slghtly ncreasng the samplng rate p( y) = = 1 p( y) : pxel color at ( y) c(, y) : sample color w : weght n w c(, y) 1 Accumulaton Buffer (A-Buffer) Use a buffer that has the same resoluton as the orgnal mage To obtan a 2x2 samplng of a scene, 4 mages are made by shftng the buffer horzontally/vertcally for half a pxel The results are accumulated and the fnal results are obtaned by averagng Varous samplng schemes are avalable Pxel center Subsampled pont Dfferent Samplng Schemes 2
Accumulaton Buffer (A-Buffer) The lghtng computaton s usually done only once per vertex Not dong the lghtng computaton at each sample pont The A-buffer s focus s on the edge antalasng Also useful for renderng transparent objects, moton blur (wll be covered later n the course) Edges Stochastc Samplng A scene can be produced of objects that are arbtrarly small A regular pattern of samplng wll always exhbt some sort of alasng One approach to solve ths s to randomly sample over the pxel Jtterng : subdvde nto n regons of equal sze and randomly sample nsde each regon The oversamplng rate s 1 and 2 from left to rght Today Texture Mappng : Why needed? Ant-alasng Texture mappng Common texture coordnates mappng Texture coordnates We don't want to represent all ths detal wth geometry 17 3
Texture mappng. Texture mappng. Method of mprovng surface appearance by addng detals on surface. Image s pasted onto a polygon. Image s called a Texture map, t s pxels are often referred as a Texels and have coordnates (u,v) Texture coordnates are defned for each vertex of the polygon and nterpolated across the polygon. v u y v x u 19 2 Photo-textures Texture Interpolaton Specfy a texture coordnate (u,v) at each vertex Can we just lnearly nterpolate the values n screen space? (,1) (,) (1,) Interpolatng the uv coordnates Agan, we use barcentrc coordnates u1 v1 Interpolaton - What Goes Wrong? Lnear nterpolaton n screen space: u= α u1 + β u2 + γ u3 v = α v1 + β v2 + γ v3 u3 v3 u2 v2 texture source what we get what we want 4
Why does t happen? Unform steps on the mage plane does not correspond to unform steps along the edge How do we deal wth t? Use hyperbolc nterpolaton (u,v) cannot be lnearly nterpolated, but 1/w and (u/w, v/w) can w s the last component after the canoncal vew transformaton 2n x pw r l y pw = z pw w 2n t b r + l r l t + b t f + b n f n 1 x y 2 fn z f n 1 Texture Mappng Examples Computng the uv coordnates at the nternal ponts For three ponts of the trangle, get r = [ p 1 u v,,, ] w w w Lnear nterpolaton vs. Hyperbolc nterpolaton Two trangles per square 1 u v [,, ] Compute w at the nternal ponts of the w w trangle by nterpolaton Compute w by nvertng 1/w, and multply them to (u /w,,v /w) to compute (u,v) Common Texture Coordnate Mappngs Orthogonal Cylndrcal Sphercal Texture Mappng & Illumnaton Texture mappng can be used to alter some or all of the constants n the llumnaton equaton: pxel color, dffuse color. Phong s Illumnaton Model Constant Dffuse Color Dffuse Texture Color Texture used as Label Texture used as Dffuse Color 5
Readngs Chapter 5.1-2 of Real-Tme Renderng Second edton http://books.google.co.uk/books?d=mokefbt w4xc&prntsec=frontcover&source=gbs_v2_ summary_r&cad=#v=onepage&q=&f=false Hyperbolc Interpolaton IEEE Computer Graphcs and Applcatons, vol12, no.4, 89-94, 1992 Demoed Software http://www-u.s.s.u-tokyo.ac.jp/~takeo/java/smoothteddy/ndex.html 6