real time discrete shading

12
16 Real time discrete shading* Daniel Cohen 1, Arie Kaufman 1, Reuven Bakalash 1 ** and Samuel Bergman 2 1 Department of Computer Science, State University of New York, Stony Brook, NY 11794-4400, USA 2 Department of Mathematics and Computer Science, Ben Gurion University, Beer Sheva 84120, Israel A shading technique for voxel-based im- ages, termed congradient shading, is pre- sented. As the surface information is not available in voxel representation, the sur- face normal must be recovered from the 3 D discrete voxel map itself. The technique defines the normal as one of a finite set of neighborhood-estimated gradients and can thus employ precalculated look-up tables. Furthermore, a table-driven mechanism permits changing the light source parame- ters by merely redefining the look-up table. The technique uses only simple arithmetic operations and is thus suitable for hard- ware implementation. Since it has been im- plemented not as a post-processor, but as part of the projection pipeline of the cube architecture, congradient shading can be executed in real time. Two versions of the technique have been conceived and imple- mented: unidirectional shading, in which the gradient is estimated only from neigh- borhoods along the scan-lines; bidirection- al shading, in which both horizontal and vertical components of the gradient are considered. In spite of the simplicity of the technique, the results are practically indis- tinguishable from images generated by conventional techniques. Key words: Shading technique - Congra- dient shading - Voxel - Cube architecture * This work was supported by the National Science Foundation under grants DCR 8603603, CCR 8743478, CCR 8717016, and MIP 8805130 ** Also with the Department of Computer Science, Hofstra University, Hernpstead, NY 11500, USA 1 Introduction Volumetric objects, in applications such as medical imaging, 3 D image processing, solid modeling, 3 D simulation, and 3 D scientific visualization, are of- ten stored as a large 3 D matrix of unit volume cells, or voxets. Producing a display of a 3 D voxel object on a 2D screen entails rendering the 2D projection in order to form the appearance of a real object in three dimensions. Shading is a ren- dering technique that provides critical depth cues. Shading of 3 D discrete voxel objects is the subject of this work and is referred to as discrete shading, as opposed to conventional shading, which as- sumes a continuous geometric or parametric repre- sentation. In conventional shading the surface nor- mals are available, while in discrete shading the normal at each point must be recovered from the 3 D voxel map. Two primary goals are set up for discrete shading. One is to provide optimal visual recognition or discernment of the displayed objects. The projec- tions of objects with uniform surface coloring are merely silhouettes of those objects, and their fea- tures cannot be discerned without shading. For ex- ample, a sphere projects as a flat disk, and a cube projects as a rectangle or a hexagon. Shading is then necessary for visual recognition. The other goal is to provide the natural appearance of a real object. Due to the discreteness of individual cubic voxels in a voxel representation, projections have a checkerboard appearance with sharp, artificial discontinuities. Discrete shading should provide the pleasing illusion of a real, "smooth" object, while retaining the minute details of the original object. To date, the discrete shading process is one of the bottlenecks in voxel-based software and hardware systems. It is commonly configured as a post-pro- cessor of the display pipeline and requires the full projection color buffer and depth buffer as input. The lack of a fast "real-time" shading technique degrades the utilization of voxel-based systems. This paper is concerned with a real-time discrete shading technique, called congradient shading, in which shading is performed at the pixel refresh rate. It provides rapid shading with visual discernment and a quality appearance that is practically indis- tinguishable from images generated by convention- al techniques. Congradient shading is based on a surface gradient approximation evaluated from the depths of the immediate neighborhood of each voxel, which then indexes into a pre-computed look-up table (LUT) of illumination values. A specific table represents The Visual Computer (1990)6:16 27 Springer-Verlag 1990

Upload: daniel-cohen

Post on 10-Jul-2016

217 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Real time discrete shading

16

Real time discrete shading* Daniel Cohen 1, Arie Kaufman 1, Reuven Bakalash 1 * *

and Samuel Bergman 2

1 Department of Computer Science, State University of New York, Stony Brook, NY 11794-4400, USA 2 Department of Mathematics and Computer Science, Ben Gurion University, Beer Sheva 84120, Israel

A shading technique for voxel-based im- ages, termed congradient shading, is pre- sented. As the surface information is not available in voxel representation, the sur- face normal must be recovered from the 3 D discrete voxel map itself. The technique defines the normal as one of a finite set of neighborhood-estimated gradients and can thus employ precalculated look-up tables. Furthermore, a table-driven mechanism permits changing the light source parame- ters by merely redefining the look-up table. The technique uses only simple arithmetic operations and is thus suitable for hard- ware implementation. Since it has been im- plemented not as a post-processor, but as part of the projection pipeline of the cube architecture, congradient shading can be executed in real time. Two versions of the technique have been conceived and imple- mented: unidirectional shading, in which the gradient is estimated only from neigh- borhoods along the scan-lines; bidirection- al shading, in which both horizontal and vertical components of the gradient are considered. In spite of the simplicity of the technique, the results are practically indis- tinguishable from images generated by conventional techniques.

Key words: Shading technique - Congra- dient shading - Voxel - Cube architecture

* This work was supported by the National Science Foundation under grants DCR 8603603, CCR 8743478, CCR 8717016, and MIP 8805130 ** Also with the Department of Computer Science, Hofstra University, Hernpstead, NY 11500, USA

1 Introduction

Volumetric objects, in applications such as medical imaging, 3 D image processing, solid modeling, 3 D simulation, and 3 D scientific visualization, are of- ten stored as a large 3 D matrix of unit volume cells, or voxets. Producing a display of a 3 D voxel object on a 2D screen entails rendering the 2D projection in order to form the appearance of a real object in three dimensions. Shading is a ren- dering technique that provides critical depth cues. Shading of 3 D discrete voxel objects is the subject of this work and is referred to as discrete shading, as opposed to conventional shading, which as- sumes a continuous geometric or parametric repre- sentation. In conventional shading the surface nor- mals are available, while in discrete shading the normal at each point must be recovered from the 3 D voxel map. Two primary goals are set up for discrete shading. One is to provide optimal visual recognition or discernment of the displayed objects. The projec- tions of objects with uniform surface coloring are merely silhouettes of those objects, and their fea- tures cannot be discerned without shading. For ex- ample, a sphere projects as a flat disk, and a cube projects as a rectangle or a hexagon. Shading is then necessary for visual recognition. The other goal is to provide the natural appearance of a real object. Due to the discreteness of individual cubic voxels in a voxel representation, projections have a checkerboard appearance with sharp, artificial discontinuities. Discrete shading should provide the pleasing illusion of a real, "smooth" object, while retaining the minute details of the original object. To date, the discrete shading process is one of the bottlenecks in voxel-based software and hardware systems. It is commonly configured as a post-pro- cessor of the display pipeline and requires the full projection color buffer and depth buffer as input. The lack of a fast "real-time" shading technique degrades the utilization of voxel-based systems. This paper is concerned with a real-time discrete shading technique, called congradient shading, in which shading is performed at the pixel refresh rate. It provides rapid shading with visual discernment and a quality appearance that is practically indis- tinguishable from images generated by convention- al techniques. Congradient shading is based on a surface gradient approximation evaluated from the depths of the immediate neighborhood of each voxel, which then indexes into a pre-computed look-up table (LUT) of illumination values. A specific table represents

The Visual Computer (1990) 6:16 27 �9 Springer-Verlag 1990

Page 2: Real time discrete shading

the particular position and characteristics of the light source. Moving or changing the light source merely requires altering or replacing the LUT. Different congradient shading techniques have been implemented as part of the Cube voxel-based architecture [-11], which is described briefly in Sec- tion 3. While the congradient shading operations may be performed in software, a simple hardware modification of the Cube architecture can execute congradient shading in real time with no time over- head.

2 Discrete shading techniques

In general, shading is defined as a function that computes the intensity value that reaches the viewer's eye from each point of the visible surfaces, taking into account the normal and the character- istics of the object's surfaces and the light sources [3]. In geometric objects composed of polygon meshes or mathematical surfaces, the normals are either calculated from the geometric information or stored as part of the surface representation. This paper, and discrete shading in general, is concerned with ways to shade the projection of 3 D objects represented as voxel maps. The objects' actual sur- faces and their normals are unknown and must be recovered from the voxel map structure. In voxel representation, each voxel is assumed to be a unit cube or a cuboid (rectangular parallelopiped). A voxel has six faces whose normals are in the direc- tions of the primary axes, and up to three faces may be visible from any given eye position. Utilizing the visible voxel faces as a polygon mesh with constant shading creates a displeasing checker- board effect of artificial edges, which is accentuated by the fact that the visible faces of the same voxel are orthogonal. However, a variation of this tech- nique used in earlier methods of discrete shading [2, 6] ameliorates the problem of artificial edges by de-emphasizing the dependency on the incident angle. Another simple technique suitable for voxel-space is distance-only (depth-only) shading [7, 16]. The color of a surface varies only as a function of the distance between the observer and the surface point. The shaded objects look smooth because neighboring voxels are about equidistant from the observer. Although this technique smoothes out any sampling noise, it suppresses the minute details that are essential in applications such as medical

imaging, and, more importantly, eliminates edges and object discontinuities that are essential to hu- man comprehension of the 3 D scene. Recently, improved discrete shading methods that overcome the lack of surface normal information in the voxel representation and attempt to resolve the problems caused by constant shading (artificial edges) and distance-only shading (loss of real edges) have been proposed. They are the gradient [5], contextual [2], gradient interpolation [1], and gray-level gradient [-8] methods. The first two methods are relevant to our work. Gradient shading, [-5] accepts a pixel image and its depth buffer as input. The depth buffer, which stores the distance of each visible voxel from the observer, is a result of a hidden-surface algorithm or a surface detection algorithm. The normal is estimated from the gradient vector (~z/Ox, Oz/ ay, - 1 ) at all points of the surface. The gradient value is obtained from the immediate discrete neighborhood of the point. The x derivative, for example, is estimated from either the forward (right), the backward (left), or the central differences of the depth values in the depth buffer of the two immediate neighbors of the center point along the x direction. The complexity of gradient shading is proportional to the pixel image size and is inde- pendent of the number of objects in the 3 D scene. A main drawback of this technique is that the shad- ing pattern artifacts vary as the objects are trans- formed. The normal-based contextual-shading technique [2] determines the normal and, thus, the shading of a face (of a voxel) not only by the orientation of that face, but also by the orientation of the adjoint faces that share edges with it. Each neighbor is assigned one of three possible orientation codes ( - 1, 0, 1) relative to the center face. The neighbors on the left and the right determine the nine possible horizontal gradients, resulting in a total of 81 possi- ble horizontal-vertical neighborhood arrange- ments, with only 25 distinct normal vector orienta- tions. The primary advantage of normal-based contextual shading is that the 25 possible shading values can be pre-computed and stored in an inten- sity LUT for fast retrieval. In spite of the coarse granularity of the normal vector, the quality of the contextual-shaded images is relatively impressive [2]. The main disadvantage of this technique, how- ever, is that in order to have a fast shading algo- rithm, an extra neighbor-code is stored for each voxel face of the boundary surface of the object.

17

Page 3: Real time discrete shading

The desire to deliver realistic images of 3 D volu- metric objects in real time or near-real time has prompted research and development of voxel- based architectures and special-purpose hardware. In all the reported voxel-based architectures, shad- ing is calculated in a final post-processor. The full- color and depth buffers are assumed as input to this post-processor. The distance-only technique used by GODPA [4] and the block (constant)- shading technique used by Insight [13] are suitable for hardware implementation, but have quality de- ficiencies. Goldwasser [4] postulates that gradient shading is a promising technique for medical appli- cations and has the capacity for hardware imple- mentation. Insight's surface-normal technique re- quires a large memory overhead to store the nor- mal for each voxel. The PARCUM [91, SCOPE [-15], and 3 DP 4 [14-1 gradient interpolation tech- niques provide smoother images, but are computa- tionally complex. Jackel [9] has suggested that the process can be transformed into an MIMD archi- tecture because of the independency of both col- umn and row in the distance matrix. Unlike these systems, the discrete congradient shading technique is implemented as an integral part of the projection process and does not require the full-color and depth maps as input. Moreover, since shading is performed while the image is being projected, there is no time overhead. The congra- dient technique is a variation of the gradient- and the contextual-shading techniques that employ small pre-computed illumination LUTs. The tech- nique, which is suitable for hardware realization, has been developed in the framework of the Cube architecture described briefly in the next section.

3 The Cube architecture

The Cube architecture [11] is a versatile voxel- based architecture for 3 D graphics. The essence of the architecture is that 3 D voxel objects are represented by a large 3 D cubic frame buffer (CFB) of voxels, each having a numerical value that char- acterizes its density, color, texture, translucency ra- tio, and the like. Cube is a multiprocessor system with three processors that access the CFB to input, manipulate, view and render the CFB images. The 3 D frame-buffer processor acts as a channel for in- putting 3 D scanned voxel images, which are the primary source of the CFB data. Once the images are in the CFB, they can be manipulated and trans-

18

formed by the processor, operating as an extended 3D bitblt engine. Three-dimensional geometric models are another source of the CFB data. These models are scan-converted by the 3 D geometry pro- cessor into their 3 D voxel representation within the CFB and can be intermixed with the scanned data. The 3D viewing processor generates a 2D shaded orthographic projection of the CFB image in a conventional 2 D frame buffer. The 3 D viewing processor carries out the projection and the con- gradient-shading processes simultaneously. In order to manage the huge quantity of voxels and still perform in real time, the system is replete with speed-ups and parallel mechanisms. In partic- ular, two key features were incorporated within the architecture: a unique skewed CFB organization, which permits the retrieval and storage of voxels in parallel, and a multiple-write projection bus, which speeds up the viewing process. The special 3 D skewed CFB organization enables simulta- neous storage or retrieval of a whole beam of vox- els that is parallel to one of the principal axes. The n 3 CFB is partitioned into n distinct memory modules each with n 2 voxels such that each of the n voxels of a beam resides in a different memory module [10]. Consequently, a conflict-free one-cy- cle write or read of any of the 6 n 2 beams is guaran- teed. This special organization reduces a 3 D prob- lem involving voxels to a 2 D problem involving beams of voxels, whereby the entire set of n 3 voxels can be retrieved as n 2 beams in O (n 2) time. The architecture also hinges on means of extracting a single voxel depth and its color value from among all the voxels along a beam in O(logn) time. The selected voxel is generally the closest non-transpar- ent voxel to an observer, permitting the construc- tion of an orthographic projection, for example, in O (n 2 log n) time. The mechanism exploits a spe- cial common bus, called the voxel multiple-write bus (VMWB), composed of n identical processing units, each associated with a unique memory mod- ule. A full beam of n voxels, fetched from the CFB along the view direction, is placed into the VMWB processing logic, with each voxel in its associated processing unit, for the selection of the non-trans- parent voxel closest to the observer. All the units holding non-transparent voxels "race" for the bus by comparing their sequential indices bit for bit, and the one closest to the observer succeeds after log n steps [11]. For every beam, the VMWB outputs two values associated with the closest voxel along the beam

Page 4: Real time discrete shading

corresponding to its color and its depth (distance from observer). These two values are passed direct- ly to the shading unit. As will be described later, the shading unit, implementing the congradient technique, is pipelined at the pixel level with the VMWB. Since the shading time is less than the viewing time (CFB retrieval and VMWB process- ing), no additional processing time accrues due to the shading unit.

4 Congradient shading

The new shading technique capitalizes on the ad- vantages of both contextual shading and gradient shading and, hence, has been labeled congradient shading. Congradient shading, like normal-based contextual shading [-2], defines the surface orienta- tion as one of a finite set of neighborhood codes and, consequently, can employ a fast table-driven mechanism. However, instead of defining the orien- tation of a voxel face relative to its adjoint faces by a sign function (one of three possibilities), the congradient technique computes the gradient in a way similar to the gradient shading method; thus, no additional memory is required to store the neighboring code with each voxel face. The com- plexity of the gradient method is avoided by com- puting the normal using a simplified version of the central differences, and by employing a finite, rela- tively small LUT to find the appropriate color in- stead of explicitly calculating it. The weighted aver- ages of forward and backward differences [5] are not employed here. Although this may cause some artifacts around abrupt changes from one surface to another, it simplifies the congradient architec- ture. With minor changes, however, the weighted differences can be incorporated within the congra- dient-shading method. Unlike other voxel-based systems that perform shading in a separate post-processor, the congra- dient-shading unit in Cube is an integral part of the projection process, and each single pixel is pipe- lined through the projection and shading units. Every opaque voxel that survives the race for visi- bility (now a pixel) is shaded en route to the 2 D frame buffer (FB). This is accomplished simulta- neously with the reading and the projection of the next voxel beam, and since the shading time is less than the total retrieval and projection time, shad- ing requires no additional time. Achieving true real-time shading speed is the result of implement-

ing the congradient technique in a fast and simple hardware architecture, which is described in Sec- tions 6 and 10. Furthermore, the location and char- acteristics of the light source can be arbitrarily and rapidly changed in congradient shading, which is of great advantage for human comprehension of the 3 D scene. Two basic versions of the congradient technique have been conceived. In the simpler of the two ver- sions, the gradient estimate takes into considera- tion only the horizontal neighbors. This is called unidirectional shading. While it causes some vertical artifacts, it nevertheless generates a quality 3 D im- age. Figure 1 a, c presents some low-resolution ob- jects illuminated by unidirectional congradient shading. The second version, called bidirectional shading, calculates both the horizontal and the vertical vec- tors of the gradient. This requires a larger buffer and a hardware realization that is slightly more complex. With this version, the quality of the shaded images is comparable to that of other con- ventional techniques. Figure l b, d presents some low-resolution examples of bidirectional shading.

a b

c d Fig. lad. Objects projected from a 1283 CFB shaded a, e by unidirectional congradient shading; b, d by bidirectional con- gradient shading

19

Page 5: Real time discrete shading

5 Unidirectional congradient shading

The simple congradient-shading technique assumes a light source at infinity shaped as a vertical line, and since only the horizontal x derivative is needed to estimate the gradient, this technique is termed unidirectional shading. (A similar unidirectional shading can be achieved with a horizontal light and a vertical y derivative.) The gradient Nx at any point is then approximated by a horizontal neigh- borhood. Calculation of the central difference in- volves finding the difference between the depths of the two horizontal neighbors on both sides, left and right, of the point and dividing it by A x, which is the distance between the two neighbors along the horizontal axis. Let d u be the distance from the observer to the visible surface at pixel (i, j), where 0 =< i < n, 0 < j < n, and n is the resolution. The horizontal derivative Oz/~x is best approxi- mated by the central difference:

~? z A z 1 - - - - - (di+r j - d i - z , j ) 3 x " ~ A x A x '

l < i < n - - r , O<=j<n (1)

where r and 1 are the size of the neighborhoods to the right and the left of the center voxel, respec- tively, and

A x = r + l . (2)

Considering the common case of a neighborhood of size 3 (i.e., r = / = l and Ax=2) , Eq.(1) yields the gradient of the center voxel:

6z 1 c~x "~ 2 (di+ 1,j - d i - 1j). (3)

A main factor in attaining the high shading speed is that the shading process is split into two stages. One stage is performed in parallel with the projec- tion process before storing the image in the FB, and the other is performed past the FB using a color LUT. During the first stage, only the voxel congradient N~ = f l (%,) is calculated. The congradient function f l is a clipped gradient N~:

N x = A (Nx)= / HN/2

t -H/2

i f - - H/2 <= N~ <= H/2 i f N~ > H/2 i f N~ < - H/2

(4)

fl (N•

+HI2

I I

I

-HI2

~Nx

Fig. 2. The congradient function fl

where H is the size of the congradient space, i.e., the finite number of central differences, as depicted in Fig. 2. The gradient Nx is clipped so it can be used in the second phase as an index Nx to a small, finite LUT. bTx is concatenated with the source col- or, Sc, of the voxel, to form the intermediate result El , which is stored in the FB as two adjacent fields: Sc and Nx. Note that E1 is independent of the light source direction and intensity. The second stage of the shading takes place on the pixel route from the FB to the screen, employ- ing a color LUT that implements the light source function c~ (El, L), where L is the light source pa- rameter, including the direction of light and its in- tensity and chroma. This approach, in addit ion to being fast, gives the flexibility of illuminating the scene from different directions with different light characteristics, simply by varying the LUT and without the need for repetitious scanning and pro- cessing of the CFB images. Since the congradient is used only to index a LUT and is a relative quantity, Eq. (3) can be simplified to

N~ = d~ + 1 , j - di- 1,j, (5)

which also simplifies the congradient function f l (N~). The precision of the result bT~ depends on the bit precision of the bounded central differences. The congradient values are spread evenly within the bounds of an interval of size H, e.g.,

H - H - 2 <N~< = 2 " (6)

20

Page 6: Real time discrete shading

sourcs colors

T M Nl!'iii!!iiiiiiii ............... .............. I

4> shades

direction ~ of light

I [!I l iijFiiiiliiiiiiiiiiiiFIliiiiiiii - 4 - 3 - 2 - I 0 I 2 3 4

direction of light

I;i!i!iiiil l iiiiiiiiliiiiiiNIN - 4 - 3 - 2 -1 0 1 2 3 4

from from VMWB depth VM,WB color ~I S~[~] L regiske i

q•

FB

cI(Sc,R~,L)

L liqht direction 5 color/intensiCy

Sc

screen

Fig. 3. A LUT implementation of c 1

Fig. 4. A typical row from the LUT cl for two different direc- tions of light

Fig. 5. Block diagram of the unidirectional shading hardware

The shift of the congradient from the center of the interval of size H expresses the required shift from the original color of the voxel according to its gra- dient. The exact nature of such color fluctuation is given by the entity Ea, which represents a combi- nation of the voxel gradient and its color. It disre- gards the virtues of the light source: direction, in- tensity, and chroma, which are incorporated by the function cl (El, L) in the second stage. The function ca is implemented as a 2D color LUT in which each row entry represents one of the source colors. The various shades, indexed by -gx, are distributed across the row of length H and represent different shadings of the source color for each possible con- gradient. The way the different shades fluctuate around the central source color depends on the light source direction (see Fig. 3). When the direction of the light coincides with an orthographic viewing direc- tion, the source color is placed in the middle, and

the shades are spread uniformly on both sides. Moving the original hue from the row center to- ward one of the ends has the effect of adjusting the direction of the light source (see Fig. 4). This mechanism provides a tool for dynamically and rapidly changing the light source direction, which assists in comprehending the 3 D scene. Al- tering the light parameters does not require recal- culation of the FB image and is done instead by reloading the LUT. Consequently, real-time light changing is feasible with this technique.

6 Hardware architecture for unidirectional shading

The hardware block diagram of unidirectional shading is depicted in Fig. 5. Assuming a neighbor- hood of 3, the recent voxel just retrieved from the CFB is not being processed yet, but rather the one

21

Page 7: Real time discrete shading

just before it. Therefore, the contents of two voxels are being held in a two-word shift register. The previous voxel color, output from the shift register, is stored as the Sc field of E~ in the FB. The congradient calculation originates in a triple shift register, which holds the depth values of the central voxel being processed and its two horizon- tal neighbors. The depths of the two neighbors are compared in a subtraction unit and the difference becomes the gradient Nx of the center voxel. This is then clipped by the function fa (Nx), resulting in a congradient N~. Sc and 57:, are stored in two sepa- rate fields within the FB word as El. In the second stage, the Sc is a basic color pointer to the LUT, and the congradient value Nx offsets the color to the corresponding shade. The time necessary to generate and store one Ea pair in the FB is the sum of three steps: subtraction, binary value clipping, and FB memory access. This sum is estimated to be less than 60 ns, assuming an H width of 3 bits and an FB size of 5122. This estimate is based on the subtraction time of two- depth words, 9 bits each, on f~ clipping logic (two- level gate network) and access time to a 5122 mem- ory matrix of the FB. Consequently, to shade and fill the entire 5122 FB would take only 16 ms. This means a shading rate of more than 60 times per second, which is the usual display refresh rate and is undoubtedly true real time. These time measures are much shorter than that of the projection process, which includes the beam retrieval and processing by the VMWB. The esti- mated time for a single beam retrieval and projec- tion is about 2 ~ts (33 times slower than the shading of a single pixel), while the entire FB projection can be generated in about 0.5 s for a 5122 CFB using off-the-shelf hardware components. Note also that the second stage of unidirectional shad- ing, which exploits the conventional color LUT present in 2 D raster systems, operates in parallel with the projection process and the first phase of congradient shading. Consequently, the whole pro- cess of congradient unidirectional shading in Cube is entirely time-transparent.

7 The congradient space

The size of the congradient space, denoted H, dic- tates the clipping of the gradient by fl and the length of the cILUT row. The determination of

22

this number takes into consideration three con- straints. The first is the sensitivity of the congradient due to its discrete representation. Since the congradient is calculated as the difference between the discrete depths of two voxels, the resolution of the gradient is low. In the case of a neighborhood of size 3, a central difference of 1 between two nearest neigh- bors represents a slope of 18~ a difference of 2 represents a slope of 34~ and a difference of 7 rep- resents a slope of 67 ~ (see Table 1, Fig. 6). Table 1 shows that the congradient function is more sensi- tive in the range of relatively large angles. However, from our experience, it is sufficient to use a pre- cision in the range of 2-4 bits, representing slopes that cover the majority of the range of angles. The second constraint is the hardware limitation. As the binary representation of H gets smaller, the LUT becomes smaller, leading to faster LUT ac- cess. In addition, smaller H leads to faster arithmet- ic operations and reduces the cost and complexity of the hardware. Therefore, in terms of hardware, a small range of H is advantageous. The third constraint is encountered by the human eye, which does not distinguish between small vari- ations in shades caused by a large /-/. However, poor resolution in shades creates undesirable arti- facts. As a result of our observations, an / - /wid th of 3 bits (including positive and negative varia- tions) gives a sufficient impression of realistic shad- ing. It furnishes eight different shades, including

T a b l e 1. C o n g r a d i e n t an g l e o f t h e c e n t e r voxe l as a f u n c t i o n

of the r e l a t i ve d e p t h of its n e i g h b o r s

A z N e i g h b o r h o o d size

A x = 2 A x = 3 A x = 4

1 26.6 ~ 18.4 ~ 14.0 ~

2 45.0 ~ 33.7 ~ 26.6 ~

3 56.3 ~ 45.0 ~ 36.9 ~

4 63.4 ~ 53.1 ~ 45.0 ~

5 68.2 ~ 59.0 ~ 51.3 ~

6 71.6 ~ 63.4 ~ 56.3 ~

7 74.1 ~ 66.8 ~ 60.3 ~

8 76.0 ~ 69.4 ~ 63.4 ~

9 77.5 ~ 7 ! .6 ~ 66.0 ~

10 78.7 ~ 73.3 ~ 68.2 ~

11 79.7 ~ 74.7 ~ 70.0 ~

12 80.5 ~ 76.0 ~ 71.6 ~

13 81.3 ~ 77.0 ~ 72.9 ~

14 81.9 ~ 77.9 ~ 74.1 ~

15 82.4 ~ 78.7 ~ 75.1 ~

16 82.9 ~ 79.4 ~ 76.0 ~

Page 8: Real time discrete shading

Z depth

7

6

5

4

3

2

I

0

AZ=-I

x

z depth

7

6

5

4 3

1 N 0

>,z= -2 '~X

z depth

6

AZ= -3

z depth

7

5 N 4 N

2N 1N oN

z~z= - 4

. .~x

z depth

N-

z~Z= +3

Z depth

7

6

5

4 3

2

I

0

AZ=+2

Z depth

7

6

S

4

3

2

I

0 ~X

AZ=+I X

Z depth

7

6

5

4

3

2

I

~ AZ= 0

Fig. 6. Various central depth differences for a neighborhood of 3

the source color. This seems to be the lowest limit of width acceptable for human vision; it covers the major slopes and yields a sufficient number of shades. The hardware takes advantage of it in terms of speed and simplicity.

8 The neighborhood size

Different neighborhoods can be used to calculate the gradient N~. Using a large neighborhood might result in a more exact computation of N~, but also usually requires more hardware and more calcula- tion time, using summation and division (or shift- ing) to get an average depth. Since we are interested in fast, simple, and accurate calculations, only the impact of small and near neighborhoods will be considered. In the unidirectional scheme, Nx repre- sents the gradient:

Az Oz N~, = ~xx ~ ~ x (7)

where the normal angle 0 is

/Oz\ [~z\ O=arctan~xxJ~arctant~xx), (8)

and A x is the size of the horizontal neighborhood of voxels from which Nx is calculated. Different sizes of A x define different discrete values of 0. Table 1 exhibits the gradient angles of the center voxel as a function of the relative depths of its neighbors using neighborhoods of sizes 2, 3, and 4. In a neighborhood of size 2, Nx is computed between the center voxel and its left neighbor (backward difference): Nx = d i , j - di_ t , j . In a neigh- borhood of 3, the depth of the left and right neigh-

- - 1 �9 bors are compared: Nx - ~ (di + 1, j - - d i - 1 , j ) , while in a neighborhood of 4, the second voxel to the left is compared with the voxel to the right of the center

__1 voxel" N x - ~ ( d i + l , j - d i - 2 , j ) . Other schemes of neighborhoods can be considered as well. For ex- ample, the relative depth of four diagonal neigh- bors can be calculated, pair by pair, and then aver-

1 aged: Nx= ~((di+ t,j+ t - d i _ l,j_ l)-{-(di_ x,j+ l -di+ x,j-1)).

As can be seen from Table 1, when the neighbor- hood size grows, the range of covered angles ex- pands into the smaller angles. As a result of in- creasing the angle resolution in the lower range, the picture is smoothed, which might be considered an advantage in overcoming artifacts due to object discreteness. On the other hand, a smaller neigh- borhood is sensitive to small changes on the surface

23

Page 9: Real time discrete shading

and, therefore, contributes to the realistic appear- ance of coarse surfaces. The unanswered question is whether those small changes are caused by the discrete nature of the image or are part of the true appearance of the real scene.

9 Bidirectional congradient shading

As can be seen in Fig. i a, c, unidirectional shading introduces horizontal artifacts. To eliminate these artifacts, bidirectional congradient shading has been devised. The unidirectional shading technique has been expanded to a bidirectional technique by including in the congradient calculation both the horizontal and the vertical gradients, each comput- ed as in the unidirectional case. For example,

Nx=di-l, j-di+l,j Ny=di,j-1 -di,j+l. (9)

The resulting shaded images lack the horizontal artifacts and are shaded more "accurately", taking into consideration the vertical orientation of the surfaces (see Figs. 1 b and d). As in the unidirection- al technique, there are several possible schemes for calculating the derivatives, all involving different size neighborhoods. It has been found, however, that considering a small neighborhood of the voxel is most effective, particularly for low-resolution surfaces. The function that reduces the number of gradient levels is now bivalued and bivariate:

(Nx, N r) = f2 (N~, -IVy) = (fl (Nx), fl (Nr)). (10)

The two components of f2(N~, Nr), together with the source color Sc, are stored in the FB as three separate fields of the intermediate result E2. Once the FB has been established, the two congradients (N:, Nr) with the source color, Sc, are employed in choosing the proper entry in a 3D color LUT for each FB pixel. In other words, shading a single source color with nine shading levels requires 81 entries in a 2D color LUT, as shown in Fig. 7a, c. To avoid having a 3D LUT or a separate 2D LUT for each source color (as in Fig. 7 a, c), two different LUTs are used in succession, each in a separate phase, a second and a third phase. The second phase employs the Nx and Nr congradient values to select from a 2D "achromatic" LUT, which is a function g2(Nx, Nr, L) of the 2D congradient and

24

a b

c d

Fig. 7a-d. A 2D LUT for a single color Sc, comprised of 81 entries (nine for Nx and nine for Ny). Thus, a 3 D LUT is required for the entire Sc space. Note, however, that there are only nine distinct shades in each Sc table, and, therefore, a two tier LUT can be employed, a, e 2D LUTs for different light directions; b, d the corresponding shaded images

the light source direction. In the third phase, the value g2 (Nx, Ny, L), together with Sc, is used to se- lect from a 2D color LUT, c2LUT. The source color Sc selects a row within the czLUT, while the value gz(Nx, Ny, L) specifies the relative location of the shade across the row, based upon the voxel gradient and the light source direction. Note that the g2 LUT incorporates the light direction proper- ties, while the czLUT incorporates the color and intensity of the light source. Consequently, dynam- ic changes in the light source direction are easily and rapidly carried out by changing the gzLUT; changes in the light source intensity and color are carried out by changing the czLUT.

10 Hardware architecture for bidirectional shading

The block diagram of the bidirectional shading hardware is depicted in Fig. 8. This architecture is an extension of the unidirectional scheme shown in Fig. 5. In the bidirectional case, four neighbors

Page 10: Real time discrete shading

from from VrfWB VMWB

~ l depth register L~t ! : l l l l l , . . , l l l l l ' l l l l l l , , . 1111112n*~ II

L Light direction color / intensi ty

color reg~sLer

IIII ........ lllllBn+l

Fig. 8. Block diagram of the bidirectional shading hardware

. . .~ ' ~ 9 ~

Depth Shift Register

- n +n

~ , . , ~::#:r162162162 ,..

Color Shift Register - n 0

~ . , . I::~::~i:il::~i~i~::li~::~::~::l!~!~::r

FB

ii!i iii~i~i i~i~i~i i!i!i!i i!iii!iliii~i~iH ii!iiiiiiii!iii

I I

Fig. 9. The depth and color shift registers for a 3-neighborhood in bidirectional shading

of each voxel (e.g., neighborhood 3 in both horizon- tal and vertical directions) are considered. Conse- quently, the color and depth registers are longer than in the unidirectional implementation (see Figs. 8, 9). Their lengths are n + 1 cells (the current point and one row following it) and 2n + 1 cells (the current point, a row before it, and a row fol- lowing it), respectively, where n is the length of a beam (the resolution). Referring to the architec- ture depicted in Fig. 8, the difference between the two voxels on both sides of the one being shaded yields the horizontal gradient N~. Similarly, the left- most and the rightmost points in the depth shift register are the closest vertical neighbors (just above and just below) to the voxel being shaded and, therefore, their difference yields the N r gra- dient (see Eq. 9). The 2 D congradient function f2 operates on both N~ and %, yielding a pair of congradients (Nx, Ny) that are stored in two fields of the E2 word in the FB. The third field is the source color Sc of the current pixel and is transferred directly from the rightmost cell of the color shift register. As in the unidirectional scheme, the steps described above are crucial to real-time performance. Al- though two components of the congradient are

computed in the bidirectional method, the speed of this hardware unit is the same as that of the unidirectional method (i.e., 60 ns for one E2 com- putation). This is because the two subtraction units and the f2 can operate in parallel on both gra- dients. The increased size of the FB word does not change the speed. Consequently, the on-the-fly gen- eration of the FB matrix is as fast as that of the unidirectional method; it is also time-transparent with regard to the projection process. As previously mentioned, the second phase of bi- directional shading uses the congradients (-Nx, %) to select the value g2(bTx, Nr, L ) from the gaLUT, and this is then used with Sc in the third phase to select the final shaded pixel color from the c2LUT. The third phase of the bidirectional shad- ing is equivalent to the second phase of the unidi- rectional shading and can also exploit a similar conventional color LUT mechanism. However, the bidirectional process has an extra phase (its second phase) that requires an additional small LUT and may slightly increase the shading time by an extra LUT access. Since the projection time far exceeds the shading time, the projection process is still the bottleneck of the system, and any increase in the shading time is not noticeable.

25

Page 11: Real time discrete shading

ompeter 11 Concluding remarks

We have presented the congradient-shading tech- nique implemented as an inherent part of the pro- jection process, rather than as a post-processing shader. This makes the congradient method suit- able for real-time performance, which is a principal goal of the Cube architecture. The two versions of congradient shading, unidirectional and bidirec- tional, have been described. The hardware realiza- tion of the unidirectional method is simpler and slightly faster than that of the bidirectional method, but its image quality is not as good as that of the latter. Both operate in real time, approximately 60 times per second. This has been achieved mainly by devising a fast gradient-computing method and by splitting the shading process into two or three separate phases, the last of which is handled by a conventional LUT mechanism. The congradient method enables a dynamic change of the light source direction, as well as its color and intensity. This shading is clearly ideal for hardware imple- mentation as there is no need for complex calcula- tions, and the only components required are shift registers, adders, and LUTs. Congradient shading has been developed and si- mulated at the Department of Computer Science of the State University of New York at Stony Brook and at the Center of Computer Graphics of the Ben-Gurion University. The simulations have been carried out on SUN-3/160C worksta- tions. Congradient shading has been integrated into all of the Cube implementations [11, 12]. Fig- ures 10 and 11 show two examples of synthetic and empirical objects, respectively, shaded using Cube implementations of congradient shading.

A reduced-resolution hardware prototype of the Cube system of 163 CFB of voxels has been realized in hardware and has been running successfully in real time. This realization, which includes the mem- ory and the VMWB components, consists of 16 modules implemented as printed-circuit boards. The hardware congradient shading is being de- signed for integration with this Cube prototype. The goal of this implementation is to demonstrate the feasibility of real-time performance of the pro- posed shading method, a feature that cannot be effectively tested with software.

Acknowledgments. The support of the National Science Founda- tion under grants DCR 8603603, CCR 8743478, CCR 8717016, and MIP 8805130 and of the Fraenkel Center of Computer Sci- ence at Ben-Gurion University are gratefully acknowledged.

References

1. Bright S, Laflin S (1986) Shading of solid voxel models. Computer Graphics Forum, 5 (2): 131 138

2. Chen LS, Herman GT, Reynolds RA, Udupa JK (1985) Surface shading in the cuberille environment. IEEE Comput Graph Appl 5 (12):33-43

3. Foley JD, Van Dam A (1982) Fundamentals of interactive computer graphics. Addison-Wesley, Reading, MA

4. Goldwasser SM (1984) A generalized object display proces- sor architecture. IEEE Comput Graph Appl 4 (10):43-55

5. Gordon D, Reynolds RA (1985) Image space shading of 3-dimensional objects. Computer Vision, Graphics and Im- age Processing 29:361-376

6. Herman GT, Liu HK (1979) Three-dimensional display of human organs from computed tomograms. Computer Graphics and Image Processing 9:1-21

7. Herman GT, Udupa JK (1981) Display of three dimensional discrete surfaces. Proc SPIE 283:90-97

8. H6hne KH, Bernstein R (1986) Shading 3 D-image from CT using gray-level gradients. IEEE Trans Medical Imaging, MI-5, 1:45-47

10

26

11

Fig. 10. A synthetic 5123 voxel torus shaded using congradient shading

Fig. 11. A 1283 voxel image of a brain, density-segmented from MRI scans and shaded using congradient shading

Page 12: Real time discrete shading

9. Jackel D (1985) The graphics PARCUM system: a 3D mem- ory based computer architecture for processing and display of solid models. Computer Graphics Forum 4: 21-32

10. Kaufman A (1986) Memory organization for a cubic frame buffer. Proc EUROGRAPHICS '86, Lisbon, Portugal (Au- gust 1986), pp 93-100

11. Kaufman A, Bakalash R (1988) Memory and processing architecture for 3-D voxel-based imagery. IEEE Comput Graph Appl 8 (6): 10-23

12. Kaufman A (1988) The CUBE workstation - a 3D voxel- based graphics environment. The Visual Computer 4 (4):210-221

13. Meagher DJ (1985) Applying solids processing methods to

medical planning. Proc NCGA, Dallas, TX (April 1985), pp 101-109

14. Ohashi T, Uchiki T, Tokoro M (1985) A three-dimensional shaded display method for voxel-based representation. Proc EUROGRAPHICS '85. Nice, France (September 1985), pp 221 232

15. Uchiki T, Tokoro M (1985) SCOPE: solid and colored ob- ject projection environment. Transaction of the Institute of Electronics and Communication Engineers of Japan, 68-D, 4 (April 1985):741-748

16. Vannier MW, Marsh JL, Warren JO (1983) Three-dimen- sional computer graphics for craniofacial surgical planning and evaluation. Comput Graph 17 (3): 263-273

DANIEL COHEN is a Ph.D. student in the Department of Computer Science at the State University of New York at Stony Brook. Prior to coming to Stony Brook, he was a soft- ware engineer at Aphkon, Ltd., Israel, working on bitmap graphics. He holds a B.Sc. (with honors) in both Mathematics and Computer Science (1985) and an M.Sc. (with honors) in Computer Science (1986) from Ben-Gurion University, Israel. His research interests are vol- ume visualization, graphics ar-

chitectures, and graphics algorithms.

ARIE KAUFMAN is a Profes- sor of Computer Science at the State University of New York at Stony Brook. He has held positions as a Senior Lecturer and Director of the Center of Computer Graphics of the Ben- Gurion University in Beer-She- va, Israel, and as an Associate and Assistant Professor of Computer Science at Florida International University in Miami. His research interests include computer graphics ar- chitectures, algorithms, and lan- guages, voxel-based graphics,

and visualization. Kaufman received a B.Sc. in Mathematics from the Hebrew University in 1969, an M.Sc. in Computer Science from the Weizmann Institute of Science in 1973, and a Ph.D. in Computer Science from the Ben-Gurion University in 1977. He is a member of ACM, SIGGRAPH, IEEE-CS, EUROGRAPHICS, NCGA and IPA.

NEUVEN BAKALASH holds a research position at the Depart- ment of Computer Science at the State University of New York at Stony Brook, and is also an Assistant Professor of Computer Science at Hofstra University, New York. For five years he was with Beta Engi- neering and Development, where he was engaged with CAD systems. Then he was the head of EE and CAD/CAM Departments in the Practical Engineering College of Beer- Sheva, Israel. His research in-

terests include computer graphics architectures and algorithms, CAD/CAM, voxel-based graphics, and graphics applications. He received a B.Sc. in Electrical Engineering from the Technion, Israel in 1972, an M.Sc. in Electrical Engineering (1982) and a Ph.D. in Computer Science (1988) both from the Ben-Gurion University. He is a member of ACM, IEEE, ITIM, and IPA.

SAMUEL BERGMAN received his B.Sc. in Electrical Engineer- ing from the California Institute of Technology in 1960, his M.Sc. in Computer and Electri- cal Engineering from New York University in 1963, and his Ph.D. in Computer Science from the University of Pennsyl- vania in 1972. He is one of the founders of the Computer Sci- ence program at the Ben-Gur- ion University in Beer Sheva, Israel. Currently, he is the Di- rector of the Fraenkel Center of Computer Sciences at the Ben-

Gurion University. Among his interests are computer graphics, operating systems, architecture, and CAI.

27