Adaptive Forward Differencing For Rendering Curves and Surfaces
Adaptive Forward Differencing For Rendering Curves and Surfaces
Abstract Introduction
An adaptive forward differencing algorithm is presented tot Parametric curves and curved surfaces are a common form
rapid rendering of cubic curves and bicubic surfaces. This of surface and object representation. In particular, non-
method adjusts the forward difference step size so that uniform rational b-splines have gained popularity for
approximately one pixel is generated along an ordinary or mechanical CAD applications. Since high speed hardware
rational cubic curve for each forward difference step. The capable of rendering vectors and polygons is widely avail-
adjustment involves a simple linear transformation on the able, high speed curve and surface rendering is usually done
coefficients of the curve which can be accomplished with by subdividing and rendering them as straight lines or planar
shifts and adds. This technique combines the advantages of polygons. For conics, non-parametric, incremental solutions
traditional forward differencing and adaptive subdivision. A of the implicit equations[7, 8, 3, 1] are well known and a few
hardware implementation approach is described including hardware curve generators have been built. Less progress
the adaptive control of a forward difference engine. Sur- has been made on hardware techniques for rendering higher
faces are rendered by drawing many curves spaced closely order curves and surfaces. Research has focused largely on
enough together so that no pixels are left unpainted. A sim- subdivision methods for rendering and modelling.J2,6]
ple curve anti-aiiasing algorithm is also presented in this Recursive subdivision for curve and surface rendering is
paper. Anti-aliasing cubic curves is supported via tangent expensive to implement in hardware due to the high speed
vector output at each forward difference step. The adaptive stack memory requirements and the fact that frame buffer
forward differencing algorithm is also suitable for software memory access is easier to optimize if the pixels are being
implementation. written to adjacent addresses.
Lane and others[5] developed scan line methods for render-
ing bicubic patches. They used Newton iteration to compute
CR Categories and Subject Descriptors: 1.3.5 [Computer the intersections of the patch with the plane of the scanline.
Graphics]: Computational Geometry and Object Modelling These approaches were not intended for, nor are they simple
- Curve, surface, solid, and object representations; enough for hardware implementation.
Geometric algorithms, and systems; 1.3.3 [Computer Our adaptive forward difference (AFD) technique is an
Graphics]: Picture/Image Generation - Display algorithms; extension of well known[4] ordinary forward differencing
1.3.7 [Computer Graphics]: Three-dimensional Graphics and is related to the adaptive subdivision methods in that it
and Realism - Color, shading, shadowing, and texture. adjusts the step size to the next pixel by transforming the
equation of the curve to an identical curve with different
Additional Key Words and Phrases: image synthesis, adap- parameterization. AFD differs from recursive subdivision or
tive forward differencing, parametric curves and surfaces. traditional forward differencing by generating points sequen-
tially along the curve while adjusting the parameterization to
give pixel sized steps. AFD allows ~t surprisingly simple
hardware implementation, and is compatible with frame
buffer memory interleaving for high performance.
Permission to copy without fee all or part of this material is granted This paper develops the theory of adaptive forward dif-
provided that the copies are not made or distributed for direct ferencing and covers several related aspects and problem
commercial advantage, the ACM copyright notice and the title of the areas.
publication and its date appear, and notice is given that copyingis by
permission of the Associationfor Computing Machinery. To copy 1) Reparameterization of cubic or rational cubic curves
otherwise, or to republish, requires a fee and/or specificpermission. 2) Drawing surfaces by spacing curves 8s apart
3) Generating anti-aliased curves
4) Trimming and image mapping on patches
© 1987 ACM-0-89791-227-6/87/007/0111 $00.75
111
~,,~4 SIGGRAPH '87, Anaheim, JuDy 27-31, 1 9 8 7
Principles
The method of adaptive forward differencing unifies the LLC RLC LRC RRC
(a)
processes of recursive subdivision and forward differencing.
In this section we present the principles underlying the
method. The key insights are that these processes axe both
instances of linear substitution, and that efficiency is optim-
ized by a choice of basis appropriate to the mix of substitu-
tions. LC ~- RC
We consider curves and surfaces in a space S, taken for the
sake of illustration to be R4 (homogeneous coordinates
x,y,z,w). A parametric object in S is a function f :X-~S
where X is a set constituting the p a r a m e t e r space. T h e LRC ~ RRC
object is a curve, segment, surface, or patch when x is
respectively the set R of reals, the real interval [0,1], the real
(b)
plane R 2, or the unit square [0,1]2. We take s and t for the Figure 1. Relationship of linear substitutions L, R, and E.
parameters, making f either f (t) or f (s ,t ).
A linear substitution transforms f (t) into f (at+b) and f (s,t) avoids this difficulty by stopping at different depths in dif-
into f(as+b,et+d), expressible as the composition o f f with a ferent parts of the reeursion tree. We may transfer this
linear or bilinear function respectively. The geometric effect advantage of recursive subdivision to forward differencing
of linear substitution is to translate and scale a segment or by inserting an occasional L or L -~ (the substitution 2t) into
patch within the curve or surface containing it. Any segment the stream of E ' s whenever the velocity is too great or too
of a curve can be mapped to any other segment of the same small respectively. This has the effect of changing our level
curve by some linear substitution, and likewise for patches. in the recursion tree as we forward-difference across it. We
Let us denote by L the linear substitution t/2 and by R the call this technique adaptive f o r w a r d differencing.
linear substitution (t+l)r2. Then L and R act on a segment C In order to implement the above we require concrete
to yield the " l e f t " and " r i g h t " halves LC and RC of C. representations for C, L, E, etc. We do this in the usual way:
These are the transformations associated with recursive sub- independently for each dimension of s take C to be a poly-
division; they may be applied recursively to subdivide a nomial in t (and s), regard the polynomial as a point in a
curve segment into quarters LLC,LRC,RLC,RRC (Figure l(a)), vector space of dimension one more than its degree, regard
eighths, etc. linear substitutions as a particular kind of linear transforma-
Let us denote by E the linear substitution t+l. Then E acts tion of this space, and perform the transformations in an
on a segment C to yield its "right neighbor" EC. One use appropriate basis for the space. One key property of linear
for E is as the forward difference operator. To render a long substitution is that it does not increase polynomial degree,
segment C, start with a very small initial segment D of C the other is that its action on a polynomial viewed as a vector
(e.g. D=LL.--LC) and generate the remaining (also small) is indeed that of a linear transformation.
segments of C by El) ,EED ,EEED, •. •. This process is usually While any basis will do, certain bases favor certain transfor-
called forward differencing. mations. For example the total number of l ' s in the binary
Another use for E is as a substitute for R in recursive subdi- representation of a particular transformation may be quite
vision: we may represent R as EL, as illustrated by the top small in a particular basis, permitting the transformation to
half of Figure l(b). However, rather than computing LC and be carried out with just a few shifts and adds. Catmull [2]
RC separately we can compute LC once and then apply E to gives a basis for which L and R can be cheaply computed
LC to get the right h a l l allowing us to discard C after apply- with only three adds and four shifts.
ing L to it and so avoiding a "stack pop" when the time
comes to apply R. The lower half of Figure l(h) shows that
this can be extended down another layer of recursion: we can
get to RLC, LRC, and RRC by starting from LLC and repeat-
Lc = 1 o o, 8]
0 1/4 0 00
1/2-1/8 1/2
edly applying E, thanks to the additional identity ER = LE 0 1/8 0
(i.e. EEL = LE) which allows E to make the jump from RLC to
LRC. This ability of E to run across the whole tree holds at
any depth. At sufficient depth the method turns into ordinary
forward differencing as per the previous paragraph.
A disadvantage of forward differencing is that it may not
traverse C with uniform velocity. Recursive subdivision
Rc =
[i 71
1/2-1/8 1/2
1/8
0
0
0
1
0
1
l/4J
112
(~ ~ ComputerGraphics, Volume21, Number4, July 1987
B 1
A C D ] >
0 0
Figure 2. Block diagram of an A F D unit.
However, for forward differencing neither Catmull's basis Four AFDUs can be used to generate the x,y,z,w values of
for L and R nor any of the other bases usually considered for the pixels along a cubic curve. Figure 3 shows the 4
recursive subdivision are particularly well suited to the required AFDUs and the divide by w circuit necessary for
matrix representation o f E. The best basis for E is the for- rendering rational curves. The filter unit is the controller for
ward difference basis which allows parallel additions suit- the adaptive step size, and performs other functions.
able for a pipeline implementation.
x/~
r
y/w To
B3 : l (t3-3t2+2t) = 6 t ( t - 1 ) ( t - 2 ) - Frame
Pixel
Y AVOUI Filter z/w
Buffer
B 2 = ~1( t 2- t ) = ' ~1- t ( t - l )
Bl=t
Arc length
Z AFDU I
B0=I
The E matrix of this basis requires only three adds which can Figure 3. Block diagram of the A F D hardware. Each AFDU
be done in parallel. computes a 3rd order parametric function.
E= Ii°ll 1. R e p a r a m e t e r i z a t i o n
A parametric cubic function f(t) can be represented in for-
ward difference basis as
The L and L < matrices can be implemented with simple f = aB 3(t)+bB20)+cB ~(t )+dB o(t)
shifts and adds. A cubic curve is defined by four cubic functions x(t), y(t),
z(t), and w(t), each implemented by a separate A F D unit.
L= Ii00o /i001104
1/2-1/8 1
0 1/4 -u81
o 0
L-l=
t/sJ o o
x (t) = axBB+b:,B2+cxB l+d,B o
y (t ) = ayB3+byB2+cyB l+dyB o
113
• SIGGRAPH '87, Anaheim, July 27-31, 1987
I ~ ~ 1
z'(t)=2(2)
w'(t)=w(-~) adjusted u p / ~ _ .
1 1. 1
c p = --~c-gO+--~a W e have measured the percentage of steps requiring an
adjust up or adjust down using the Utah teapot at various
d'=d
scale factors. Drawing the cubic curves comprising a wire
TO double dt, we transform the cubic functions by applying mesh on the blcubic patches making up the surface involved
the L -1 matrix: 73,000 forward steps, and 600 adjustment steps. The over-
head for the adaptive nature of the forward difference
x'(t) =x(2t)
scheme is therefore quite small. It increases when the curves
y'(t)= y(2t) being drawn have large accelerations.
z'(t ) = z (2t)
2. I n i t i a l S e t u p
w "(t ) = w (2t)
To render a cubic curve C we first convert to the forward
Here the coefficient transformation is difference basis. W e then start with a small initial segment
a" = 8a D of the curve by applying Ln=L.L .......L to the curve C. The
initial scale down is not really required. However, if not
b" ---4b +4a done, the adaptive mechanism may adjust down many times
c" = 2c +b until the pixel step size is approximately one pixel before it
starts rendering. In practice the parameterization is scaled
aV = d down before loading into the A F D units to be within the
If the step size is correct then we apply the E matrix. hardware register precision. The A F D U s adjust from there.
x'(t) =x(t+l) 3. Pixel filtering
y'(t ) = y (t+l) The pixel filter performs five functions. 1) It compares the
Z'(t) = Z( t + l ) current pixel coordinates with the previous pixel coordinates
generated by the A F D units and tells the A F D units whether
w'(t) = w(t+l) they should adjust up, adjust down, or step forward to the
The A F D units in this case generate a new pixel and advance next pixet. 2) The pixel filter also detects and replaces
to the next pixel with the corresponding coefficients "elbow" sequences of the form x,y to x,y+l to x + l , y + l with
transformed by a diagonal move x,y to x + l , y + l . This is done to improve the
appearance of generated curves. 3) It also generates arc
a" = a length along the curve generated by the A F D units. It adds 1
to the are length if the curve steps either horizontally or vert-
b" = b+a ically and adds 1.414 if the curve steps diagonally. The out-
Ct ~ C + b put arc length is used to address the pattern memory for
mapping texture along curves. 4) The filter unit performs
d" = d+c clipping on t, x, y, and z. t is clipped between a tmin register
and a tmax register to assist in rendering trimmed patches.
The adaptive forward differencing mechanism is illustrated
x, y, and z are clipped to their respective rnin and max regis-
below.
ter values. 5) The filter generates the instantaneous tangent
and normal vectors for the purpose of anti-aliasing curves.
The pixel filter thus acts as the controller for the A F D units
and also computes arc length, and antialias weights.
114
~ C o m p u t e r G r a p h i c s , V o l u m e 21, N u m b e r 4, J u l y 1987
0.5-t where <t~, ty> is the tangent and f~ and fy axe the fractional
y l ( t ) = ry tz_t+0.5 portion of the pixel x and y address. If cc is positive, then the
We can get the other half of the ellipse by mirroring the intensity of pixel <x,y> is blended by (l.0-c0, and pixel
image. By rotating the ellipse by an angle 0 and then <x,y+l> by c~. In case of a negative c~, pixel <x,y> is
translating it to <x0, yo>, we get a set of cubic functions blended by (l.0+c0, and pixel <x,y-1 > by -c~. For y_major, c~
which describe an ellipse with radius r,, ry centered at xo, Yo is
and rotated by an angle 0: t~
a = C/,-o.5) + Z - ~ : , - 0 . 5 )
x (t) = r, t ( l - t ) c o s 0 + r y (0.5-t)sin0+x o(t 2-t +0.5)
= ( X o - r ~ eosO)t z + (r~ cosO-r:~ sinO--Xo)t In this case, pixel <x,y> is blended by (1.0--c0, and pixel
<x+l,y> by c~ if c~ is positive; otherwise pixel <x,y> by
+ 0.5(rysin0+xo) (1.0+cx) and pixel <x-l,y> by -c~.
y (t) = -r~ t (1-t)sinO+ry(0.5-t)cos0+yo(tL-t+0.5)
One advantage of this anti-aliasing scheme is that it applies
= (yo+rzsin0)t2 - (r~sinO+rycosO+yo)t as well to both nonrational and rational curves. Figure 6
+ 0.5(rycos0+y0) shows a set of anti-aliased rational curves rendered with this
scheme.
w (t ) = t2--t +0.5
By converting the above cubic functions to DDA basis, we
get a set of coefficients
a~ = O
Shading Bicubic Patches
The AFD technique can be used to render shaded, curved,
b= = 2(Xo-r~cosO )
trimmed patches, generate anti-aliased curves, and map tex-
cx = (x0-rzcos0) + (rzcosO--rysinO-Xo) ture and imagery onto curves and surfaces as a function of
d, = 0.5(rysin0+x0) either are-length or parameter.
Shading and image mapping onto bicubic or rational bicubic
%=0
surface patches is performed by drawing many curves very
t,, = 2(y0+~, sin0) close to each other. Each curve is a cubic in t formed by set-
t i n g s at a constant s=s~. We therefore need to find the spac-
cy = (y 0+rzsin0) - (rx sinO+rycosO+yo)
ing 85 from one curve to the next so that no pixel gaps exist
dy = 0.5(rycos0+Y0) in between them. To compute the spacing 8a in between the
aw = 0.0 current curve f ( s = s i , t ) and the next curve, we run a series of
testing curves in the orthogonal direction (i.e. s direction) at
t~, = 2.0 t =(0.0,0.125...... 1.0) and examine the step size used by those
cw = 0.0 curves at the positions s=s i. T h e minimum size used is then
chosen as the spacing for the next curve f (s~+Ss,t). When the
d~ =0.5
85 gets smaller, it indicates that the next curve should be
We can set up the AFD units with the above coefficients for filled in closer to the current one; when 85 increases, the next
drawing the ellipse (see Figure 6). curve can be a little less close.
115
~ SIGGRAPH'87,Anaheim,July 27-31, 1987
W e explain next how A F D is used to adaptively adjust the For performance comparison purposes, we used the follow-
spacing in between curves. For a bicubic patch F ( s , t ) ing three schemes to render a wireframe mesh of curves for a
represented in forward difference basis, piece of teapot handle on a 512 x 512 screen with ten curves
in each direction: (1) ordinary forward differencing, (2)
F(s,t) = < fx(s,t),f y(s,t),fz(s,t),fw(s,t ) >
adaptive subdivision, and (3) adaptive forward differencing.
each $ (s ,t ) is a bicubic function of s and t. For example the x In this test, the ordinary forward differencing technique took
component 8192 forward steps, the adaptive subdivision technique took
3887 subdivisions, and AFD took 49 adjust_up's, 36
fx(s,t)=[Bo(t),Bl(t),B2(t),BB(t)] XloXHXI2XlB /B,<,)I adjust_down's and 3910 forward steps. It is obvious that the
~2o ~2~ x ~ x2 /B2(~)I ordinary forward differencing technique usually requires
LX3o x~1 x32 x3~j LB3(s)J more forward steps than our technique because it uses the
where x~j are the x coordinates o f the control points o f the smallest step required for no gaps and cannot adjust to a
patch. A curve at a constant s , f(s=s~,t), is a cubic function longer step when appropriate. Each forward operation takes
represented in forward difference basis as three adds, each adjust_up or adjust_down takes 3 adds and
2 multiplies. The first scheme required a total of 24516
f (s =si,t )=dB0(t )+cB l(t )+bB z(t )+aB 3(t ) adds. Our technique required 11900 adds and 255 multi-
where the four coefficients a , b , c , d are cubic functions of s in plies. The subdivision technique took a total of 11661 adds
forward difference basis: and 15548 multiplies, where a single subdivision requires 3
adds and 4 multiplies.
d (s)=Xoo B 0(s )+x 01 B 1(s)+x 02 B 2(s )+Xo3 B B(s )
W e used the adaptive subdivision technique and our patch
c (s)=XloBo(s)+x11 B l(S )+xi2 B2(s )+x13 B3(s ) rendering technique to compare the patch rendering perfor-
b (s)=x20 B 0(s)+x 22B ~(s)+x22B 2(s)+x23 B 3(s) mance on rendering a piece of teapot body and a piece of
teapot handle on a 512 x 512 screen. The termination condi-
a (s )=x3o Bo(s )+x 31B l(s )+x 3z B2(s )+x33 B 3(s ) tion we used in the subdivision technique was to constrain
We apply A F D to these four cubic functions to generate the the minimum bounding box of the control points of a Bezier
value of coefficients for the next curve. When the spacing 8s patch within 1.0 by 1.0. The subdivision technique on the
for the next curve is the same as the previous one, the E teapot body required 86380 subdivisions to fill the entire
matrix is applied. If the spacing for the next curve doubles, patch. Since a subdivision takes 36 adds and 48 multiplies, it
L -1 and then the E matrix are applied to double the spacing. requires approximately 3 million adds and 4 million multi-
If the spacing halves, we apply L and then the E matrix to plies. Our technique required 708 adjust up, 513 adjust
reduce it. W e are still examining methods for minimizing down, and 218513 forward step operations. Thus A F D used
this redundancy through subdivision and tuning o f the approximately 0.66 million adds and 3700 multiplies. Our
adjustment criterion. method has a curve set up overhead of 12 adds per curve - a
Figure 7 shows a Phong shaded Utah teapot rendered on a total o f 6000 adds in this test case, which is negligible. In
the ease o f the teapot handle, it took 143379 subdivisions
1152 x 900 screen with 80 patches using the A F D technique,
with adaptive subdivision, whereas the new method per-
for comparison with the equivalent polygon shaded version
formed 537 adjust up, 727 adjust down, and 187386 forward
in Figure 8 containing 4060 triangles.
step operations, i.e., 5.16 million adds and 6.88 million mul-
Trimmed patches are rendered by scan converting the trim- tiplies against 0.56 million adds and 2528 multiplies.
ming region in s,t space using the 8s seanline width. (Here a
Clearly, both subdivision and A F D can be implemented with
scanline in s,t space is different from a scanline in the screen
integer arithmetic given sufficient precision. In both
space.) This produces a "scanline" curve segment at each
methods the above multiplies can be performed using simple
constant si bounded by one or more tmin, tmax pairs. These
shifts. The shifts required for the L and L -~ matrices can be
curve segments are rendered with clipping to the appropriate
implemented with "wires" in hardware since all elements are
tmin and tmax. Figure 9 shows a shaded, image mapped,
integer powers of 2. A complete error analysis of a fixed
bicubic patch trimmed with a SUN logo.
point integer implementation of A F D is currently being con-
ducted.
Discussion
The relatively poor performance of adaptive subdivision is
In rendering curves we set the threshhold o f adjustment to be due to the fact that a subdivision operation takes
0.5 and 1.0, i.e. we adjust up if x and y step by less than .5 significantly more computation than a forward difference
pixel and we adjust down if x or y step by greater than 1 operation. This new method has the advantage of producing
pixel. Using this threshhold we do not overpaint too many picture quality equivalent to adaptive subdivision without
pixels, and neither do we leave gaps between pixels. Patches the memory stack management overhead of recursive subdi-
are rendered by filling many curves very close together. vision and is thus more suitable for hardware implementa-
However, using the 0.5 and 1.0 threshhold in rendering a tion. A F D also makes patch rendering performance com-
patch we tend to get missing pixels in the patch. This prob- petitive with polygon rendering. When doing image map-
lem is solved by reducing the pixel adjustment threshold ping and patch trimming, our technique operates in s,t space
down to 0.35 and 0.7, instead of by reducing the spacing in but polygon methods operate in the screen seanline order,
between adjacent curves. W e are currently trying to estab- therefore, our method does not require a transformation from
lish the optimal adjustment criterion for ensuring no pixel screen space to image coordinates as the polygon method
gaps. does.
116
(~ ~ ComputerGraphics,Volume21, Number4, July 1987
Acknowledgements
The following people contributed greatly to the ideas, simu-
lations, and design of these algorithms: Jerry Evans, David
Elrod, Nola Donato, Bob Rocchetti, Sue Carrie, Serdar
Ergene, Jim Van Loo, Paul Tien, and Mark Moyer.
References
1. Jerry Van Aken and Mark Novak, "Curve-Drawing
Algorithms for Raster Displays," ACM Transactions Figure 5. Comparison of antialiased and ordinary
on Graphics, vol. 4, no. 2, pp. 147-169, April 1985. nonrational cubic curves rendered with adaptive for-
2. Edwin Catmull, A Subdivision Algorithm for Computer ward difference scheme.
Display of Curved Surfaces, Thesis in Computer Sci-
ence, University of Utah, UTEC-CSc-74-133, 1974.
3. George M. Chaikin, "An Algorithm for High Speed
Curve Generation," Computer Graphics and linage
Processing, vol. 3, pp. 346-349, 1974.
4. Steven A. Coons, Surfaces for Computer-Aided Design
of Space Forms, Project MAC, MIT, MAC-TR-41,
June 1967.
5. Jeffrey Lane, Loren Carpenter, Turner Whitted, and
James Blinn, "Scan Line Methods for Displaying
Parametrically Defined Surfaces," CACM, vol. 23, no.
1, January 1980.
6. Jeffrey M. Lane and Richard F. Riesenfeld, " A
Theoretical Development for the Computer Generation
of Piecewise Polynomial Surfaces," IEEE Transactions
on Pattern Analysis and Machine Intelligence, vol.
PAMI-2, no. 1, pp. 35-46, January 1980.
7. M . L . V . Pitteway, "Algorithm for drawing ellipses or
hyperbolae with a digital plotter," Computer Journal,
vol. 10, no. 3, pp. 282-289, Nov. 1967.
8. Vaughan Pratt, "Techniques for Conic Splines," Com-
puter Graphics, vol. 19, no. 3, July 1985.
9. Michael Shantz and Sheue-Ling Lien, "Shading Bicu-
bie Patches," Computer Graphics, vol. 21, no. 4, July
1987.
117
~ SIGGRAPH'87,Anaheim,July27-31, 1987
Figure 7. Adaptive forward difference rendering of the Figure 8. Classical polygon rendering of the Utah
Utah teapot using 80 patches. teapot using 4060 triangles.
118