1 / 16

z-buffer and shading

z-buffer and shading. ©Anthony Steed 1999. Overview. Coping with depth Scan-line depth buffering Z-buffer Recursive sub-division Trade-offs gouraud shading phong shading. Extending the AET. Easy enough if polygon do NOT intersect

kira
Télécharger la présentation

z-buffer and shading

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. z-buffer and shading ©Anthony Steed 1999

  2. Overview • Coping with depth • Scan-line depth buffering • Z-buffer • Recursive sub-division • Trade-offs • gouraud shading • phong shading

  3. Extending the AET • Easy enough if polygon do NOT intersect • Put all polygon edges into ET with extra depth information and proceed as before except … • … now consider overlapping ranges of edges

  4. AET Example

  5. AET Example Notes • Our edge table must contain data which enables us to look up z at at intersection point • From x1 to x2 only A is considered. • At x2 A and B are considered • plane equations are solved to get depth • A is closest so x2 to x3 is filled as A • At x3 A finishes so we draw B from x3 to x4 • At x4 B and C are considered, B in front etc… • Would usually store this in a 1D BSP tree for large numbers of polygons!

  6. zbuffer • Don’t bother with per span tests - just test every pixel • Most common usage is a a full window sized array (M*N) of 16, 24 or 32 bit “depth” values. • Basic idea: • For each pixel in each polygon • IF col = colour on polygon at unprojected point x,y • If z < ZBUF[x,y] set CBUF[x,y] = col • Initialise buffer to Z_MAX

  7. Zbuffer Details • Can do this in several ways • 1D z-buffer re-used on each scan line • Process each polygon with separate AET • Use as adjunct to extended AET for multiple polygons • Problems … • Aliasing on depth (z-buffer tearing)

  8. Scanning Depth into the Zbuffer • Now we have to write a z-value for each point • directly from plane equation (re-calculate for each point) • incremental across the scan-line (store z_start and dz) • interpolate …

  9. Interpolating Depth • Interpolate z along edges AND interpolate between edges on each scan-line (bi-linear interpolation) (X2,Y2,Z2) (XL,YL,ZL) (XR,YR,ZR) (X1,Y1,Z1)

  10. Zbuffer Fill Example • General form of ET • (y2,x1,dx/dy,z1,dz/dy) • ET[1] = • ac (7,3,1/6,1,3/6) • ab (4,3,4/3,1,1/3) • ET[4] = • cb (7,7,-1,2,2/3) a=(3,1,1) b=(7,4,2) c=(4,7,4)

  11. …Contents of AET • Scanline y=1 • ac (7,3,1/6,1,3/6) • ab (4,3,4/3,1,1/3) zspans 1 to 1 • y=2 • ac (7,3.166,1/6,1.5,3/6) • ab (4,4.333,4/3, 1.333, 1/3) zspans 1.5 to 1.333 • y3 • ac (7,3.333,1/6,2.0,3/6) • ab (4,5.666, 4/3, 1.666, 1/3) zspans 2 to 1.666

  12. Recursive Subdivision Visibility • The window is covered by a polygon that is in front of all others (draw it) • The window does not intersect a polygon (draw nothing) • The window overlaps a single polygon (draw it clipped) • The window contains a single polygon (draw it unclipped) • ELSE quarter rectangle and repeat

  13. Trade-Offs • Zbuffer can be inaccurate with few bits • really simple to implement though! • Scan-line AET good for large polygons • good coherency across lines • requires non-intersecting polygons • zbuffer good for small, sparse polygons • AET more time consuming to maintain

  14. Gouraud Shading • Recall simple model for local diffuse reflection • Gouraud interpolates this colour down edges and across scan-lines in the same manner as we just did for depth

  15. Gouraud Details • ET now contains • (y2,x1,dx,z1,dz,r1,dr,g1,dg,b1,db) • (we are running out of registers!) • Problems • not constant colour on rotation of points • misses specular highlights

  16. Phong Shading • Include specular component • Interpolate normals across the scan-line instead of colours • Recaptures highlights in the centre of polygons

More Related