Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Other names:
Visible-surface detection
Hidden-surface elimination
Painters Algorithm
Object-space algorithm
Draw surfaces from back (farthest away) to front (closest):
Sort surfaces/polygons by their depth (z value)
Draw objects in order (farthest to closest)
Closer objects paint over the top of farther away objects
Problems:
overlapping polygons
x
z
6
Algorithm:
Sort objects by their minimum z value (farthest from
the viewer)
Resolve any ambiguities caused by overlapping
polygons, splitting polygons if necessary
Scan convert polygons in ascending order of their z
values (back to front)
7
Depth-Sort Algorithm
Depth-Sort Algorithm
x
Test 3 succeeds:
P
z
x
P
Q
9
Depth-Sort Algorithm
If all 5 tests fail, assume that P obscures Q,
reverse their roles, and repeat steps 3 and 4
If these tests also fail, one of the polygons
must be split into multiple polygons and the
tests run again.
10
Z-Buffering
Z-Buffering
Visible Surface Determination Algorithm:
Determine which object is visible at each pixel.
Order of polygons is not critical.
Works for dynamic scenes.
Basic idea:
Rasterize (scan-convert) each polygon, one at a time
Keep track of a z value at each pixel
Interpolate z value of vertices during rasterization.
Example
Z-buffering
Need to maintain:
Frame buffer
contains colour values for each pixel
Z-buffer
contains the current value of z for each pixel
14
Z-Buffering: Algorithm
allocate z-buffer;
Z-Buffering: Example
Scan convert the following two polygons.
The number inside the pixel represents its z-value.
-1
-1
(0,3)
-3 -2
-2 -3
-5 -4 -3
-3 -4 -5
-7 -6 -5 -4
-4 -5 -6 -7
(0,0)
(0,0)
(3,0)
(3,0)
(3,3)
Z-Buffering: Example
- - - -
- - - -
- - - -
-1
- - - -
-1
-2 -3
-3 -4 -5
-2
- -3
- - -
-3
- -4
- -5
- -
-1
-3 -2
-5 -4 -3
- - - -
-4 -5 -6 -7
-4
- -5
- -6
- -7
-
- - - -
-1
- - - -1
-
-1
- - - -
-3 -2
- - -3
- -2
-
-2 -3
- - - -
- - - -
-5 -4 -3
-7 -6 -5 -4
-3
- -5
- -4
- -
-7
- -6
- -5
- -4
-
17
-7 -6 -5 -4
-3 -4 -5
-4 -5 -6 -7
-1 - - -
-1
-
-2 -
-3 -
-3 -
-2
-
= -3 -4 -4 -3
- -5
- - -
-4 -6
-5 -
-5 -
-4
-7
-
-
-1 - - -
-1
-
-2 -
-3 -
-3 -
-2
-
-3 -5
-4 -
-4 -
-3
-
-
-4 -6
-5 -
-5 -
-4
-7
-
-
Z-Buffering: Computing Z
How do you compute the z value at a given pixel?
Interpolate between vertices
z1
y1
za
ys
y2
y3
z a z1 ( z 2 - z1 )
y1 - ys
y1 - y2
zb z1 ( z3 - z1 )
y1 - ys
y1 - y3
z s zb ( z a - zb )
xb - xs
xb - xa
zb
zs
z2
z3
Z-buffer Implementation
Modify the 2D polygon algorithm slightly.
When projected onto the screen 3D polygons look like
2D polygons (dont sweat the projection, yet).
x @ ymin
1/m
With Z-buffering:
ymax
x @ ymin
1/m
20
z @ymin
vertZ
Vertical Z
Increment
z1 - z0
vertZ
y1 - y0
21
Horizontal Z Increment
We can also compute a horizontalZ increment
for the x direction.
As we move horizontally between pixels, we
increment z by horizontalZ.
Given the current z values of the two edges of
a span, horizontalZ is given by
zb - z a
horizontalZ
xb - xa
22
8
7
6
5
4
3
edge a
edge b
1
0
0
23
x@
current y
1/m
With Z-buffering:
ymax
x@
current y
1/m
vertZ
z@
current x,y
Z-Buffering : Recap
Create a z-buffer which is the same size as the
frame-buffer.
Initialize frame-buffer to background.
Initialize z-buffer to far plane.
Scan convert polygons one at a time, just as before.
Maintain z-increment values in the edge tables.
At each pixel, compare the current z-value to the
value stored in the z-buffer at the pixel location.
If the current z-value is greater
Color the pixel the color for this point in the polygon.
Update the z-buffer.
25
Z-Buffering : Summary
Advantages:
Easy to implement
Fast with hardware support Fast depth buffer memory
On most hardware
No sorting of objects
Shadows are easy
Disadvantages:
Extra memory required for z-buffer:
Integer depth values
Scan-line algorithm
Prone to aliasing
Super-sampling
26
27
Cutting Triangles
If triangle intersects plane Split
Plane
a
a
A
t1
t3
t2
t1 =(a, b, A)
t2 = (b, B, A)
t3 = (A, B, c)
minus.add(t1)
a
minus.add(t2)
Add t3 to positive subtree:
plus.add(t3)
Plane
t1
t3
t2
B
b
t1 =(a, b, A)
t2 = (b, B, A)
t3 = (A, B, c)
29
A
c
(n a ) D
tn (c - a )
Repeat for B
30
b
a
a
c
plane
plane
if (fa * fc 0)
a->c; c->b; b->a;
else if (fb * fc 0)
a->c; c->b; b->a;
c
b
Z-Buffering
Image precision algorithm:
Determine which object is visible at each pixel
Order of polygons not critical
Works for dynamic scenes
Takes more memory
Basic idea:
Rasterize (scan-convert) each polygon
Keep track of a z value at each pixel
Interpolate z value of polygon vertices during
rasterization
34
Warnocks Algorithm
An area-subdivision technique
Idea: