1 / 14

CS 497: Computer Graphics

CS 497: Computer Graphics. James Money. Back Face Culling. The idea behind back-face culling is to remove faces of an object that are obscured by other faces of the same object. X. Gray polygons are back facing. Z. Back-Face Culling.

yaholo
Télécharger la présentation

CS 497: Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 497: Computer Graphics James Money

  2. Back Face Culling The idea behind back-face culling is to remove faces of an object that are obscured by other faces of the same object. X Gray polygons are back facing Z

  3. Back-Face Culling It is easy to determine if a polygon is back facing: the Z component(C in Ax+By+Cz+D=0) is <0. Some restrictions: • The normals for all the faces must face outward for objects. • Points in a polygon, thus must be created in a clockwise fashion. This process typically halves the number of polygons, but not always. All we need to do is add a Boolean Function for visibility to the Polygon3D object.

  4. Visible Surface Determination Now that you have reduced the number of polygons to draw, which ones are you actually seeing? What about overlapping polygons??? The answer lies in algorithms called visible surface determiners.

  5. Z Buffer Algorithm One of the most simple and most commonly used VSA’s is the Z Buffer algorithm. It is an image precision algorithm. It uses the frame buffer for the picture, but also a Z Buffer, where instead of pixel values, it has the Z depth of the closest polygon.

  6. void zBuffer(void){ int x,y; double *zBuf zBuf=new double[XMAX*YMAX]; for(y=0;y<YMAX;y++) for(x=0;x<XMAX;x++){ SetPixel(hDC,x,y,RGB(0,0,0));//background zBuf[y*XMAX,+x]=Zv.max-Zv.min;//as far back //as we can go! } for(each polygon){ for(each pixel in polygon’s projection){ double pz=-[poly’s Z-value at (x,y)]; if (pz<=zBuf[y*XMAX+x]){ zBuf[y*XMAX+x]=pz; SetPixel(hDC,x,y,PixelColor); } } } }

  7. Determining Z • Remember for polygons we can get the normal from 3 points of the polygon: • Ax+By+Cz+D=0 • For our first point we find z by:

  8. Determining Z However, this is expensive to computer for every (x,y). We can do this by increments: • At • At • If C=0 then use an average of Z at the vertices.

  9. Filling a 2D Polygon In order to draw these 3D polygons with the Z Buffer algorithm, we need to design our own function to draw the polygons.

  10. Filling a 2D polygon First we must compose the points of the polygon into edges: AB EA BC DE CD

  11. Filling a 2D polygon • First we must create a structure for each edge to contain: • Ymin • Ymax • X - the X coordinate of point with Ymin • 1/m or the X increment

  12. Filling a 2D polygon • Next we create a table for these edges sorted by Ymin as on page 98. • These edges are sorted by the X coordinate in increasing order. • This makes up the edge table.

  13. Filling a 2D polygon • Now you will have Active Edge Table(AET) for all the active edges on the line y=xxx. You initialize it to empty. • Set y to the smallest y in the edge table.

  14. Filling a 2D polygon • Repeat until Y=max Y of polygon(or until AET and ET are empty). • Move from ET to AET any edge whose Ymin=y. • Remove from AET any edge whose entry has y=Ymax. Sort AET on increasing X. • Fill in pixels using pairs of X coordinates on line y. • Increment y by 1. • Add 1/m to x.

More Related