Re: Scenes with lots of simple objects

Edward Hoffmeister ([email protected])
Tue, 7 Mar 1995 22:08:00 -0500 (EST)


On Tue, 7 Mar 1995, Gavin Bell wrote:
> On Feb 28, 9:04am, Scott Nelson wrote:
> > I'd appreciate any feedback on the following:
> >
> > I have a 50x50x50 block of cubes. This takes several minutes to

1. if there is no space between the cubes try drawing only the 50 by 50
cubes on each "FACE" of the cube of cubes. (this would speed you up by
NOT drawing 48 x 48 x 48 cubes, which is most of the work.) if there IS
space between the cubes, sorry you can't optimize by that method, as you
would be missing what is visable between them.

. . .
>
> I think it makes more sense to define new kinds of shapes that know how to
> render large numbers of simple primitives, and that know how to optimize the
> rendering. For example, a CubeSet could store the cubes in a spacial data
> structure, figure out where the eyepoint is relative to the cubes, draw them
> back to front, and (if it was really smart) avoid drawing invisible cubes.
>
if a Z-buffer is implemented AND the cubes are sorted FRONT to back, then
the front surface of the closest cube will be drawn and all of the cubes
that are "behind" those pixels will test as the z-values are further, so
they will fail the test of "should the pixel be drawn", which will avoid
drawing (which is an time consuming operation on most hardware.), and
will give the most significant speed up to those people with the slowest
drawing hardware. (which is most "bargain video cards") accelerated video
cards, may see a speed up, but the gain will be reduced, since the pixel
drawing routines are not as time consuming.

z-buffering algorithm outline (not perfect, but it'll give people the idea.)
1. perform the perspective or other transforms needed to get the polygon
into screen co-ordinates. (but KEEP the transformed z-value).

2. perform a scan-line painting algorithm, except carry the z-values
along, and also interpolate the z-value along the edges, AND between the
endponts of each line segment "to be drawn". HOWEVER for each pixel that
is "supposed to be drawn" check the z-buffers value at the coordinates of
where the pixel would be drawn, IF closer, THEN draw the pixel, and
replace the z-buffers value with the z-value of the pixel just drawn,
ELSE do nothing. (current pixel is then behind a pixel already drawn.)

example: (screen co-ordinates (x,y), and z-value = "a")
if (z_buff[x][y] < a) (* "<" is a test for closer, use what you need*)
{ z_buff[x][y] = a; draw(x,y, COLOR ) }
(* else do nothing *)