2. Painter’s Algorithm
• Display polygons in
back-to-front order
• Sort polygons by z-value
-z
– Which vertex?
– O(n log n)
• Problems…
3. Quadtree Algorithm
• Sort polygons
• Subdivide screen until each region
contains one or zero edges
• Invented by John Warnock in 1969
4. Quadtree Algorithm
• Sort polygons
• Subdivide screen until each region
contains one or zero edges
• Invented by John Warnock in 1969
5. Quadtree Algorithm
• Sort polygons
• Subdivide screen until each region
contains one or zero edges
• Invented by John Warnock in 1969
6. Quadtree Algorithm
• Sort polygons
• Subdivide screen until each region
contains one or zero edges
• Invented by John Warnock in 1969
7. Quadtree Algorithm
• Sort polygons
• Subdivide screen until each region
contains one or zero edges
• Invented by John Warnock in 1969
8. Z-Buffer -far
-far
-far
-far
Key Observation: Each pixel displays -far
-far
color of only one triangle, ignores -far
everything behind it -far
-far
• Don’t need to sort triangles, just find -far
-far
for each pixel the closest triangle -far
• Z-buffer: one fixed or floating point
zbuffer
framebuffer
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
9. Z-Buffer -far
-.1
-.2
-.3
Key Observation: Each pixel displays -.4
-.5
color of only one triangle, ignores -.6
everything behind it -.7
-.8
• Don’t need to sort triangles, just find -far
-far
for each pixel the closest triangle -far
• Z-buffer: one fixed or floating point
zbuffer
framebuffer
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
10. Z-Buffer -far
-.1
-.2
-.3
Key Observation: Each pixel displays -.4
-.3
color of only one triangle, ignores -.1
everything behind it -.7
-.8
• Don’t need to sort triangles, just find -far
-far
for each pixel the closest triangle -far
• Z-buffer: one fixed or floating point
zbuffer
framebuffer
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
11. Z-Buffer -far
-.1
-.2
-.3
• Get fragment z-values by interpolating -.4
-.3
z-values at 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
12. Normalized View Volume
glFrustum(left,right,bottom,top,near,far)
y
y
(-1,1,1)
1
z z (0,0,-far)
y
x x
-1
-1
x
1
z
1 -1
Screen Clip Viewing World Model
W2V Persp View Model
Coords Coords Coords Coords Coords
13. Perspective Projection
screen
y yview
yclip
-z
zview
d
xview
yclip zview / d
xview
1 xview
yview
d zview yview
1 yview yview
zview / d
zview
yview 1 zview
yclip
zview / d d
zview / d
1/ d 0 1
1
16. Normalized Perspective Distortion
y
y
(-1,1,1)
1
z z (0,0,-far)
y
x x
-1
-1
x
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
17. Hierarchical Z-Buffer
-.2
-.3
-.3
• Invented by Ned Green in 1994 -.5
-.4
-.5
-.5
• Creates a MIP-map of the z-buffer -far
-.6
-.7
-.7
– z-value equal to farthest z-value of -far
-.8
-far
-far
its 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