170 likes | 319 Views
Visible Surface Determination. CS418 Computer Graphics John C. Hart. Painter’s Algorithm. Display polygons in back-to-front order Sort polygons by z-value Which vertex? O ( n log n ) Problems…. -z. Quadtree Algorithm. Sort polygons
E N D
Visible Surface Determination CS418 Computer Graphics John C. Hart
Painter’s Algorithm • Display polygons inback-to-front order • Sort polygons by z-value • Which vertex? • O(n log n) • Problems… -z
Quadtree Algorithm • Sort polygons • Subdivide screen until each region contains one or zero edges • Invented by John Warnock in 1969
Quadtree Algorithm • Sort polygons • Subdivide screen until each region contains one or zero edges • Invented by John Warnock in 1969
Quadtree Algorithm • Sort polygons • Subdivide screen until each region contains one or zero edges • Invented by John Warnock in 1969
Quadtree Algorithm • Sort polygons • Subdivide screen until each region contains one or zero edges • Invented by John Warnock in 1969
Quadtree Algorithm • Sort polygons • Subdivide screen until each region contains one or zero edges • Invented by John Warnock in 1969
Z-Buffer -far -far -far -far Key Observation: Each pixel displays color of only one triangle, ignores everything behind it • Don’t need to sort triangles, just find for each pixel the closest triangle • Z-buffer: one fixed or floating point value per pixel • Algorithm: For each rasterized fragment (x,y) If z > zbuffer(x,y) then framebuffer(x,y) = fragment color zbuffer(x,y) = z -far -far -far -far -far -far -far -far zbuffer framebuffer
Z-Buffer -far -.1 -.2 -.3 Key Observation: Each pixel displays color of only one triangle, ignores everything behind it • Don’t need to sort triangles, just find for each pixel the closest triangle • Z-buffer: one fixed or floating point value per pixel • Algorithm: For each rasterized fragment (x,y) If z > zbuffer(x,y) then framebuffer(x,y) = fragment color zbuffer(x,y) = z -.4 -.5 -.6 -.7 -.8 -far -far -far zbuffer framebuffer
Z-Buffer -far -.1 -.2 -.3 Key Observation: Each pixel displays color of only one triangle, ignores everything behind it • Don’t need to sort triangles, just find for each pixel the closest triangle • Z-buffer: one fixed or floating point value per pixel • Algorithm: For each rasterized fragment (x,y) If z > zbuffer(x,y) then framebuffer(x,y) = fragment color zbuffer(x,y) = z -.4 -.3 -.1 -.7 -.8 -far -far -far zbuffer framebuffer
Z-Buffer -far -.1 -.2 -.3 • Get fragment z-values by interpolating z-values at vertices during rasterization • Perspective projection destroysz-values, setting them all to –d • Need a perspective distortion that preserves at least the ordering ofz-values -.4 -.3 -.1 -.7 -.8 -far -far -far zbuffer framebuffer
Normalized View Volume glFrustum(left,right,bottom,top,near,far) y y (-1,1,1) (left,top,-near) 1 z z (0,0,-far) y x x -1 (right,bottom,-near) -1 x 1 z 1 -1 ScreenCoords ClipCoords ViewingCoords WorldCoords ModelCoords
Perspective Projection screen y yview yclip -z zview d
Perspective Distortion screen y yview yclip -z zview 1
Distorted z-Values z1 z2 -z if z1 > z2 then -a – b/z1 > -a – b/z2 1/-z curve -a – b/z1 -a – b/z2 -a -a – b/z
Normalized Perspective Distortion y y (-1,1,1) (left,top,-near) 1 z z (0,0,-far) y x x -1 (right,bottom,-near) -1 x 1 z 1 -1
Hierarchical Z-Buffer -.2 -.3 -.5 -far -.3 • Invented by Ned Green in 1994 • Creates a MIP-map of the z-buffer • z-value equal to farthest z-value of its four children • 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 displayingfront-to-back -.4 -.5 -.5 -.6 -.7 -far -.7 -.8 -far -far hierarchical zbuffer framebuffer