Paper Assignment 2
In reading “Ten Hidden-Surface Algorithms,” two algorithms
that interested me are Roberts’s volume
solution and Warnock’s area sampling method. In this page, I will
ponder the algorithms’ implementations,
advantages and disadvantages, and compare and contrast them with each other
and with the Z-buffer (brute
force) method.
Roberts's Hidden Line Elimination
Lawrence G. Roberts's algorithm (described in his thesis)
was the "first known solution to the hidden-
line problem" (Sutherland, p.19), and of those mentioned in Sutherland's
article, it is the most intuitive
mathematically I think. Most ideally, the algorithm tests whether
a line between the viewpoint and any
point on along an edge is intersected by a volume described by its enclosing
planes.
We'll first look at my take on the mathematics of the
method. First, think of a point's relation to
a plane in 3-space whose equation is given by Ax + By + Cz + D = 0.
The first three terms are a dot
product of the point (as a vector) with the normal to the plane (the vector
<A B C>). Since a dot product
of two vectors is related to one's projection on the other, it is reasonable
that if the point is on the side of
the plane pointed to by the normal, this dot product will be positive,
and negative if the point is on the
opposite side. Thus, if we arranged that the normals of a group of
planes enclosing a volume all point
outside the volume, then dotting a point's position vector with all of
the resulting normals would tell us
if the point is outside or inside the volume (or on the surface, if all
results are zeros). This is at the heart
of Robert's method.
We want to decide what parts of an edge (if any) are
occluded from the viewpoint's perspective. This
will occur exactly where the line of slight between the viewpoint and the
edge is disrupted by an interlying
object. Robert's algorithm parameterizes this line of slight for
all points along the edge :
P = (1-a)*E1 + a*E2 + b*<0 0 -1 1>
where the first two terms are a parameterized point along the edge (with
endpoints E1 and E2), and the
third term is a vector in the direction of the viewpoint. Then, for
any object defined by enclosing planes,
if
P.F(i) < 0 for all faces i of the the object
for some P, the P's corresponding point on the edge is hidden by the object.
This system of equations is
solved for all edges, for all objects not trivially irrelevant--those whose
bounding boxes do not overlap
that of the edge. This edge/object test may discover that zero, one,
or two portions of the edge are left
unobscured by the object. These portions "are then tested against
the remaining objects" (p.20).
I have two initial issues with what I know of Roberts's
implementation. First, both Sutherland and
Roberts describe the algorithm running in the perspective space (after
the transformation into the
canonical viewing volume). That's why the term of P is <0 0 -1
1>. However, nothing about the method
insists on perspective space. In fact, line of slight is disrupted
in the perspective space exactly when it
is disrupted in the regular space. (Many of the method's specifics
may be owing to convenience in
Roberts's research, as it is just a small part of his paper). Secondly,
the exhaustive test occurs once
per frame. In that this is an object-space algorithm (and thus can
be performed to arbitrary precision),
I see these two issues coming together, with inspiration from Andrew Wilson's
PhD work. What if we
were to precompute the hidden edge method at sample points in the environment,
and at very high
precision? Then, during the rendering, we could decide what few obscurities
need to be calculated
more precisely. This could take advantage of frame coherency and
would be neat.
Sutherland made comparisons of different algorithms'
complexities, including those of Roberts and
the Z-buffer. Like most, the Roberts method is cheaper than the Z-buffer.
However, it suffers a
number of setbacks to it's usefulness. Firstly, "the algorithm severely
restricts the environment: the
volume test requires that objects be convex," which is a difficult comdition
to satisfy in an environment
not so specifically designed (p.20). This restriction can be seen
by imagining two normals to planes of
an object that are parallel but in opposite direction. Then, if a
point is negative compared to one
(indicating that the point is inside the object), it is positive when dotted
with the other normal. Another
setback to the Roberts algorithm (according to Sutherland) is that its
cost grows with the square or
worse of the increasing complexity of the environment. For example,
with every obscuration, two new
edge portions may arise that in turn must be processed with the remaining
objects (as above).
However, a recent attempt by David Rogers to employ some common shortcuts
to Roberts algorithm
have shown that the growth is really limited to complexity n to the power
1.15 (see here).
Implementing Roberts's algorithm would be interesting
to try to do effieciently. For efficient cache
use, I would create simplified structures for each object for the hidden
line solving, for example parred
down to just bounding box and normal information. I would do the
solving for a specific edge to the
precision necessary after calculating how many pixels are affected by that
edge's computations. (The
hope there would be that if an edge is very small on the image space, discretizing
the steps along the
parameterized edge would save some of the computational load of least square
linear system solving.)
I may also try to implement the pre-processing step described above to
take advantage of frame
coherency.
Warnock's Area Sampling
J.E. Warnock's algorithm hypothesizes that sample elements
in the image space can displayed
after a single shade calculation if either no faces fall within the sample
element, or one face covers
the entire element (p. 30). These are called the homogeneous conditions.
If neither condition is true,
the element is divided into four smaller elements that are separately tested.
This goes on until the
size of the element is a pixel. In fact the element size can be even
less, if averaging is desired to
create a very correct, and ugly, aliased image. For the faces that
are not eliminated by bounding box
tests, each one of the group is tested to the element (or window) "to see
whether the face 1)
surrounds the winder; 2) intersects the window, or 3) is completely disjoint
from the window" (p.30).
As would be expected, information regarding the applicability of the faces
to a window is inherited
when the window is subdivided. If, upon completion of the face testing,
surrounding faces have been
found for the window, the algorithm searches among them for the one nearest
the viewpoint. This
involves computations of the face depths at the four corners of the window.
Then these depths are
compared to those of all the intersecting (and not surrounding) faces.
If the closest surrounder is
closer than any intersector, then the window is a homogeneous case, otherwise
there is more
subdivision (as there is if there is no clear-cut surrounder).
The major issue to the Warnock algorithm is that it's
output is not convenient for the raster scan
displays. The length of time the method spends on a particular area
of the screen space varies wildly
for the scene, so that different parts of the window are ready at different
times. This is like the
object-space algorithms (like Roberts's), where the frame is not prepared
in order, but is unusual
for the screen-space methods.
In Sutherland's comparisons of this algorithm to others,
Warnock fares well. However, for very
complex environments, I think it basically becomes a Z-buffer. I
would approximate Warnock's as a
analogous to an LZ compressed Z-buffer. In other words, over swaths
of the screen only one face is
being drawn, so don't think about it per pixel. However, on more
complicated parts of the screen,
you end up having to bubble up the nearest Z value for every pixel anyway,
and in the Z-buffer, you
wouldn't have had to do 4 depths per window anyway (though this depends
on the window element
size). Sutherland's charts in the article do not agree with this
assessment for very complex
environments, but I am not sure what was involved in his complex environments.
In the end though,
from a hardware standpoint, the fastest thing is most often the algorithm
that is independent of the
current image being rendered. So where Warnock would be fast, Z-buffer
would be okay, and where
Warnock would be slow, Z-buffer would be okay. Sounds like a clear
winner.
I would like to implement Warnock's algorithm because
I see no reason for it to work too badly
in most environments. It would be interesting to code the different
conditions for a particular
window, like surrounding, etc. It also seems like part of the algorithm
may be implementable in
object space, albeit the fast part. Imagine a powerplant walkthrough.
You're in the middle of the
plant, where a low face-count wall separates the viewpoint and a dense
and (in the end) not visible mass
of pipes. Without going into talking about volume cells and linear
separability of objects and casting
shadows (and other things I don't quite grasp yet), both the Z-buffer
and Warnock algorithms
would have a fit over this view, if it were pushed through the hidden surface
algorithm. Why even
transform all those polygons behind the wall into screen coordinates, only
to do an ugly Z-buffer type
search for the nearest, only to find it's same nearest as a lot of other
pixels? It seems like there
may be a way to cull some volumes in the object space, so that they're
not propagated for any longer
than necessary. With good object information, this might be feasible.
For example, you could cast
a few rays into the environment. If you hit the same object over
a decent angular distance in rays,
you could search with small bounding volumes between this large object
and the viewpoint for
obscuring objects that would make this computation less useful. But
still you could cast a shadow,
and cull out via bounding boxes, objects that are behind the large object
you found. This would speed
up the Warnock slow case. But then, in that it would also speed up
the Z-buffer, it probably wouldn't
make a difference. I'm not even sure if it would really be an improvement
upon Warnock's, because
it seems generally applicable.
Conclusion
In that we are comparing an object-space algorithm to
an image-space one, it is expected that
Warnock's method would be faster than Roberts's. Indeed, a little
thought shows that the two
methods are doing exactly the same thing, but Roberts does this to a higher
precision that is not
taken advantage of in the output medium. Basically, in Warnock's
algorithm, the rays from a point
along an edge to the viewpoint are implied rather than specifically computed
for as in Roberts's
method. Rather than calculating the intersections with all objects
for all rays from all edges to the
viewpoint as in Roberts, Warnock effectively performs a depth search--finding
the nearest obscuring
surface--along only a constant number of rays per pixel of the final image.
Functionally the
intersection (obscuration) calculation occurs in the projection onto the
image space--all objects along
a ray or line-of-sight, that are thus obscuring one another, project to
the same pixel in the image.
Thus, there is not the added cost of precisely computing of the intersections
of these rays with
interlying objects, as is the case with Roberts's algorithm. In the
end it seems, the computational
load of linear system solving to avoid unecessary projections (projecting
a hidden edge onto the
screen) is greater than first projecting everything onto the image space
and then deciding on the
relevant face. (A Fermi solution could be: The Roberts hard
case [solving for a and b above] is at
least n squared arithmetic operations. But projection [applying
a matrix] is at most n squared, and
when followed by a bubble of a number of items equal on average to the
depth complexity [which
would would be an additional constant time], the Warnock algorithm appears
advantageous).