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.
Download
Report
Transcript 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.
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
• 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
zbuffer
framebuffer
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
-far
-far
-far
-far
Z-Buffer
zbuffer
framebuffer
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
-.1
-.2
-.3
-.4
-.5
-.6
-.7
-.8
-far
-far
-far
Z-Buffer
zbuffer
framebuffer
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
-.1
-.2
-.3
-.4
-.3
-.1
-.7
-.8
-far
-far
-far
Z-Buffer
• Get fragment z-values by interpolating
z-values at vertices during rasterization
• Need a perspective distortion that
preserves at least the ordering of
z-values
framebuffer
• Perspective projection destroys
z-values, setting them all to –d
zbuffer
-far
-.1
-.2
-.3
-.4
-.3
-.1
-.7
-.8
-far
-far
-far
Normalized View Volume
glFrustum(left,right,bottom,top,near,far)
y
y
(-1,1,1)
1
z
z
(0,0,-far)
y
x
-1
x
-1
x
1
1
z
-1
Screen
W2V Clip Persp Viewing View World Model Model
Coords
Coords
Coords
Coords
Coords
Perspective Projection
screen
y
yview
yclip
-z
zview
d
yclip
d
yclip
yview
zview
yview
zview / d
1
1
1
1/ d
xview
xview xview zview / d
y
y
y
view view view
zview zview zview / d
z
0 1 view / d d
1
Perspective Distortion
screen
y
yview
yclip
-z
1
yclip
yview
zview
zview
xview
z
view
1
xview xview
yview
1
y
y
view
zview
view
zview zview
z
1 0 1
view
zview
1
Distorted z-Values
z1
z2
-z
if z1 > z2 then
- – /z1 > - – /z2
1/-z curve
- – /z1
- – /z2
-
- – /z
yclip
yview
zview
xview
z
view
1
xview xview
yview
1
y
y
view
zview
view
zview zview
z
1 0 1
view
zview
1
Normalized Perspective Distortion
y
y
(-1,1,1)
1
z
z
(0,0,-far)
y
x
-1
x
-1
x
1
1
2 near
right left
z
-1
2 near
top bottom
right left
right left
top bottom
top bottom
far near
far near
1
2 far near
far near
0
Hierarchical Z-Buffer
framebuffer
• 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 displaying
front-to-back
-.2
-.3
-.4
-.5
-.6
-.7
-.8
-far
-.3
-.5
-.5
-far
-.7
-far
-far
hierarchical zbuffer