approximation techniques for high performance texture mapping

8
Comput. 81 Graphics, Vol. 20, No. 4, pp. 483-490, 1996 Copyright 0 1996 Elsevier Science Ltd Printed in Great Britain. All rights reserved 0097-8493/96 $15.00+0.00 PIk SOO97-8493(96)0002&9 Hardware Supported Texturing APPROXIMATION TECHNIQUES FOR HIGH PERFORMANCE TEXTURE MAPPING MEHMET DEMIRER and RICHARD L. GRIMSDALE+ Centre for VLSI and Computer Graphics, School of Engineering,University of Sussex, Brighton BNl 9QT, U.K. Abstract-Accurate perspective mapping in real-time requires costlydivision operations per pixel and therefore approximation techniques areoftenemployed. These permit the mapping to beperformed by interpolation, but generally with a significant set-up cost for the computation of the parameters. An efficient approximation technique which achieves good results with modest set-up requirements is presented. The technique uses Chebyshev control points to minimize errors. Copyright 0 1996 Elsevier Science Ltd 1. INTRODUCTION Texture mapping involves both geometrictransfor- mations and, to avoid aliasing,filtering operations. Only the former is considered here, with the main emphasis on texture coordinate calculation. Since the correct mappingfunction involvesthe evaluationof a quotient per pixel [l], it is computationally expensive. Therefore, approximate methods are generally em- ployed, although these can introduce errors 121. To improve the accuracy, polygonsmay be subdivided, however, as the number of polygons increases, the calculation becomes more expensive. Several approx- imation techniques have been reported [3, 41. Both scan line and polygon based approximation tech- niqueshave beeninvestigated. These approximation techniques in both cases require a considerable number of operations for the calculation of inter- polation coefficients. We present here new quadratic and cubic approximation techniques for both cases with significantly reducedset-up cost and improve- ment in the accuracyof the results. 2. PERSPECfIVE MAPPING In order to map a 2-D imageonto an object in a perspective mapping, Eq. (1) must be performed at eachpixel. U=Ax+By+C Gx+Hy+Z Dx+Ey+F “= Gx+Hy+Z where x and y are screen coordinates,u and v are texture coordinates and A to Z are coefficients which characterize the mapping function. Although this is an efficient solution to texture mappingin software, + Author for correspondence. the division operation makesreal time performance hard to achieve with hardware,since the two texture coordinates (u, v) must be produced every 50ns to satisfy real-time constraints.The distinctive feature of perspective mappingis that it preserves lines in all orientations,however, linesconvergeto a vanishing point unless they are parallel to the projection plane. 3. CONVENTIONAL APPROXIMATION TECHNIQUES 3.1. Linear approximation The simplest and most widely used approximation technique is linear approximation. However, it results in severe errors in perspective projection, since the linear approximation is a poor representa- tion of a rational function. Therefore, linear approx- imation cannot generate the foreshortening effects of true perspective [I, 5, 81. 3.2. Quadratic approximation along a scanline Perspective mapping defined by Eq. (1) can be approximatedby a quadratic function asbelow: u=Ax’+Bx+C v=Dg+Ex+F (2) where A to F are constants.In order to calculate these coefficients, the mappingof three points, i.e. the two ends of a scanline and its midpoint of each scan- line, are required. Thus, a general solution for the polynomial coefficients can be found [3]. The quad- ratic coefficients are: A = quo - 2Ul + u2) (x0 - X2j2 B= XoW + 3Xm - 4Xou1- 4Xm + 3XoUz + X2U2 (x0 - X2J2 483

Upload: mehmet-demirer

Post on 23-Aug-2016

216 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Approximation techniques for high performance texture mapping

Comput. 81 Graphics, Vol. 20, No. 4, pp. 483-490, 1996 Copyright 0 1996 Elsevier Science Ltd

Printed in Great Britain. All rights reserved 0097-8493/96 $15.00+0.00

PIk SOO97-8493(96)0002&9 Hardware Supported Texturing

APPROXIMATION TECHNIQUES FOR HIGH PERFORMANCE TEXTURE MAPPING

MEHMET DEMIRER and RICHARD L. GRIMSDALE+

Centre for VLSI and Computer Graphics, School of Engineering, University of Sussex, Brighton BNl 9QT, U.K.

Abstract-Accurate perspective mapping in real-time requires costly division operations per pixel and therefore approximation techniques are often employed. These permit the mapping to be performed by interpolation, but generally with a significant set-up cost for the computation of the parameters. An efficient approximation technique which achieves good results with modest set-up requirements is presented. The technique uses Chebyshev control points to minimize errors. Copyright 0 1996 Elsevier Science Ltd

1. INTRODUCTION

Texture mapping involves both geometric transfor- mations and, to avoid aliasing, filtering operations. Only the former is considered here, with the main emphasis on texture coordinate calculation. Since the correct mapping function involves the evaluation of a quotient per pixel [l], it is computationally expensive. Therefore, approximate methods are generally em- ployed, although these can introduce errors 121. To improve the accuracy, polygons may be subdivided, however, as the number of polygons increases, the calculation becomes more expensive. Several approx- imation techniques have been reported [3, 41. Both scan line and polygon based approximation tech- niques have been investigated. These approximation techniques in both cases require a considerable number of operations for the calculation of inter- polation coefficients. We present here new quadratic and cubic approximation techniques for both cases with significantly reduced set-up cost and improve- ment in the accuracy of the results.

2. PERSPECfIVE MAPPING

In order to map a 2-D image onto an object in a perspective mapping, Eq. (1) must be performed at each pixel.

U=Ax+By+C Gx+Hy+Z

Dx+Ey+F “= Gx+Hy+Z

where x and y are screen coordinates, u and v are texture coordinates and A to Z are coefficients which characterize the mapping function. Although this is an efficient solution to texture mapping in software,

+ Author for correspondence.

the division operation makes real time performance hard to achieve with hardware, since the two texture coordinates (u, v) must be produced every 50ns to satisfy real-time constraints. The distinctive feature of perspective mapping is that it preserves lines in all orientations, however, lines converge to a vanishing point unless they are parallel to the projection plane.

3. CONVENTIONAL APPROXIMATION TECHNIQUES

3.1. Linear approximation The simplest and most widely used approximation

technique is linear approximation. However, it results in severe errors in perspective projection, since the linear approximation is a poor representa- tion of a rational function. Therefore, linear approx- imation cannot generate the foreshortening effects of true perspective [I, 5, 81.

3.2. Quadratic approximation along a scanline Perspective mapping defined by Eq. (1) can be

approximated by a quadratic function as below:

u=Ax’+Bx+C

v=Dg+Ex+F (2)

where A to F are constants. In order to calculate these coefficients, the mapping of three points, i.e. the two ends of a scanline and its midpoint of each scan- line, are required. Thus, a general solution for the polynomial coefficients can be found [3]. The quad- ratic coefficients are:

A = quo - 2Ul + u2)

(x0 - X2j2

B= XoW + 3Xm - 4Xou1 - 4Xm + 3XoUz + X2U2

(x0 - X2J2

483

Page 2: Approximation techniques for high performance texture mapping

484 M. Demirer and R. L. Grimsdale

c= xox;?u(J + x;uo - 4XOXZUl - x$42 + x0x$42

(x0 - x2Y (3)

3.3. Cubic approximation along a scanline In a similar way to quadratic approximation, a

cubic expression can also be employed along a scanline. The general expression of the cubic inter- polation polynomial is:

(4)

where us to b3 are constants. There are four unknown coefficients for the cubic approximation thus four constraints must be imposed to calculate them. For example, the polynomial passes through the two endpoints of a span and satisfies the imposed conditions on the first derivative. The calculation of derivatives and the coefficients are given in [3].

3.4. Biquadratic approximation Equation (1) can be approximated with a quad-

ratic function in two variables [2, 41.

u= (Ax+B~+C)~ (5)

Re-arranging the equation above, this equation can be expressed in the form:

u = A1x2 + A2y2 + A3xy + A4x + A5y + A6 (6)

similarly,

v=B,~+&~+B~xy+B~x+B~y+B~ (7)

The biquadratic equation given in Eq. (6) is for a quadratic surface and quadratic interpolation is thus set up by fitting this surface to six points: the vertices and side midpoints of a triangle. Thus, using the Gaussian elimination method, six simul- taneous equations are solved to obtain the inter- polation coefficients. These six coefficients must be calculated before texture coordinates are generated. Then, using the forward differencing method, interpolation is performed.

3.5. Bicubic approximation A bicubic interpolation is an improvement over

the biquadratic technique. The mapping equation is:

N A,x3 + A2y3 + A3x2y + A4xy2 + A5.xZ + ,469

+ A7xy + &3x + A9y + Alo (81

The 10 coefficients must also be calculated before texture coordinate generation. The control points can be chosen in several ways, provided certain constraints are satisfied over the polygon. However, in order to solve the 10 simultaneous equations, Gaussian elimination is again required, which requires approximately 1000 operations. This re- presents an excessive computational cost.

4. CHEFSYSHEV APPROXIMATION

The solution that we adopt to approximate the perspective mapping equation is a combination of the well-known Chebyshev and the Lagrange interpolation methods. The approximation with Chebyshev roots exploits the rather special proper- ties of the use of unequally distributed data points and evenly distributed errors. Chebyshev points are located in the span [ - 1, I] and can be applied to any other range by mapping it into the range of interest. Thus, the approximation polynomial using Chebyshev points can be derived. The arithmetic operations for these derivations are given in [6, 71.

4.1. Second order polynomiul The second order approximation polynomial

along a scanline uses 3 Chebyshev points in the span [a, b]. The 3 points are calculated by setting K= 3 in Eq. 9 and letting n take the values 1, 2, K.

zn=f [(b-a)cos (w).+a+b] (9)

Then, the general formula for the interpolation polynomial is:

g(z) = To + Tlz + Tzz2 (10)

where

To = Az,z2 + Bzoz2 + Czoz,

T I = -[A(zI + z2) + B(zo + z2) + c(zo + z,),

Tz=A+B+c (11)

and

A = (zo - $io - z2)

B = (2, - $Y, - z2)

Page 3: Approximation techniques for high performance texture mapping

High performance texture mapping 485

4.2. Third order polynomial In a similar way to that described in the previous

section, the third order interpolation polynomial can be obtained. The general formula is:

g(z) = To + Tlz + T22 + T3z3 (13)

where

To = -[z244z, + Bzo) + zozl (Cz, + Dzz)]

T I = zlzz(A + D) + .W3(A + c) + z2z,(A + B)

+ zoz2(B + D) + ZOZ3(B + C) + ZOZI (C + D)

T2 = -[z~(A+C+D)+Z&~+B+D)

+Z3(44+B+C)+zo(B+C+D)]

T3=A+B+C+D (14)

and

A = (zo - Zl) ,z:‘4”i,, (zo - Zj)

B = (z1 - zo) (X’“A, (z1 - z3)

c = (z2 - zo) (iz) (z2 - z3)

D = (a - zo) (1”1) (z3 - z2) (15)

Once the coefficients are calculated, u and v values follow through the use of forward differencing [3]. Therefore, three forward difference constants are used to approximate perspective mapping repre- sented by a cubic polynomial. The same procedure is valid for the quadratic polynomial.

9 Control Points

(a)

16 Control Points

(W

9 Control Points

03

16 Control Points

(d)

Fig. 1. Chebyshev control points.

Thus, after a four-corner correspondence has been established between the unit square in texture space and an arbitrary quadrilateral in screen space, scan- conversion is performed by the interpolation function obtained by using Chebyshev points. The bicubic polynomial can be derived in several ways. We have used the transtInite interpolation method. The gen- eral transfinite interpolation function is:

4.3. Biquadratic and bicubic interpolation on Chebyshev points

@, Y) = 5 ~m(x)F(xm, Y) + 2 Yn(Y)F(X, Yn) m=O n=o

In our approach, 9 control points for the M N

biquadratic and 16 control points for the bicubic are used, which are the roots of the second and the

- c c @m(X)~‘,(Y)F(Xm, Yn) m=O n=O (16)

third order Chebyshev polynomial along both the x and y axes. Figure 1 shows the positions of the where Chebyshev points over a polygon. Although the equal intervals along both axes have been chosen [see Fig. l(a, b)], unequal intervals can also be evaluated as shown in Fig. l(c, d). In the first case, four

CD&) = fi x--xk k=O,k#m xm - xk

Chebyshev points for the span [O,l] are: zo=0.038060234, z1 =0.308658295, z2=0.691341736 and z3=0.961939758. Since interpolation will be Y,(y) = fi y-yk (17) performed across a polygon and span lengths are k=O,k#n ym - yk

equal along x and y axes, the true values of F(x,, yn) are calculated for x0, ye, . . . , x3, y3 where and M=N=3. Also, F(x, y,) and F(x,,,, y ) can be zo=xo=Yo~ z1 =x1 =yl, z2=x2=y2 and z3=x3=y3. expressed as: CAG 20-4-e

Page 4: Approximation techniques for high performance texture mapping

486

where F,,,, values are the true values on Chebyshev points.

When the auxiliary arithmetic operations are completed, the interpolation function takes the form:

F(x, y) = H,y3x3 + Hzy3x2 + H3y3x + H4y3

+ Hsy2x3 + Hsy*x* + H,y*x + Hsyz

+ Hgyx3 + H,oyx’ + HI ~yx + HIZY

+ H,3x3 + Hd + HISX + HM

(19)

M. Demirer and R. L. Grimsdale

H7 = - 2 Aj 2 Ei80 j:O i=O

Hg = - k Aj 5 Fit90 j=o i=O

H~=~Bj~O~ j=O i=o

H~o = - 2 Bj 2 Dj6, idI i=o

HII ~2 @j 2 Ei0, j=O i=o

HIZ = - e Bj 2 FiSp j=O i=O

HIP=--& c, 2 Qb j=O i=O

H14 = e Cj 2 DiBQ j-0 i=O

H~s=-k Cj 2 EiQ, j=O i=O

H16 = 2 Cj e FiQ, j=O i=O

The coefficients HI to HI6 are calculated via another coefficient matrix 0.

CXCYFOO -CYFIO CYFZO -CxC~f'30

@= -CXFOI Fll -F21 Cd.31

CxFo2 -F12 F22 - CxF32

-CxCrFo3 CYFI 3 -cYF23 CxCyF33 1 (20)

where CX = (x2 - x1)/(x3 - x0) and CY = (~2 - yr)/ (ys - ys). Further algebraic manipulation results in simplified expressions for the coefficients which are now given by:

H, =e -&i$ i=o j=o

Hzc-2 Di 20~ i=O j=O

H3=2 .Ei & 8,

i=O j=O

H4 = - 2 Fi 5 80 i=o j=O

Hs = - 2 Aj L 00 j=O i=o

Hs ~2 Aj 2 6~ i=o i=O

(22)

5. ACCURACY

The Chebyshev polynomial has n zeros in the interval [ - 1, l] as given in Eq. (9) and n + 1 maxima and minima, located at:

k = 0, I, , n. (23)

The maxima and minima of the polynomial can only be equal to 1 and - 1, respectively. This property makes Chebyshev polynomials useful in approximating functions [7]. Although the particular approximation in a certain interval using AT Cheby- shev roots (provided that N is big enough) may not be better than any other having some other set of N data points, the approximation polynomial can be truncated to a polynomial of lower degree FB in a very graceful way that yields the most accurate approx- imation of degree m.

Since the polynomial is bounded between - 1 and 1, the difference between tih and mth (m < N) order polynomials cannot be larger than the sum of neglected coefficients, which typically decrease

Page 5: Approximation techniques for high performance texture mapping

High performance texture mapping 487

Table 1. Number of operations

Set-up operations

Operations

Traditional Quad. Traditional Cubic Chebyshev Quad. Chebyshev Cubic

Scanline

36 >75

24 62

Polygon

>216 > 1000

138 310

rapidly. Therefore, the error is dominated by an oscillatory function with m + 1 extrema distributed over the interval. This truncated approximation is nearly the same polynomial as the minimux polynomial [7], which has the smallest maximum deviation from the true function among all poly- nomials of the same degree and is very difficult to find.

6. COST We have considered several approximation techni-

ques in previous sections. In order to calculate approximation coefficients for the conventional biquadratic and bicubic interpolation polynomials, the Gaussian elimination method is used. This method requires approximately N3 operations where N denotes the number of equations. Therefore, much computational power is needed. As for the Cheby- shev approximation, many fewer operations are required and the results are more accurate as a greater number of control points are used. The requirements for the traditional and Chebyshev approximation techniques are given in Table 1.

7. RESULTS

Figures 24 show the results of scanline based approximation techniques. In order to compare the

Fig. 3. Direct quadratic approximation.

methods, a rather difficult perspective view has been chosen. Generally, all images generated by approx- imate methods exhibit errors related to preserving straight and diagonal lines. Careful examination of squares near the viewing point shows deformation of the nearest black square. Line errors and distortions of squares become less visible in Fig. 6, which uses the Cubic Chebyshev approximation along a scanline. Figures 7 and 8 also show two different graphs of approximate coordinate versus true co- ordinates. The straight line represents the accurate result and it can be seen that the error with the use of the Chebyshev approximation method are less than with the others. Figures 9 and 10 also compare the

Fig. 2. Linear approximation. Fig. 4. Quadratic Chebyshev approximation.

Page 6: Approximation techniques for high performance texture mapping

488 M. Demirer and R. L. Grimsdale

Fig. 5. True texture coordinates.

results of the true algorithm and the Bicubic Cheby- shev approximation technique. The perspective pro- jection chosen for these views is also considered to be a difficult case and can give rise to severe deforma- tions in the checkerboard pattern at large perspective distances if the mapping technique is not sufficiently accurate. However, the errors in the Bicubic Cheby- shev approximation technique are acceptably small and distortion of straight lines is only apparent in a few diagonals, after careful examination.

Fig. 7. Comparisons of case i

8. DISCUSSION

The method described in Section 4.3 has been applied to a single rectangular surface. It uses 16 control points for the bicubic polynomial, which are chosen as the roots of the third order Chebyshev polynomial. It may not always be possible to restrict the surface to a rectangular shape and it may take the form of a general quadrilateral or a triangle. Furthermore, in a model with a number of facets, there can be a multiplicity of polygons with the same texture pattern. Since the Chebyshev points would be

Fig. 6. Cubic Chebyshev approximation. Fig. 8. Comparisons of case 2

Page 7: Approximation techniques for high performance texture mapping

High performance texture mapping

Comparison of 3 different approximations 5500

5 5000 z ;;; 4500 -

6

-True -----0uadratic -..----Chebysha! ----Linear

15ool 1500 2000 2500 3000 3500 4000 4500 5000 5

Base function (f(x))

Fig. 9. True texture coordinates.

I-

51

489

DO

chosen independently for two adjacent surfaces, there would be a discontinuity between the texture patterns along the common edge. Therefore the use of Chebyshev points is impractical in this case. How- ever, as can be observed from Eqs (16) and (17), the control points can be arbitrarily chosen over a polygon at a cost of a few more multiplication operations. Although the errors will now be greater, the technique is still more accurate than other bicubic approximation methods due to the extra control points.

9. CONCLUSION

A linear approximation is a poor fit for a rational function and in an extreme case, a quadratic one also fails. Therefore, a cubic approximation can be considered a reasonable technique. Traditional tech- niques are reasonably accurate in the middle range of

the interval, but the error increases towards the edges. On the other hand, using Chebyshev approx- imation methods, errors become more evenly dis- tributed throughout the interpolation and their magnitudes become less than the other techniques. The reason for this is that the traditional methods use equi-spaced data points whereas Chebyshev approx- imation employs roots of Chebyshev polynomial as data points, which are defined by a cosine function and the spacing between these points is greatest at the centre of the interpolation domain, decreasing towards the edges. The results show that the Cubic and Bicubic Chebyshev approximation techniques provide rather acceptable images at much less cost in comparison with conventional techniques. Hardware design can be based on either scan line or polygon rendering algorithms. Therefore, real time or near real time performance can be achieved.

Comparison of 3 different approximations 2000

e 1600’

3 1600‘ In g 1400.

.-

-True ------Quadratic - -.--a-.Chebyshev ----Linear

Base function (f(x))

Fig. 10. The Bicubic Chebyshev approximation.

Page 8: Approximation techniques for high performance texture mapping

490 M. Demirer and R. L. Grimsdale

REFERENCES

P. Heckbert and H. P. Moreton, Interpolation for polygon texture mapping and shading. In State of the Art in Computer Graphics Visualization and Modelling. D. F. Rogers and R. A. Earnshaw (Eds), Springer- Verlag (1991). D. Kirk. and D. Vorrhies. The renderine: architecture of the DNlOOOOVS. Computer Graphic> 24, 299-308 (1990) G. Wolberg, Digital Image Warping, IEEE Computer Society Press (1990).

4. G. J. Dunnett, Texture Magping Architectures Jbr High Performance Image Generation. DPhil Thesis. Sussex University, U.K. (1994).

5. P. Heckbert, A survey of texture mapping. In IEEE Computer Graphics and Applications, X--67 (1986).

6. S. Nakamura, Applied Numerical Methods in i’. Prentice-Hall (1993).

7. W. H. Press, S. A. Teukolsky, W. T Vetterling and B. P. Flannery, Numerical Recipes in C. Cambridge University Press (1992).

8. P. Heckbert, Texture mapping polygons in perspectlvc. NYZT Technical Memo. No. 13, April (1983).