The Hidden/Visible Object Problem
by William Shoaff with lots of help
- Hidden Object Algorithm Basics
- Back-face Culling
- Floating Horizon Algorithm
- z-Buffer Algorithm
- Scan-line Algorithm
- Painter's Algorithm
- Binary Space-Partition Trees
- Warnock's Algorithm
- Hidden object algorithms involve (explicit or implicit) depth sorting
(depth priority)
- Coherence - the tendency of characteristics in a scene to be
locally constant can be used to increase the efficiency of hidden object
algorithms
- span coherence -- scan lines contain runs of constant intensity
- scan-line coherence -- patterns are similar from scan line to scan line
- edge coherence -- edge changes visibility only where it crosses
a visible edge or penetrates a face
- depth coherence -- adjacent parts on the same surface are
typically close in depth
- frame coherence -- scenes are similar from frame to frame
- Some hidden object algorithms are object space algorithms that
work in floating point world coordinates
- Object space algorithms are called continuous;
they perform visibility determination over continuous areas giving
precise results
- Images can be enlarged without recomputation
- Useful in precise engineering applications
- A general rule-of-thumb is that object space algorithms are O(n2) where n is the number of objects in the scene
- Complexity of algorithms is high, few primitives are supported,
and special effects often are difficult to implement
- Hidden-line algorithms are often implemented in object space
- Some hidden object algorithms are image space algorithms that
work in integer device coordinates
- Image space algorithms are called point sampling;
they perform visibility determination over discrete areas giving
crude results
- Enlarged scenes are unacceptable
- A general rule-of-thumb is that image space algorithms are O(nN) where n is the number of objects in the scene and N is the number
of pixels
- Allow more advanced effects and complex models
- Many hidden-surface algorithms are implemented in image space
- List-priority algorithms are partially implemented in both coordinate
systems
- If the inner product
,
then the polygon's visible face can not be seen by the viewer
- If the scene is in eye coordinates,
so that
,
then the polygon's visible face can not be seen by the viewer
if the z component Nz of the surface normal is greater than or equal
to zero
- Consider the example
- Let
define a triangle
- Newell's method gives a normal with components
- If
,
then the face is visible
- If
,
then the face is not visible
- Note backface culling can not be used for open solids
- About a 50% savings in computation is expected by backface culling
- The visible surface problem can be formulated as:
- Given --
- A set of surfaces in three dimensions
- A viewpoint
- An oriented image (view) plane
- A field of view
- For each point on the image plane within the field of view
determine which point on which surface lies closest to the viewpoint
along a line from the viewpoint through the point in the image plane
- Useful for rendering a mathematically defined surface
- The algorithm can be implemented in object space (with a rootfinding
algorithm, which may be expensive,) or in image space (where
aliasing may occur).
- Given a surface represented in the implicit form
F(x,y,z) = 0
- Surface is represented by curves drawn on it, say curves of constant
height z=c for multiple values of c
- Convert the 3D problem to 2D by intersecting the surface with
a series of cutting planes at constant values of z
- The function
is reduced to a curve in each of
these parallel planes,
where z is constant for each of the planes
Pseudocode for floating horizon
- The surface may dip below the closest horizon and the bottom of
the surface should be visible
- Keep two horizon arrays, one that floats up and one that floats down
- In image space, aliasing can occur when curves cross previously drawn curves
- Example:
- Let curves at z=0, z=1 and z=2 be defined by
y= 10,
respectively
- Set
h[0..40] = 0 and for
compute the value of y
saving higher y and drawing the curves
It is useful to consider the structure of the four most widely used
point sampling hidden surface algorithms [1].
- 1.
- Pseudocode for z-buffer
- 2.
- Pseudocode for ray casting
- 3.
- Pseudocode for scanline
- 4.
- Pseudocode for painter's
The z-buffer and ray casting algorithm differ only in the order of their main loops.
The z-buffer algorithm handles objects one at a time and operates on all
covered pixels, the ray casting algorithm handles one pixel at a time and
compares every object's depth at a pixel.
All point sampling algorithms can produce aliasing artifacts since they may
miss important data in the pixels they sample. There are anti-aliasing
techniques that can be used to mitigate these problems.
Another factor in choosing a hidden surface algorithm is its support for
other rendering effects such as transparency. Ray casting, scanline and the
painter's algorithm all handle transparency well since all of the coverage
information is known, however, due to the processing loops in the depth
buffer algorithm it is harder to incorporate transparency.
- An image space, point-sampling method
- Polygons are tested one at a time
- At each pixel position on the view plane, the polygon with the closest
z coordinate is visible
- Requires two buffers
- A frame (refresh) buffer that store intensities
- A z (depth) buffer stores z values for each pixel
Given:
- a list of polygons
;
- An array zbuffer[maxX,maxY] initialized to
;
- An array framebuffer[maxX,maxY] initialized to background color;
Here's a more complete pseudocode for z-buffer
- For each pixel position
initialize depth buffer
- For each pixel position
initialize frame buffer
- For each pixel in polygon's projection calculate its z value at (n,m)
- If
,
then
where I is the intensity of the polygon at position
- Let
Ax+By+Cz+D=0 be polygon's plane equation
- The depth is
- Depth at next pixel
on scan line y is
- Depth at next scan line
is
- The z-buffer algorithm does not require objects to be polygons
(all we need to be able to determine is a shade and a z value)
- The z-buffer algorithm performs a radix sort in x and y, requiring
no comparisons
- The z sort takes one comparison per pixel for each polygon containing
the pixel
- The z-buffer algorithm requires a large amount of space
The ray casting algorithm is a precursor to ray tracing.
Pseudocode for ray casting
- An image space, point-sampling method
- For each scan line, all polygon surfaces intersecting the scan line are
examined to determine which is visible at each pixel along the scan line
- Extension of polygon scan-conversion filling algorithm
- Uses scan-line coherence and edge coherence
- Extend node used in scan-line filling to include ID of polygon being
filled
- Also require a polygon table that contains
- Polygon's ID
- Coefficient of the plane equation
- Shading or color information
- In-out boolean flag, initialize to FALSE
- Sort surfaces in order of decreasing depth (in object space)
- Scan-convert surfaces in order, starting with surface of greatest depth
- Sort polygons according to largest z value
- If surface of greatest depth does not overlap any other surface
(in z) scan-convert it and proceed to polygon of next greatest depth
- If overlap in z
- Do the two polygons overlap in x?
- Do the two polygons overlap in y?
- Is greatest depth polygon entirely on far side of other polygon's
plane?
- Is nearer polygon entirely on near side of deeper polygon's plane?
- Do the projections of the polygons onto the
plane not overlap?
- If all five tests fail, we ask if nearer plane can be scan-converted
before farther plane
- Questions 1, 2, and 5 do not need to be asked again
- Replace question 3 with:
is nearer polygon entirely on far side of farther polygon's plane?
- Replace question 4 with:
Is farther polygon entirely on near side of nearer polygon's plane?
- If either of these two tests succeed, move nearer polygon to the end of
the list and it becomes the new farthest polygon to test
- If all tests fail, split either the farther or nearer polygon by the
plane of the other, discard the old polygon and put its pieces in order on
the list
- Possible to have infinite loops when nearer polygons are cyclically
moved to end of the list
- Build a binary tree (BSP-tree) that determines the correct order (back-to-front)
to scan convert polygons from any view point
- Pick any polygon to be displayed as the root of the tree
- Partition space into the front half-space containing all polygons
in front of the root polygon (relative to its surface normal) and
the back half-space containing all polygons behind the root
polygon
- Recursively repeat the space partitioning until each node contains a
single polygon
- Polygons may need to be split in two by the plane of a root polygon
- To display the scene, from the current viewpoint, use modified in-order
tree traversal
- If the viewer is in the roots front half-space,
visit the sub-tree in the back half-space, and vice versa
Pseudocode for Building BSP tree
Pseudocode for Displaying BSP tree
- Object/Image space, continuous algorithm
- Uses area coherence
- If easy to decide what polygons are visible in an area, display them
- Otherwise, divide the area into smaller areas
- Given an area of interest, classify polygons to be displayed as
- Surrounding completely containing the area
- Intersecting intersecting the area
- Containing completely inside the area
- Disjoint completely outside the area
- Disjoint polygons can be eliminated from consideration
- Intersecting polygons can be split into disjoint and containing polygons
- If all polygons are disjoint from the area, display the background
color
- There is only one containing polygon (perhaps derived from an
intersecting polygon), fill area with background, then scan
convert containing polygon
- There is a single surrounding polygon, and no intersecting or
containing polygons, display the surrounding polygon's color
in the area
- There is a surrounding polygon in front of all other polygons,
display the surrounding polygon's color in the area
- A surrounding polygon can be determined to be in front by computing
the z coordinates of the surrounding, intersecting, and containing
polygons at the four corners of the area
- If we can not determine how to display the area, subdivide it into
four sub-rectangles and repeat the process
- We can stop subdividing when the resolution of the display is reached
and display the polygon with closest z value at the pixel (if none
of the four cases have occurred)
- Alternatively, for antialiasing, we can subdivide further and use
a color weighting
- Except when none of the four cases occur, the algorithm can be
implemented in object space
- Jim Blinn -- CG&A (January 1990, Vol 10, No. 1, pp 70 - 75)
describes an efficient triage table for maintaining the
lists of polygons
- 1.
- What is back-face culling?
- 2.
- How is testing for a back-face done?
- 3.
- Let
3x-2y+6z-5=0 be the equation of a plane viewed from
eye position
,
while looking at the point
.
Is the front of the plane visible?
- 4.
- What is the difference between an image space and an object space
hidden surface algorithm?
- 5.
- What is coherence?
- 6.
- Let curves at z=0, z=1 and z=2 be defined by
and
y= 300,
Show how the floating horizon algorithm would draw the surface.
- 7.
- Describe the basic flow of control for the z-buffer algorithm.
- 8.
- What incremental technique can be used in the z-buffer algorithm?
- 9.
- Suppose you are given a
frame buffer and z buffer
initialized as shown to the background color and the far value of z.
Show the contents of both the frame buffer and the z buffer after
processing polygons P1, P2 where
Here the notation
at each pixel indicates the z depth
and the intensity of the polygon at the pixel.
- 10.
- What is the basic concept of the Painter's algorithm?
- 11.
- What is an important advantage of a binary space partition tree?
- 12.
- Show how to construct a binary space-partition tree from the
polygons displayed below starting with polygon A as the root.
Note the polygons are displayed as line
segments (think of viewing them on their edges) with an arrow
indicating the front side of the polygon. Clearly explain how your
tree is built.
- 13.
- What are the basic tests in Warnock's algorithm?
- 1
-
K. JOY, C. GRANT, N. MAX, AND L. HATFIELD, Computer Graphics: Image
Synthesis, IEEE Computer Society, 1989.
William Shoaff
2000-11-20