A Scan Line Algorithm for Computer Display of Curved Surfaces

6
A SCAN LINE ALGORITHM FOR COMPUTER DISPLAY OF CURVED SURFACES Turner Whitted Department of Electrical Engineering North Carolina State University Raleigh, NC 27650 Abstract The conventional procedure for generating shaded images of curved surfaces is to approximate each surface element by a mosaic of polygons and to then apply one of several established polygon display algorithms. The method described here produces an excellent approximation of bi-cubic parametric surfaces in scan line order. Each surface patch is described in terms of edge curves which are intersected by successive scanning planes to form endpoints of scan line segments. Visibility is calculated for each segment by a hybrid priority/z- buffer scheme. Shading is computed using Phong's illumination model with interpolated surface normal values. CR Categories: 8.2. Introduction Most scan line algorithms for shaded display [1-3] can be applied only to polygonal objects. Curved surfaces are approximated by collections of many small polygons which may be smooth shaded via techniques developed by Gouraud [4] and Phong [5] to produce images of good quality except along the object's silhouette. Algorithms by Mahl [6] and MAGI [7] display quadric surfaces directly, but such surfaces cannot be smoothly joined to form arbitrary shapes. The curved surfaces of greatest general interest are bi-cubic parametric surfaces such as Coons, Bezier, or B-spline patches. Catmull's subdivision algorithm [8] produces images directly from bi-cubic surface descriptions, but requires a frame buffer since it does not proceed in scan line order. This paper describes a technique for directly rendering a shaded display of bi- cubic surfaces in scan line order. The process yields an approximation to the actual surface that is superior in most respects to polygonal approximations. Any scan line display process must intersect a three-dimensional object with a series of horizontal planes spaced so that each plane corresponds to a raster line on the display device, a process called scan conversion. The intersection of one of these planes with the object's surface is a series of line segments in the scanning plane. To generate a scan line from these segments a shader assigns inten- sity values to each pixel lying along the projection of the visible portion of the segment. If the surface is polygonal, each *This work was supported by Grant MCS75- 06599, Div. of Computer Systems Design, National Science Foundation. segment is a straight line which can be uniquely determined by the intersection of the polygon edges with the scanning plane. If a bi-cubic surface is to be dis- played the intersection and shading problems become more difficult. Calculating a single point of intersection between the curved patch and the scanning plane requires the simultaneous solution of two equations, each of which are cubic in two unknowns. The central idea of the algorithm presented here is to avoid these difficult calculations altogether while rendering a reasonably accurate picture of the curved object. As in the polygon display algorithms, each surface element is described in terms of its edges (in this case cubic curves) which are passed to a scan conversion processor to form the endpoints of scan line segments. This approach fails, naturally, if the sur- face element contains a silhouette on its interior or if it is excessively curved. To circumvent this problem the processor that generates edges also detects silhouettes and divides the patch along the silhouette curve. If a patch is excessively curved, the edge generator can produce additional curves on the interior of the patch to im- prove the accuracy of the image. These preprocessor stages, which may be regarded as "scene preparation", are tailored to the specific type of surface rendered. As out- lined in Figure 1, the preprocessor is followed by a scan conversion processor and the shader. Edge Description of Patches Bi-cubic surface patches are defined by the expression f(u,v)=[ 3 u 2 u 1] M P MT [v 3 v 2 v 1] for u,v e [0,1]. P is a matrix of "control 8

Transcript of A Scan Line Algorithm for Computer Display of Curved Surfaces

Page 1: A Scan Line Algorithm for Computer Display of Curved Surfaces

A SCAN LINE ALGORITHM FOR COMPUTERDISPLAY OF CURVED SURFACES

Turner WhittedDepartment of Electrical EngineeringNorth Carolina State University

Raleigh, NC 27650

Abstract

The conventional procedure for generating shaded images of curved surfaces is

to approximate each surface element by a mosaic of polygons and to then apply

one of several established polygon display algorithms. The method described

here produces an excellent approximation of bi-cubic parametric surfaces in

scan line order. Each surface patch is described in terms of edge curves which

are intersected by successive scanning planes to form endpoints of scan line

segments. Visibility is calculated for each segment by a hybrid priority/z-

buffer scheme. Shading is computed using Phong's illumination model with

interpolated surface normal values. CR Categories: 8.2.

Introduction

Most scan line algorithms for shadeddisplay [1-3] can be applied only topolygonal objects. Curved surfaces areapproximated by collections of many smallpolygons which may be smooth shaded viatechniques developed by Gouraud [4] andPhong [5] to produce images of good qualityexcept along the object's silhouette.Algorithms by Mahl [6] and MAGI [7] displayquadric surfaces directly, but such surfacescannot be smoothly joined to form arbitraryshapes. The curved surfaces of greatestgeneral interest are bi-cubic parametricsurfaces such as Coons, Bezier, or B-splinepatches. Catmull's subdivision algorithm[8] produces images directly from bi-cubicsurface descriptions, but requires a framebuffer since it does not proceed in scanline order.

This paper describes a technique fordirectly rendering a shaded display of bi-cubic surfaces in scan line order. Theprocess yields an approximation to theactual surface that is superior in mostrespects to polygonal approximations.

Any scan line display process mustintersect a three-dimensional object witha series of horizontal planes spaced sothat each plane corresponds to a rasterline on the display device, a processcalled scan conversion. The intersectionof one of these planes with the object'ssurface is a series of line segments in thescanning plane. To generate a scan linefrom these segments a shader assigns inten-sity values to each pixel lying along theprojection of the visible portion of thesegment. If the surface is polygonal, each

*This work was supported by Grant MCS75-06599, Div. of Computer Systems Design,National Science Foundation.

segment is a straight line which can beuniquely determined by the intersection ofthe polygon edges with the scanning plane.

If a bi-cubic surface is to be dis-played the intersection and shading problemsbecome more difficult. Calculating a singlepoint of intersection between the curvedpatch and the scanning plane requires thesimultaneous solution of two equations, eachof which are cubic in two unknowns. Thecentral idea of the algorithm presented hereis to avoid these difficult calculationsaltogether while rendering a reasonablyaccurate picture of the curved object. Asin the polygon display algorithms, eachsurface element is described in terms of itsedges (in this case cubic curves) which arepassed to a scan conversion processor toform the endpoints of scan line segments.This approach fails, naturally, if the sur-face element contains a silhouette on itsinterior or if it is excessively curved.To circumvent this problem the processorthat generates edges also detects silhouettesand divides the patch along the silhouettecurve. If a patch is excessively curved,the edge generator can produce additionalcurves on the interior of the patch to im-prove the accuracy of the image. Thesepreprocessor stages, which may be regardedas "scene preparation", are tailored to thespecific type of surface rendered. As out-lined in Figure 1, the preprocessor isfollowed by a scan conversion processor andthe shader.

Edge Description of Patches

Bi-cubic surface patches are definedby the expressionf(u,v)=[ 3u 2u 1] M P MT [v

3v2v 1]for u,v e [0,1]. P is a matrix of "control

8

Page 2: A Scan Line Algorithm for Computer Display of Curved Surfaces

Figure 1 Display system block diagram

points" and M is a matrix of coefficientsthat define the interpolating function forthe surface. Depending on the way that Mand P are defined, the surface element maybe a Coon's patch, Bezier patch, or B-splinepatch. B-splines are used in all examplesshown here. These patches have four natural"edge" curves: Eo=f(u,O), El=f(O,v), E2=f(u,l), and E3=f(l,v), each of which iscubic in one variable. If, as in the caseof excessively curved patches, it is neces-sary to specify additional "edges" on theinterior of the patch, these edges (para-metric curves on the surface) are also cubiccurves of one variable, defined by either

Ev=f(ku,v) or Eu=f(u,kv).

The addition of two such interior edges,specified by ku=0.5 and kv=0.5, has theeffect of dividing the patch into foursubpatches, as shown in Figure 2.

Figure 2

A third type of edge is the patch sil-houette, i.e., the curve on the surface forwhich the z component of the normal vectoris zero. In general, the order of the sil-houette curve is greater than cubic, but it

is approximated here by a piecewise cubicinterpolant so that the silhouette can betreated the same as any other edge. If thesilhouette curve passes through a patch,f(u,v), there are two points, (ua,va) and(ub,vb), each on an edge of the patch suchthat Nz(ua,va)=O and Nz(ub,vb)=O where Nzis the z component of the normal vector.At each of these points a plane tangent tothe surface is defined by the two vectorsaf/3u and 3f/3v. Since any vector tangentto the surface must lie in this plane, thederivative of the silhouette curve can beexpressed as a linear combination of thetwo vectors that define the plane. Then, ahermite interpolant joining the two end-points can be specified by

The accuracy of the resulting silhouettecurve depends on the number of cubic seg-ments used in the piecewise approximationand on the choice of the a and $ terms.Since each cubic segment spans the areabetween endpoints on the edges of a patch,the specification of additional edges on theinterior of the patch containing the sil-houette will improve the result. After thepatch is subdivided by adding internal edgesthe silhouette generator examines each sub-patch in turn to see if its edges areintersected by the silhouette and producesan approximating segment that spans the twoendpoints. This approach to approximatingthe silhouette is similar to the one des-cribed in [9]. If the silhouette crossesthe boundaries of a subpatch just once, ormore than twice, or crosses any one boundarymore than once, of it it is contained en-tirely within the subpatch, then the

9

Page 3: A Scan Line Algorithm for Computer Display of Curved Surfaces

silhouette generator defaults and an erroroccurs on the visible portion of that sub-patch.

The choice of a and B terms in theinterpolation formula determine both thedirection and magnitude of the endpointderivative vector. Since excessivelycurved patches are typically subdivided bythe insertion of internal edges, one mayassume that each subpatch examined by thesilhouette generator is reasonably close toplanar. Then a very simple approximationwill suffice for a and a.

Then the first expression can be rewritten

To adjust for the arclength of the inter-polant

Figure 3 shows the resulting silhouetteapproximation superimposed on a set ofsectional curves.

Figure 3

10

The definition of a cubic edge requires12 coefficients: four each for the x, y, andz components. In addition, surface normalinformation along each edge must be provi-ded for use by both the shader and thesilhouette detector. If only an ortho-graphic view is required in the final dis-play, all of the required information canbe obtained from the coefficients of thederivative with respect to the constantparameter* along each edge. The derivativewith respect to the variable parameter (thecurve's tangent vector) can be derivedreadily from the curve coefficients. Thecross-product of these two derivatives yieldsan exact normal at each point on the edge.

Ordinarily a perspective view isrequired. A technique described by Catmull[8] uses a bi-cubic equation to approximatethe normal vector on the surface, yieldinga cubic normal function along each edge.The perspective view of the surface isgenerated by transforming the controlpoints for the surface and using theresulting control points to form an approx-imation to the transformed bi-cubic surface.The bi-cubic normal approximation is notpassed through the perspective transformsince proper shading depends on preservingthe object space illumination direction.Use of the approximate normal function hasthe added advantage of speeding the scanconversion process since it is not neces-sary to calculate cross products at everyintersection point on an edge to find thesurface normal. Edges are stored in a y-sorted list of modules, each containing 24coefficients (12 for the edge curve and 12for the cubic normal approximation). Asnoted before, the inclusion of interioredges effectively subdivides the surfaceelement into smaller and more nearly planarsubpatches. There are interesting dif-ferences between this approach and the sub-division of patches for approximation bypolygons. Figure 4a shows a polygonalapproximation of a bi-cubic patch createdby evaluating the patch equation at 25equally spaced vertex points. Assumingthat the patch is surrounded by fourneighbors with which it shares vertices and

Page 4: A Scan Line Algorithm for Computer Display of Curved Surfaces

edges, the number of vertices per patch is16 and the number of edges is 32. Eachvertex is defined by six coefficients(three for position and three for the sur-face normal) and each edge descriptionrequires two pointers (one to each of theendpoint vertices). The total number ofwords required per patch is 160. Figure 4bshows the same patch in terms of itsboundary curves and six internal edges.Assuming that the boundaries are shared,the total number of edges per patch is 8,requiring 192 words of memory. In general,if a patch is subdivided M times in the udirection and N times in the v direction andrepresented by quadralateral polygons, thenumber of edges required is 2MN per patch.For the same level of subdivision, only M+Ncubic edges are required. (For Figure 4M=4 and N=4.) Furthermore, every cubicedge lies entirely on the surface (exceptfor the silhouette approximation) whereasif a polygonal approximation is used, theedges coincide with the surface only at thevertices.

Intersection Processor

The intersection (scan conversion)processor is the heart of this algorithm;it operates on the edge list and outputsscan line segments in reverse order ofvisibility.

The first stage of the procedureexamines each edge to insure that it ismonotonic in y, segmenting those that arenot, and avoiding the problem of findingmultiple intersections of the edge with asingle scan line. The presence of extremaalong an edge can be detected rapidly byexamining the coefficients of the y com-ponent of the edge curve, and since thederivative of the curve is quadratic, theirlocation is found using the quadratic for-mula to solve for zeros of the derivative.

The equation E (t)=yn, where Yn is they value of scan line number n and Ey(t) isthe component of the edge curve, is solvedusing Newton's iteration to yield tn. Inturn, Ex(tn), Ez(tn), and the components ofthe normal vector at that point on the edgeare computed. Making use of scan linecoherence, a first order estimate of thesolution for the next scan line,

results in rapid convergence of the nextsolution, usually in the first iteration.Because t is restricted to the [0,1] in-terval, Newton's method will occasionallyfail to converge. In this case the scanconversion routine resorts to a brute forcesearch for the solution.

Because internal edges and concavitieslead to multiple pairs of intersectionpoints, edges of a given patch must besorted into ascending x order to insure thegeneration of proper segments. Note thatthis is a relatively cheap sort since apatch is typically intersected only a fewtimes on any given scan line. As eachsegment is formed, it is inserted into a

11

depth ordered list of all segments for thecurrent scan line. In the interest of highspeed processing, the depth separator testis limited to comparing the average depthof segment endpoints to establish thepriority of segments. The test is performedin two dimensions instead of three and in-volves only scan line segments rather thanentire objects or patches. Z ordering ofthe segments is included to enable thesimulation of transparency, but it can beeliminated if only opaque surfaces areconsidered, since final visibility isestablished by z-buffer comparisons thatare incorporated into the shader.

Shader

The shader operates on the list ofscan line segments, assigning intensityvalues to the pixels spanned by each seg-ment. With the segment list stored inreverse depth order, the shader can overlaysegments into a pixel buffer in the mannerof Newell's algorithm [2], but since thedepth separator test does not always yieldthe correct result, a z-buffer is includedfor point-by-point visibility comparisonsas in Myer's algorithm [3]. The z value ofa scan line segment is linearly interpola-ted between endpoints. If two patchesintersect, a piecewise cubic approximationof the curve of intersection should beincluded in the list of edges since point-by-point comparison between linearlyinterpolated z values will not usuallyyield a smooth curve of intersection. (Thecurrent preprocessor has no provision forgenerating the approximate intersectioncurves.)

Intensity calculations are performedby the method described by Phong [5] inwhich the normal vector is linearly inter-polated between endpoint values. Theshading function used is

where N is the surface normal, R is thespecular reflection vector, I is theincident light vector, and T is the trans-mission coefficient (equal to zero foropaque objects). The function f(N)=(l-Nz2 )is used to create an illusion of thicknessin transparent surfaces by attenuating thebackground in silhouette regions. Trans-mission coefficient, hue, and glossinessare stored in tables that are indexed bycodes stored in the patch description,allowing each patch to have a differentset of attributes. The constants shown inthe shading equation have been chosenthrough a process of trial and error.

Implementation

The display algorithm is implementedas a series of modules written in Fortranand assembly language on an Adage AGT-30computer. Display is on a standard 19"color television refreshed from an analogvideo disc. A specially designed interfaceallows the computer to write an image on

Page 5: A Scan Line Algorithm for Computer Display of Curved Surfaces

the disc one scan line at a time. Thesedisplay routines are part of an experimen-tal graphics animation display system(EGADS) being developed at North CarolinaState University.

The modular construction of the soft-ware allows the use of several configura-tions for different applications. For thepictures of Figures 5 and 6, each objectwas processed separately and overlaid intoa frame buffer. Figures 7 and 8 weregenerated by applying the preprocessor andintersection stages to each objectseparately and then merging all scan linesegments into a large list. The entirelist of segments was then passed to theshader. Each object in these figures iscomposed of B-spline patches. Generationtimes for such simple scenes vary from twominutes to ten minutes, depending on theconfiguration of the processor, with theshader occupying about 80% of the CPU time.A new shader, currently being developed[10], will improve the processor's per-formance by a factor of at least two.

Figure 5Figure 5Summary

Figure 6

Figure 7

In the algorithm described here, thescan conversion process is performed onlyat the edges of surface elements; shadingand visibility calculations on the interiorof the surface are performed using inter-polated data. To insure the quality of thefinal image, additional edges may be addedalong silhouettes, intersections ofpatches, and on the interior of the patchif necessary. The use of edges to describethe surface elements allows the displayprocessor to operate only on univariatefunctions, resulting in a reasonably fastalgorithm. In a sense, this algorithmrepresents an extension of existing polygon-based display methods, but it overcomesmany of their shortcomings.

Figure 6

12

Page 6: A Scan Line Algorithm for Computer Display of Curved Surfaces

References

[1] Watkins, G.S. A real-time visiblesurface algorithm. UTEC-CSc-70-101,Computer Science Dept., Univ. of Utah,June 1970.

[2] Newell, M.E., Newell, R.G. and Sancha,T.L. A solution to the hidden sur-face problem. Proc. of the ACM Nat'l.Conf., 1972, pp. 443-450.

[3] Myers, A.J. An efficient visible sur-face algorithm. Computer GraphicsResearch Group, Ohio State University,July 1975.

[4] Gouraud, H. Computer display ofcurved surfaces. UTEC-CSc-71-113,Computer Science Dept., Univ. of Utah,June 1971.

[5] Bui Tuong Phong. Illumination forcomputer generated images. UTEC-CSc-73-129, Computer Science Dept., Univ.of Utah, July 1973.

[6] Mahl, R. Visible surface algorithmfor quadric patches. IEEE Trans. onComputers, Vol 21, p. 1, Jan. 1972.

[7] MAGI, Mathematical Applications GroupInc. 3-D simulated graphics. Data-mation, 14, Feb. 1968, p. 69.

[8] Catmull, E. A subdivision algorithmfor computer display of curved sur-faces. UTEC-CSc-74-133, ComputerScience Dept., Univ. of Utah, Dec.1974.

[9] Yoshimura, S., Tsuda, J., and Hirano,C. A computer animation techniquefor 3-D objects with curved surfaces.Proc. of the 10th Annual UAIDE meet-ing, 1971, pp. 3.140-3.161.

[10] England, J.N. and Whitted, J.T. Ahigh speed shader for color computergraphics. Signal Processing Lab,Electrical Engineering Dept., NCState University, unpublished report.

13