Visible Surface Determination CS418 Computer Graphics John C. Hart
Painter’s Algorithm
Painter’s Algorithm
Painter’s Algorithm
Painter’s Algorithm
Painter’s Algorithm
Painter’s Algorithm Backface Culling • Q: How does Bob Ross paint the trees so fast? • A: He doesn’t paint the back sides of the trees. • Cull triangles that face away from the viewer v ⋅ n (view) ≤ 0 v
Painter’s Algorithm • Display polygons in back-to-front order
Painter’s Algorithm • Display polygons in back-to-front order
Painter’s Algorithm • Display polygons in back-to-front order
Painter’s Algorithm • Display polygons in back-to-front order • Sort polygons by z-value – O(n log n) – Which vertex?
Painter’s Algorithm • Display polygons in back-to-front order • Sort polygons by z-value – O(n log n) – Which vertex? • Problems…
Quadtree Algorithm • Subdivide screen until each region is simple (e.g. one polygon) or is a pixel • Invented by John Warnock in 1969
Z-Buffer -far -far -far -far Key Observation: Each pixel displays color of only one -far -far triangle, ignores everything behind it -far • Don’t need to sort triangles, just find for each pixel -far -far the closest triangle -far -far • Z-buffer: one fixed or floating point value per pixel -far zbuffer framebuffer • Algorithm: For each rasterized fragment ( x , y ) If z > zbuffer( x , y ) then framebuffer( x , y ) = fragment color zbuffer( x , y ) = z
Z-Buffer -far -.1 -.2 -.3 Key Observation: Each pixel displays color of only one -.4 -.5 triangle, ignores everything behind it -.6 • Don’t need to sort triangles, just find for each pixel -.7 -.8 the closest triangle -far -far • Z-buffer: one fixed or floating point value per pixel -far zbuffer framebuffer • Algorithm: For each rasterized fragment ( x , y ) If z > zbuffer( x , y ) then framebuffer( x , y ) = fragment color zbuffer( x , y ) = z
Z-Buffer -far -.1 -.2 -.3 Key Observation: Each pixel displays color of only one -.4 -.3 triangle, ignores everything behind it -.1 • Don’t need to sort triangles, just find for each pixel -.7 -.8 the closest triangle -far -far • Z-buffer: one fixed or floating point value per pixel -far zbuffer framebuffer • Algorithm: For each rasterized fragment ( x , y ) If z > zbuffer( x , y ) then framebuffer( x , y ) = fragment color zbuffer( x , y ) = z
Z-Buffer -far -.1 -.2 -.3 • Get fragment z-values by interpolating z-values at -.4 -.3 vertices during rasterization -.1 -.7 -.8 • Perspective projection destroys -far -far z-values, setting them all to – d -far zbuffer framebuffer • Need a perspective distortion that preserves at least the ordering of z-values
Normalized View Volume y y (-1,1,1) 1 z z (0,0,-far) y x x -1 x -1 1 z 1 -1 Screen Clip Viewing World Model W2V Persp View Model Coords Coords Coords Coords Coords
Perspective Projection screen y y view y clip -z z view d x view − y 1 x z / d y x clip = − view view view view d z 1 y y y = view view view view ≡ − / z d y 1 z z view = − view view view y clip − − − z view / d d 1/ d 0 1 z / d view 1
Perspective Distortion screen y y view y clip -z z view 1 x view − z view 1 x x view view y view y 1 y y = − view − view = view ≡ y z clip view α + β α β z z z view view view β − α − − − 1 0 1 z view z view 1
Distorted z-Values z 1 z 2 - z if z 1 > z 2 then - α – β / z 1 > - α – β / z 2 1/- z curve - α – β / z 1 - α – β / z 2 - α - α – β / z x view − z view 1 x x view view y view y 1 y y = − view − view = view ≡ y z clip view α + β α β z z z view view view β − α − − − 1 0 1 z view z view 1
Normalized Perspective Distortion y y (-1,1,1) 1 z z y (0,0,-far) x -1 x x -1 1 z 1 -1 − × + 2 near right left − − right left right left − × + 2 near top bottom − − top bottom top bottom + × × far near 2 far near − − − far near far near − 1 0
Hierarchical Z-Buffer -.2 -.3 -.3 -.5 • Invented by Ned Green in 1994 -.4 -.5 -.5 • Creates a MIP-map of the z-buffer -far -.6 -.7 -.7 – z-value equal to farthest z-value of its -far -.8 -far -far four children framebuffer hierarchical zbuffer • Before rasterizing a triangle… – Check z-value of its nearest vertex against z-value of the smallest quadtree cell containing the triangle – If z-test fails, then the entire triangle is hidden and need not be rasterized • Works best when displaying front-to-back
Recommend
More recommend