Title: Hidden Surface Elimination
1Hidden Surface Elimination
Visible Surface Determination
2Approaches
- Back-Face Removal
- z-Buffer (Depth-Buffer)
- Scanline Algorithm
- Depth-Sort
- BSP-Tree
3Back-Face Removal (Culling)
- Used to remove unseen polygons from convex,
closed polyhedron (Cube, Sphere) - Does not completely solve hidden surface problem
since one polyhedron may obscure another
4Back Face Algorithm
- Before the Viewing Transformation
- 1. List the vertices for each polygon
counter-clockwise - with respect to the front face.
- P1, P2, P3, P4
- P5, P8, P7, P6
- 2. Compute the equation of the plane for each
polygon such that the normal vector points out of
the front face. - 3. If A eyex B eyey C eyez D polygon is a backface.
- The transform T(-PRP)RT(-VRP) takes the PRP to
the origin. - Therefore, the inverse will take the origin to
PRP (the eye) - (T(-PRP)RT(-VRP))-10,0,0,1 (eyex, eyey,
eyez, 1) - After the Perspective Projection
- 1. Look at the z-coordinate of the Normal vector
5z- Buffer (Depth-Buffer)
- Z-Buffer has memory corresponding to each pixel
location. - Usually 16 to 20 bits/location.
- Initialize
- Each z-buffer location ? Max z value
- Each frame buffer location ? background
color - For each polygon
- Compute z(x,y), polygon depth at the pixel
(x,y) - If z(x,y)
- z buffer(x,y) ? z(x,y)
- pixel(x,y) ? color of polygon at (x,y)
6z-Buffer (cont.)
- Advantages/Disadvantages
- LOTS of memory
- Modifications needed to implement antialiasing,
transparency, translucency effects - Linear performance
- Polygons may be processed in any order
- Commonly implemented in firmware/hardware ? very
fast.
7What z????
- Z-buffer is done after the perspective
transformation since two different points in
3-space may map to the same pixel. - Example (100, 100, 100) and (200, 200, 200)
with d 10 both map to pixel (10, 10). - In deriving the perspective transformation we
assumed either z 0 or zd! - We need a z-value that preserves the depth
relationship between objects after the
perspective transformation. - If A is in front of B, the projected_A should be
in front of projected_B. - Transforming points on a straight line should
result in co-linear points. - Transforming coplanar points in a polygon should
not warp the polygon.
8Old Value of z will not work
- We need a projection that takes the z-coordinate
into a projected z-coordinate space
that maintains lines and planes.
9Scaling Z
10Scaling Z (cont.)
- -1 ? x ? 1, -1 ? y ? 1, -1 ? z ? 0
(x, y, (z -zmin) /( 1 zmin), -z) Projected
3-D Point is ( x/(-z), y/(-z), (z -zmin )
/ (-z)( 1 zmin) )
11Computing Pixel z-values
The perspective projection gives you z-values for
the vertices of polygons. To find the z-values
for the boundary and interior pixels you do a
linear interpolation.
- When moving vertically zi1 zi ?zv, ? zv
(z1-z3)/(y1-y3) - When moving horizontally zi1 zi ? zh, ? zh
(z1-z3)/(x1-x3) - This could also be done by using the equation of
the plane that transformed polygon lies in, but
first you have to compute the equation of the
plane. (The old one will not do!)
12Scan Line Algorithm
- Idea is to intersect each polygon with a
particular scanline. Solve hidden surface
problem for just that scan line. - Requires a depth buffer equal to only one scan
line - Maintain an active polygon and active edge list
- Can implement antialiasing as part of the
algorithm
13BSP Trees
- Binary Space Paritition is a relatively easy way
to sort the polygons relative to the eyepoint - To Build a BSP Tree
- 1. Choose a polygon, T, and compute the equation
of the plane it defines. - 2. Test all the vertices of all the other
polygons to determine if they are in front of,
behind, or in the same plane as T. If the plane
intersects a polygon, divide the polygon at the
plane. - 3. Polygons are placed into a binary search tree
with T as the root. - 4. Call the procedure recursively on the left
and right subtree.
14BSP Tree Example
15Traversing the BSP-Tree
- Traverse the BSP tree such that the branch
descended first is the side that is away from the
eyepoint. This can be determined by substituting
the eye point into the plane equation for the
polygon at the root. - When there is no first branch to descend, or that
branch has been completed then render the polygon
at this node. - After the current node's polygon has been
rendered, descend the branch that is closer to
the eyepoint.
16Traversing the BSP Tree Example
EYE 1
A
F2
C
B
Z
D
F1
D
E1
C
F1
E2
F2
E2
A
E1
B
X
-X
EYE 2
17Splitting Triangles
If all our polygons are triangles then we always
divide a triangle into more triangles when it is
intersected by the plane.
- It is possible for the number of triangles to
increase exponentially but in practice it is
found that the increase may be as small as two
fold. - A heuristic to help minimize the number of
fractures is to enter the triangles into the
tree in order from largest to smallest.