A Generalization Drawing of Algebraic Surface: James F. Blinn Jet Propulsion Laboratory
A Generalization Drawing of Algebraic Surface: James F. Blinn Jet Propulsion Laboratory
A Generalization Drawing of Algebraic Surface: James F. Blinn Jet Propulsion Laboratory
The mathematical description of three-dimensional surfaces usually falls into one of two classifications: parametric and implicit. An implicit surface is defined to be all points which satisfy some equation F (x, y, z) = 0. This form is ideally suited for image space shaded picture drawing; the pixel coordinates are substituted for x and y, and the equation is solved for z. Algorithms for drawing such objects have been developed primarily for fLrst- and second-order polynomial functions, a subcategory known as algebraic surfaces. This paper presents a new algorithm applicable to other functional forms, in particular to the summation of several Gaussian density distributions. The algorithm was created to model electron density maps of molecular structures, but it can be used for other artistically interesting shapes. Categories and Subject Descriptors: 1.3.3 [ C o m p u t e r Graphics]: Picture/Image Generation--display algorithms; 1.3.5 [ C o m p u t e r Graphics]: Computational Geometry and Object Modeling--curve, surface, solid, and object representations; 1.3.7 [ C o m p u t e r Graphics]: Three-Dimensional Graphics and Realism--visible line~surface algorithms General Terms: Algorithms, Performance
1. INTRODUCTION
The technology of creating realistic and visually interesting images of threedimensional shapes is advancing on many fronts. One such front is the development of algorithms for drawing curved surfaces directly from their mathematical definitions rather than by dividing them into large numbers of polygons. Two classes of surfaces which have received attention are the quadric and the bivariate parametric surfaces. Bivariate parametric surfaces are generated by three functions of two variables (most popularly polynomials), as the variables take on different values. Algorithms dealing with such surfaces are due to Catmull [2]; Lane, Carpenter, Whitted and Blinn [7]; and Clark [3].
The research described in this paper was carried out by the Jet Propulsion Laboratory at the California Institute of Technology, under contract with the National Aeronautics and Space Administration. Author's address: Jet Propulsion Laboratory, California Institute of Technology, 4800 Oak Grove Drive, MS 201-209, Pasadena, CA 91109. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. 1982 ACM 0730-0301/82/0700-0235 $00.75 ACM Transactions on Graphics, Vol. 1, No. 3, July 1982, Pages 235-256.
236
J.F. Blinn
Quadric surfaces, on the other hand, are solutions to second-order functions of the coordinates:
a x 2 + bxy + cxz + dx + ey 2 + f y z +gy
+ h z 2 + iz
+j=0. This class of surfaces includes such shapes as spheres, cones, hyperboloids of revolution, and so forth. Algorithms for dealing with such shapes have not been widely published but have been implemented by MAGI [5], Blinn [1], Duff [4], and General Motors research labs [10]. While this class of shapes is somewhat restricted, it can be used to advantage in modeling many useful objects such as machine tool parts, as long as the modeling system allows a fragment of a shape to be employed as well as the entire shape. Quadrics belong to the class of curved surfaces known as "implicit" surfaces, that is, solutions to some equation
F ( x , y, z ) = O.
This paper examines a more general solution to the imaging problem for such surfaces and describes in detail its application to a class of surfaces which are closely allied to quadrics but have a wider range of shapes.
2. THE MODEL
T h e problem which motivated this paper is the familiar one in computer graphics of displaying molecular models. This is most often done with a ball-and-stick model or a space-filling-sphere model. In either case, the model consists of a possibly intersecting collection of two basic shapes: spheres and cylinders. To draw a picture of the model, the spheres and cylinders can easily be broken down into polygons and passed to a conventional polygon-rendering algorithm. Alternatively, any of several curved surface algorithms may be employed, and, in fact, several special-purpose algorithms [6, 8, 9] have been formulated to handle efficiently just these two shapes for rapid display of large molecular structures. In the interests both of artistic variety and scientific accuracy, a new model was sought that breaks away from the ball-and-stick/space-filling mold. It was desired to make the bonds between atoms appear more like those shown in Figure 1. This is, in fact, more like what a real electron density cloud might look like for a covalent bond. In addition, for the purposes of animation, this bond must stretch and contract in a pleasing manner as it vibrates, ultimately snapping apart as an atom is pulled completely away from the molecule. This is illustrated in Figure 2. A conventional approach might be to model such a shape via the already familiar bicubic or quadric surfaces. This is moderately feasible for one isolated bond but becomes difficult for more elaborate molecules with several overlapping bonds (e.g., ring structures). In addition, the topological changes that must occur when a bond breaks are difficult to deal with in an automated manner. For these reasons a basic mathematical model was used which is similar in form to an
A C M Transactions on Graphics, Vol. 1, No. 3, J u l y 1982.
237
Fig. 1.
Fig. 2.
B o n d stretching a n d breaking.
actual simulation of electron density maps. Quantum mechanics represents the e l e c t r o n in a n a t o m a s a d e n s i t y f u n c t i o n o f t h e s p a t i a l l o c a t i o n . A s a m p l e f u n c t i o n for a h y d r o g e n a t o m is
D ( x , y, z) = e x p ( - a r )
where r = ~/(x- xl) 2 + (y-y1) (xl, y l , Zl) = l o c a t i o n o f a t o m W e c a n r e p r e s e n t t h i s f u n c t i o n for a c o l l e c t i o n o f a t o m s b y s u m m i n g contribution from each atom separately. the 2 + (z - z l ) 2
D ( x , y, z) = ~, bi e x p ( - a i r i )
i
w h e r e ri = d i s t a n c e f r o m x, y, z to t h e c e n t e r o f a t o m i.
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
238
J.F. Blinn
A surface can be defined as those points where this density function equals some threshold amount:
F ( x , y, z) = D ( x , y, z) - T.
Note t h a t all points inside the s u g a c e have electron densities greater t h a n T. For the purposes of computational eft~ciency, the function actually implemented was similarly shaped:
D ( x , y, z ) = ~ bi e x p ( - a i r ~ )
i
This does not require taking a square root. T h e exponential t e r m is a simple Gaussian b u m p centered at ri, with height bi and standard devation ai. B y adjusting the ai and bi parameters, different effects can be achieved for the same a t o m arrangement. T h e s e effects alter the "blobbiness" of the object. In fact, for modeling purposes, it is more useful for a designer to specify these two p a r a m e t e r s in terms of the radius of the atom in isolation and a blobbiness parameter. T h e radius of an isolated a t o m Ri is found by setting
T = bi e Xp ( - a i R i )2 = e x p ( - a i R ~ + In bi)
T h e net density contribution of one atom in terms of the two shape-defining p a r a m e t e r s Ri and Bi is
Di(x,y,z) = Texp(Bi 2~--~ri-Bi)"
N o t e t h a t B~ must be negative to ensure t h a t the desity function goes to zero as r~ goes to infinity. Since there is a factor of T in each contributing atom t e r m the value of the threshold is now irrelevant; we can set it to some canonical value such as 1. One can get the same effect as changing the threshold by adjusting the scale factors, bi, of the individual terms (i.e., by adjusting the blobbiness p a r a m e t e r s Bi). For clarity, though, we usually write the threshold as T, with the understanding t h a t T = 1. A canonical threshold value of 1 is particularly convenient since its logarithm is 0. T h e surface defined by an isolated atom, defined by setting Di = T, is t h e n a conventional quadric surface. This is seen by taking the logarithm of b o t h sides of the above equation yielding 0 = (Bi/R~)r~ - B/. A sample image showing a range of such p a r a m e t e r s is shown in Figure 3.
239
Fig. 3.
Surfaces defined algebraically are inherently well suited to raster conversion algorithms. The general structure of such an algorithm is straightforward: for each (xs, ys) pixel location the defining algebraic equation reduces to a univariate equation in z. Solutions to this equation {if any) yield the z depth of the surface at that pixel. In the case of the more common quadric surfaces this solution is easy to obtain. In the case of the more general surfaces described here, the solution must be obtained numerically. The important part of the algorithm described here is a technique for speeding up this computation.
3.1 Coordinate Systems
We begin by defining the various coordinate systems to be used. All atoms are transformed into a standard viewing space, with the eye looking down the +z axis, the x axis pointing to the right, and the y axis pointing upward (a left-handed coordinate system). In this space the sizes and shapes of viewed objects are not altered, only their orientations and positions are adjusted according to the viewing direction. A perspective image is then obtained with the eye positioned at the origin. This yields a homogeneous perspective matrix in terms of the field of view (Fov) and the locations of the near and far clipping planes (Zn and zr).
if0001 whereccosFovj2
p = C 0 0 S =sin(Fov/2) 0 0 Q R S 0
Q=--Szf/(Zn--Zf)
R---Qzn
This transformation will be followed by a scale and translation in x and y (the "viewport" transformation) which converts from the canonical - 1 to +1 visible
240
J . F . Blinn
coordinate space into hardware screen (pixel) coordinates. Note t h a t the x and y scale might not be equal if pixels in the screen space are not square.
V=
[XwO
0 0 Xc yw 0 yc 0 1 0
T h e s e two transformations are concatenated with the viewing transformation to m a k e one net transformation directly into p e r s p e c t i v e space. In this space, the shapes of objects have been distorted in such a m a n n e r t h a t a simple orthographic projection onto the z = 0 plane yields the correct p e r s p e c t i v e picture. It must be realized t h a t this perspective space is just an efficiency measure. It represents removing the perspective calculations from the rendering loop; the perspective projection {e.g., of polygon vertices) is done simultaneously with the modeling and viewing transformations via one matrix multiplication. This merging of transformations also works for rational bicubic and quadric surfaces since these classes of surfaces are closed under the perspective transformation. T h e r e are some calculations, however, which must still be done in the undist o r t e d viewing space (e.g., light reflection calculations) since t h e y depend on geometric distances and vector dot products. In fact, for the functions used here, the solution of the function itself can be done about as easily in viewing space as in perspective space. For this reason the merging of the perspective/viewport transformations and the modeling/viewing transformations is not used for this algorithm. All the a t o m centers and radii are transformed into viewing space, and pixel by pixel calculations are done by explicit rays from the origin through the pixel. A point on such a ray is defined by its z d e p t h and the perspective and screen parameters. We find this relationship by first transforming a point on the ray into perspective space. (x y z 1)[P][V] = ( x ' y ' z ' w ' )
= (xCxw + zSxc, yCyw + zSyc, zQ + R, zS)
solving for the viewing space (x, y) in terms of viewing space z yields
x = z(xs - x~)S/(Cxw) y = z(ys - yc)S/(Cyw) - ZXz =- zyz. (,)
Any point on this ray is a scalar multiple of this vector and can be parameterized by its z coordinate, yielding
(x, y, z ) = z R .
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
241
r?
I
hhl
Z ~ Fig. 4.
Zml C a u s e of r o u n d - o f f error.
For a particular pixel, the square of the distance from the center of atom i, P~, to a point on the viewing ray, z/t, reduces to a quadratic polynomial in z. r~ = (zR - P i ) " ( z / ~ - P i )
-- z 2 ( R . R ) - 2 z ( R "Pi) + ( P i ' P i )
This expression is algebraically correct but it is unfortunately susceptible to round-off error. T h e reason for this can be seen from Figure 4. T h e function can be a quite narrow parabola centered possibly quite far back on the z axis. While commonly encountered values for the coefficients of this equation do not themselves present problems, solution of the equation requires taking differences of their products. This can easily exceed the accuracy of single precision arithmetic. T o avoid the necessity of multiple precision arithmetic we adopt a more geometrically meaningful representation
r~ = ( R . R ) ( z - z~i) + M i
where
zmi = ( R . P D / ( R . R ) M~ = (zm~[~ - Pi)" ( z m i ~ - P~)
Here, zm~ is the z distance of the local minimum, Mi, of r~. Each t e r m in the density function is thus a Gaussian b u m p function of z centered at zm,. T h e total function is the sum of several such bumps. T h e visible z depth value is the first location where this function exceeds the value T. This is shown in Figure 5. If only one atom is visible, the z d e p t h can be found analytically by setting the density t e r m for t h a t atom equal to the threshold value of 1.
T = 1 = exp(-air~ - Bi)
Taking the logarithm of both sides and substituting our formula for r~,
0 = a i [ ( R . R )(z - z m i ) + M i ] 2
+
Bi.
Solving for z (note t h a t the negative square root is taken to get the solution
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
242
J . F . Blinn
f
A~
z ----~
Fig. 5.
I
VISIBLE POINT
D e n s i t y f u n c t i o n of z d e p t h . ( D o t t e d l i n e is s u m of Di.)
If t h e r e is more t h a n one atom, an analytic solution is not feasible and we must resort to numerical methods. Two popular m e t h o d s for the iterative solution of such equations are N e w t o n iteration and "regula falsi." N e w t o n iteration works by beginning with an initial guess and refining it by. approximating the function D with a straight line tangent to the function at t h a t point. Solving this linear equation yields a new guess, z ....
D(z) - T
Znew ~ Z
D'(z)
dz
- Zmi) e x p ( - a i r ~
- Bi)
N o t e t h a t this calculation uses m a n y computations in c o m m o n with the calculation of D, so evaluation of b o t h D and D ' is relatively economical. Regula falsi begins with two initial guesses which are known to bracket the solution: Zn, where D (z,) < T, and zf, where D (zf) > T. It generates a new guess b y drawing a line between (z,, D ( z n ) ) and (zf, D ( z f ) ) and solving for T. Z.ew =
zn(D(z:) - T) - zf(D(z,) D(zf) D(zn)
-
- T)
T h e real value of D (z.ew) is t h e n calculated. If D (Znew) < T t h e n Znewreplaces Zn. Otherwise it replaces zf. T h u s the range between z , and z f continually contracts a r o u n d the correct solution. If the initial guess is close enough to the real solution, N e w t o n iteration converges rapidly. If it is not close, however, it will diverge. Regula falsi is g u a r a n t e e d to converge but does so more slowly. We therefore have adopted a
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
243
Z --~l,.Fig. 6.
INITIAL GUESS
t
r~
.,'72q%
z ~ I
INITIAL GUESS
Fig. 7.
h y b r i d solution. A value for Znew is calculated by N e w t o n iteration. I f this value is outside the range (Zn, Zf) t h e n the value is recalculated f r o m the regula falsi formula. T h i s process is r e p e a t e d until the value of l D ( Z n e w ) - - T I is less t h a n s o m e error tolerance t. T o generate the first initial guess range, we rely on some heuristics based on our knowledge of the functional form. We expect the solution to be at or n e a r solutions to either the individual a t o m b u m p s (Figure 6) or to the local m a x i m u m of a b u m p if it does not itself exceed the threshold value T (Figure 7). W e therefore m a k e a list of potential initial guess z values and sort t h e m in ascending order of z. T h e sorted list is t h e n scanned f r o m front to back, and, for each element, the actual function value (i.e., the s u m of all a t o m contributions) is calculated. I f this is less t h a n the threshold value, it is a s s u m e d t h a t the local m a x i m u m of D n e a r here does not r e a c h the threshold and the next list i t e m is evaluated. I f it exceeds the threshold value, t h a t z is used as the initial value of zf and the previous list i t e m is used as the initial value of zn. See Figure 8.
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
244
J.F. Blinn
f
N
a
k.1
47
Z --------4~
Fig. 8.
I n i t i a l g u e s s list.
3.4 Intensity Calculations W h e n a z solution is found, it is s u b s t i t u t e d into eq. (*) to get the x and y locations of the visible point on the surface in viewing space. T o calculate an intensity, it is t h e n necessary to find the surface n o r m a l at this point. T h i s can be found b y taking the gradient of the surface defining function, F.
F o r the function we are using here this is readily done. For example, the x c o m p o n e n t will be
OF Ox
-- ~ - - 2 a i ( x -- x i ) e x p ( - - a i r ~
-- B i ) .
Finally, we can allow the surface reflective properties (such as color) to v a r y o v e r the surface b y blending t h e m according to the contributions f r o m each atom. T h i s is done b y taking a weighted s u m of the surface p r o p e r t y f r o m each atom, the weight being chosen as the value of Di f r o m t h a t atom. (Recall t h a t these s u m to t h e t h r e s h o l d value of 1.0.) Alternatively, as in the ease of the diagrams shown here, we can find the a t o m with the highest value of Di at the visible point and use its surface properties.
3.5 Optimizing the Algorithm
F o r images containing m o r e t h a n a few a t o m s (up to 4000 in s o m e of the images required for this project), the s u m m a t i o n of the D function over all the a t o m s is c o m p u t a t i o n a U y out of the question. Fortunately, for a n y given pixel, m o s t of the
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
245
Fig. 9.
atoms are sufficiently far away from the scan ray so that their contribution to the D function is negligible. We can therefore economize considerably by using in calculations only those atoms which are "close" to the scan ray. The term "close" is given precise meaning by enclosing each atom in a sphere defined by
Di (x, y, z) = tT,
where the value t is the same error tolerance used as the convergence criterion. If the scan ray intersects this sphere, there must be points along it where the contribution to D is large enough to matter. If, on the other hand, the scan ray is disjoint from the enclosing sphere, then all points on it contribute less than the error introduced by the termination conditions of the numeric solution. The atom can then be skipped. T h e value of the error tolerance, of course, determines the quality of the image. A larger tolerance will be faster but the image will have some noise added. Figure 9 shows the results obtained with different values of t. The halo around each example indicates those pixels covered by the enclosing spheres of the atoms. The errors in the surface begin to be apparent with t = 0.03. T h e y show up initially as a crease through the highlight at the top of the shape. T h e process of maintaining a list of "close" atoms during the rendering is similar to that of maintaining a list of potentially visible polygons in more conventional poygon-rendering algorithms (or perhaps, more properly, maintaining a list of visible spheres in a sphere-drawing program). We begin with the outer (y) loop. To initialize the loop, the enclosing spheres of all atoms are projected into screen space and the maximum and minimum visible y values are computed. The exact mathematics for this is given in the next section. The atom list is then sorted on minimum y, forming the "y-enter" list. During the y scan loop we maintain an additional "y-active" list of all atoms whose enclosing sphere includes the current scan plane. Additions to and deletions from this list are done incrementally each time through the loop. T h a t is, each
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
246
J . F . Blinn
OLD Ys NEW Ys
A, B, C, D, E, F
Fig. 10.
y-enter~y-active lists.
t i m e ys is i n c r e m e n t e d the top e l e m e n t on the y - e n t e r list is examined. If it is now a b o v e the new ys it is m o v e d to the y-active list and the next e l e m e n t on the ye n t e r list is examined. W h e n the top of the y - e n t e r list is below the new y8 t h e n we k n o w t h a t all entering a t o m s h a v e b e e n added. N o w examine the y-active list for deletions. T h e ymh of each a t o m on the y-active list is tested against the new y~, and if it is a b o v e it the e l e m e n t is removed. See Figure 10. Inside the y loop t h e r e is an x loop which goes across the screen. H e r e we m a i n t a i n an x-active list with the candidates coming f r o m the y-active list. T h i s is done in a m a n n e r exactly analogous to the y loop. For each e l e m e n t in the yactive list the enclosing sphere is projected onto the screen and the m a x i m u m a n d m i n i m u m x value is computed. T h e y-active list is t h e n sorted on Xmin and b e c o m e s the x-enter list. Since the y-active list is in fact identical to the x-enter list it is always k e p t in x-sorted order, f r o m scan line to scan line. Any additions are m e r g e d into the list using an exchange sort. As the scan progresses f r o m left to right the x - e n t e r list is e x a m i n e d for entering a t o m s to add to the x-active list. T h e x-active list is t h e n scanned for a n y exiting atoms. See Figure 11. At this point we have, for a given pixel, a list of all a t o m s whose enclosing sphere intersects the c u r r e n t scan r a y t h r o u g h t h a t pixel. T h i s list r e p r e s e n t s a significant culling of the totality of a t o m s to j u s t those which are r e l e v a n t to the
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
247
x-enter~x-active lists.
FIRST
SECOND
THIRD
~
A I B I I I I c D
A, B C, D
current pixel. T h e r e is one more level of culling available, however. This is in the z direction. In Section 3.3 we described the technique for finding an initial point for the iterative solution as a scan from front to back t h r o u g h a z-sorted list of potential solution points. If, prior to this zscan, we calculate the Zmin//Zmaxvalues of the intersections of the enclosing spheres with the scan ray, we can maintain a z-active list as the zscan progresses. In this case, the z values examined for entering/exiting tests are not equally spaced integer values as in the x and y cases. T h e y are instead taken one at a time from the potential z list. This does not alter the basic principle, however. See Figure 12.
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
248
J.F. Blinn
4,;
tg ~4
'J
W h e n we p e r f o r m the iteration loop t h e n the s u m m a t i o n of the Di will be t a k e n over only those a t o m s close enough to the initial guess to m a t t e r . For example, for the image containing over 4000 a t o m s {Figure 13), t h e r e were at m o s t 6 a t o m s on the z-active list for the iteration and usually m u c h less.
3.6 Calculating the Range in x, y, and z
In this section we explicitly indicate how to calculate the x, y, and z extents of the enclosing sphere of an a t o m . Such enclosing spheres are defined, as described in Section 3.5, b y the equation
t T = Di = exp(-air~
- Bi).
T a k i n g the l o g a r i t h m (and recalling t h a t T = 1), we t r a n s f o r m this into the e q u a t i o n for a quadric surface
0 = air~ + (Bi + in t).
T o calculate ZmjZmax for the range test of the zscan, we substitute the expression for r~ in t e r m s of z:
0 = a i [ ( R . R )(z - Zmi) 2 + Mi] + (Bi + in t)
a n d solve for z:
Zmin
Zmax
~
~
Zmi Zmi
-"~
Dz Dz
where
x / a i M i + B i + In t
T h e r e will be two roots to this as long as the expression u n d e r the radical is positive. T h e curve defined b y setting this equal to zero will t h e n define the
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
249
projection of the silhouette outlines of the enclosing sphere onto the screen:
aiM~ + Bi + in t = 0
S u b s t i t u t i n g the definition of Mi and Zmi we can t r a n s f o r m this into A{R.R}(R.Pi) 2=0 where
A= (Pi.Pi) + - -
Bi + In t ai
N o w for a particular scan line, y, is constant. We t h e n h a v e a quadratic equation in xz whose solutions give the range in xz for t h a t scan line. x2( A - x 2) + X z ( - 2 x i ( y z y i + zi)) + (h(yz2 + 1) - ( y z y i + z,) 2) = 0 T h e solutions to this equation (X, mm, X. . . . ) m u s t still be converted to pixel coordinates (X~mi,, X.... ) b y reference to eq. (*). T h e a b o v e equation will h a v e two roots at all values of yz for which its discriminant is positive. T h e values of yz for which this discriminant becomes zero therefore yield the m a x i m u m and m i n i m u m yz for which the enclosing sphere is visible.
4x~(y~yi+zi) 2-4(A - x~) ( A ( y z2 + 1) _ ( y ~ y i + z,) 2) = 0
Again, the two solutions for yz f r o m this equation m u s t be converted to pixel coordinates via eq. (*). In b o t h the x and y cases, the pixel range for the enclosing sphere m u s t be intersected with the pixel range of the display. T h i s effectively m e a n s t h a t we are p e r f o r m i n g clipping in screen space. If the range of the sphere is completely outside the screen t h e n it can be eliminated entirely.
4. T I M I N G
T h e rendering algorithm, while m a k i n g some quite interesting shapes, is not terrifically fast. In an effort to see where the time is spent within the algorithm it was i n s t r u m e n t e d for timing m e a s u r e m e n t s . T a b l e 1 shows the results for the calculations involved in generating Figure 14, containing 64 atoms. Again, the halo a r o u n d the molecule r e p r e s e n t s the enclosing spheres of the a t o m s and indicates the pixel range over which calculations are made. N o t e t h a t even t h o u g h the y s c a n and x s c a n routines take quite a while (since t h e y h a v e to deal with larger active lists), their net contribution to the running t i m e is small since t h e y are called only once per image and once per potentially occupied scan line, respectively. T h e zcalc routine is where the values of zm,, M~, and so forth, are calculated for all the a t o m s on the z-active list. T h i s is w h a t t a k e s m o s t of the time. P a r t of the reason for this is not so m u c h the a m o u n t of t i m e s p e n t in the routine as the v e r y large n u m b e r of times it is called. It is called once for each pixel covered by a n y enclosing sphere, while the iteration and shading routine are called once per actually occupied pixel. W e also p r e s e n t h i s t o g r a m s of the sizes of the active lists for each of the nested scans. E a c h bin of the h i s t o g r a m counts the n u m b e r of times a given size of active
ACM Transactions on Graphics, Vol. 1, No. 3, J u l y 1982.
250
J. F. Blinn
Fig. 14.
S a m p l e i m a g e for t i m i n g test.
list is passed to the routine. N o t e that, due to the culling process, the iteration and shading routines were usually called with active lists of length 3 or less. See Figure 15 (pages 252-253).
5. HIERARCHICAL MODELING
T h e i m p l e m e n t a t i o n of this algorithm was done on a PDP-11, which allows limited address space for user programs. T h e r e is not enough user m e m o r y for a program which does b o t h the modeling and rendering for systems of atoms of the size desired. Accordingly the process is divided into two programs which communicate via a t e m p o r a r y file. This file is, in fact, just the y-enter list sorted on ymax for the enclosing volume of each atom. A general purpose modeling program accepts c o m m a n d s controlling the positioning and blobbiness p a r a m e t e r s of atoms, global lighting, viewing parameters, and so forth. It t h e n writes out the sorted y-enter list into a t e m p o r a r y file. T h e rendering program t h e n reads in this file, a t o m b y atom, as the scan proceeds down the screen. This frees the rendering p r o g r a m from any restrictions on the total n u m b e r of atoms visible. It needs only to read one a t o m ahead of itself in the y-enter list Erie to be able to tell when the next a t o m is to enter the y-active list. Internally it maintains only the y-active list and thus has restrictions only on the m a x i m u m n u m b e r of atoms visible on any one scan line. (This technique has also been used by the a u t h o r in polygon-
251
rendering programs and bicubic patch-rendering programs, the lists in those cases being of polygons or patches.) T h e r e are still some limits on the m a x i m u m n u m b e r of atoms which the modeling program can maintain. T h e s e can be relaxed by inserting a separate sorting module between the modeler and the renderer. T h e modeler t h e n does not need to be able to store all the atoms in a scene. It just concerns itself with c o m m a n d line interpretation, setting parameters, and transforming atoms to viewing space. It writes out the atom list as it reads it from a molecule definition file. T h e sorter t h e n is a small program with a large array. It reads the y-enter list file, sorts the data, and writes it out again. For the purposes of modeling large polymerized molecules (like DNA) an alternative hierarchical modeling scheme was employed. Polymers are made up of a large collection of a few basic modules. For D N A these modules are the four nucleotides and a few free radicals used to simulate the replication process. Each module is modeled as a rigid body at an arbitrary position and orientation. T h e definition of a module lists its constituent atoms and the radius of an enclosing sphere for the entire module. W h e n an image is to be made, the modules are first sorted in an order based on the m i n i m u m y+ of their enclosing spheres. T h e n a scan is made in the y direction to generate the entire y-enter list of atoms directly in sorted order. For each new y, value the y-module list is examined to see if any modules have become active. W h e n a module becomes active it is expanded into its constituent atoms which are t h e n transformed into viewing space according to the module's orientation and position. T h e s e atoms are added to a candidate yenter pool. W h e n all newly activated modules have been expanded, the candidate y-enter pool is examined. Any atoms which have actually become visible on the scan line are written to the y-enter file. T h e advantage of this process is that the candidate y-enter pool never gets very large and can therefore handle large structures.
6. EXTENSIONS
T h e initial algorithm was devised for a special purpose task. We examine here some simple generalizations of the process to give a wider range of shapes which can be modeled.
6.1 General Quadric Seeds
One obvious extension to the shapes defined so far is to provide for nonspherical primitive shapes. Recall the original defining equation consisted of terms
exp(-air~ - Bi).
yi) 2 + (z -
z i ) 2) - B i
0
1 0
-Yi
0-xtrx 1
0
-zi
= (xyzl)(-ai)
-Y, l l Y l -Z/l/Z /
xi
PJL 1 J
252
J.F.
Blinn
30
--
< U
20
--
10
--
2 4
81012141618202224262830323436
11
10
.<
--
O
:2:: I--v
,q, 6
U I.l_
5 4
::D
3 2
1
0 1 2 3 4
I
5
Fig. 15.
Figure 15 continued on next page. ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
A Generalization
of Algebraic
Surface
Drawing
253
11
10
---
9 Z
<
--
"rl-v
6
(.9 u_
---
0 4. 3 2 -
j h.
6 7
9 LIST
N U M B E R O F ELEMENTS I N X - A C T I V E U P O N E N T R Y TO Z - S C A N
10 9
C~
---
8 7
-----
.<
"r"
6
..J U it.
5 4 3
z 2
0 2 3 4 5
254
J . F . Blinn
where p = x ~ + y i2 z ~ + -Bi ~ + l -. ai B y allowing general quadrics here, we can have ellipsoids, cylinders, planes, and so forth, as modeling primitives. This is done by beginning with a canonical unit sphere at the origin defined by
0 = (xyzl) 0
0 -Bi 0
0 0 ijlil
0
-Bi
T h i s is t h e n scaled, rotated, and translated to the desired location by the standard transformation techniques for quadrics [1], t h a t is, multiply on the left by the inverse of the transformation matrix and on the right by the transpose of the inverse.
Q ' = T - 1 Q T -it
T h e r e a d e r can verify t h a t b y scaling the matrix by R i and translating it to (xi, yi, zi) one obtains just the special case formulation we used above for pure spheres. T h e generalization of most of the other equations in the preceding discussion can be p e r f o r m e d by making the following replacements:
ai(R.R) ai(Pi. R ) ai(Pi.Pi) + Bi
RQ'R t
.~Q,~t WQ'V~ rt
A sample picture appears in Figure 16. For shapes of infinite extent, such as cylinders, the calculation of m a x / m i n values in x, or ys m a y yield an infinite range. This occurs when there are no solutions to the range determining quadratic equations of Section 3.6. T o handle these situations properly we must recall t h a t we are solving these equations not so m u c h to find their zeros as to find the region where the quadratic polynomial is positive (since its square root is required later). In the general case this m a y yield one finite span (for ellipsoids), one infinite span (the axis of a cylinder) or two semiinfinite spans (hyperboloids). With proper care in examining the polynomial these cases can be readily distinguished.
A C M T r a n s a c t i o n s on Graphics, Vol. 1, No. 3, July 1982.
255
Fig. 16.
Another extension is to allow negative values for bi. This effectively gives negative volumes. T h e y are not visible themselves, but when placed near normal objects they make dents. This is because their density contributions are being subtracted from the summation. A sample image appears in Figure 17. In fact, with some adjustments to the algorithm it should be possible to allow complex values for the bi. This would prove useful for molecular simulations since quantum wave functions are actually complex valued functions. We could therefore represent antibonding orbitals.
6.3 Hyperellipsoids
A more general surface shape can be provided by allowing exponents other than 2 on the terms of the exponent.
ACM Transactions on Graphics, Vol. 1, No. 3, July 1982.
256
J.F. Blinn
6.4 Other Bump Functions The final extension considered here involves alterations to the exponential function. We can use any shape that has the same general form. In fact, the implementation of the algorithm here uses a table lookup procedure with interpolation for rapid evaluation of the exponential function. By placing different values in the table we can easily change the shape of the bump function. Care should be taken not to defeat the heuristics for the selection of initial guesses for the numerical solution. Basically the function must equal 1 at f(0) and increase monotonically over the range used.
7. CONCLUSIONS
We have presented an algorithm which simultaneously models and renders a class of surfaces which have an interesting visual appearance and should prove useful for a variety of applications. Some simple extensions to this process show promise of generating other interesting shapes. All raster scan image synthesis algorithms must address the problem of antialiasing (e.g., area sampling). Algorithms based on algebraic surfaces are fairly entrenched in point sampling. This creates problems mostly at silhouette edges since the main body of the surface shape does not have any high frequencies to alias. No explicit anti-aliasing has yet been attempted on the images presented here. This would be a fruitful topic for further research.
REFERENCES
1. BLINN, J.F. Geometric representations in computer graphics. Workshop on representation of three-dimensional objects, Univ. of Pennsylvania, Philadelphia, Pennsylvania, May 1979. 2. CATMULL, E.E. Computer display of curved surfaces. In Proc. of the Conf. on Computer Graphics, Pattern Recognition, and Data Structure (Los Angeles, Calif., May 14-16), 1975, IEEE, New York, pp. 11-17. 3. CLARK, J.H. A fast scan-line algorithm for rendering parametric surfaces. Unpublished. 4. DUFF, T. The soid and roid manual. New York Institute of Technology, Sept. 1980. 5. GOLDSTEIN, E. AND NAGLE, R. 3D visual simulation. Simulation 16, 1 (Jan. 1971), 25-31. 6. KNOWLTON, K. AND CHERRY, L. Atoms, a 3D opaque molecule system. Comput. Chem. 1, 3 (1977), 161-166. 7. LANE, J.M., CARPENTER, L.C., WHITTED, T., AND BLINN, J.F. Scan line methods for displaying parametrically defined surfaces. Commun. A C M 23, 1 (Jan. 1980), 23-34. 8. MAX, N.L. Atom LLL:--Atoms with shading and highlights. Computer Gr. 13, 2 (Aug. 1979), 165-173. 9. PORTER, T. Spherical shading. Computer Gr. 12, 3 (Aug. 1978), 282-285. 10. ROTH, S. Ray casting as a method for solid modeling. Comput. Gr. Image Process 18, 2 (Feb. 1982), 109-144.