Analytic Rasterization of Curves with Polynomial Filters
Total Page:16
File Type:pdf, Size:1020Kb
EUROGRAPHICS ’0x / N.N. and N.N. Volume 0 (1981), Number 0 (Editors) Analytic Rasterization of Curves with Polynomial Filters Josiah Manson and Scott Schaefer Texas A&M University Figure 1: Vector graphic art of butterflies represented by cubic curves, scaled by the golden ratio. The images were analytically rasterized using our method with a radial filter of radius three. Abstract We present a method of analytically rasterizing shapes that have curved boundaries and linear color gradients using piecewise polynomial prefilters. By transforming the convolution of filters with the image from an integral over area into a boundary integral, we find closed-form expressions for rasterizing shapes. We show that a poly- nomial expression can be used to rasterize any combination of polynomial curves and filters. Our rasterizer also handles rational quadratic boundaries, which allows us to evaluate circles and ellipses. We apply our technique to rasterizing vector graphics and show that our derivation gives an efficient implementation as a scanline rasterizer. Categories and Subject Descriptors (according to ACM CCS): I.3.7 [Computer Graphics]: Three-Dimensional Graphics and Realism—Color, shading, shadowing, and texture 1. Introduction Although many shapes are stored in vector format, dis- plays are typically raster devices. This means that vector im- There are two basic ways of representing images: raster ages must be converted to pixel intensities to be displayed. graphics and vector graphics. Raster graphics are images that A major benefit of vector images is that they can be drawn are stored as an array of pixel values, whereas vector graph- accurately at different resolutions. For example, text appears ics represent images as collections of geometric shapes, such the same when printed at 600 dpi on paper or on a 72 dpi as lines, curves, circles, and polygons. Vector graphics are screen and the butterflies in Figure1 are easily drawn at dif- used in many applications in computer graphics. In 3D, al- ferent sizes. Recently, mobile devices have become another most all geometry is represented in vector form as polygons important medium and have generated a renewed interest in or smooth parametric shapes. Even in two dimensions, vec- scalable graphics. In particular, websites are often viewed tor images are extremely common. For example, nearly all both on computers with screens thousands of pixels wide and text is drawn with vector fonts, where letters are stored as on phones with screens hundreds of pixels across. Therefore quadratic curves that indicate the transition between the in- text, images, and icons must scale gracefully. side and outside of the letter. Vector images are also used in maps, signs, and logos to give a crisp, clear appearance. There has been a trend to improve the quality of images c 0x The Author(s) Computer Graphics Forum c 0x The Eurographics Association and Blackwell Publishing Ltd. Published by Blackwell Publishing, 9600 Garsington Road, Oxford OX4 2DQ, UK and 350 Main Street, Malden, MA 02148, USA. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters rather than the number of pixels that are drawn. In part, this over areas of an image, and accurate approximations require trend exists because the rate at which mathematical oper- numerous point samples, regardless of the sampling pattern. ations are performed is increasing faster than the speed of Calculating area integrals is complicated, especially when memory. The biggest improvement to pixel quality comes taking occlusion into account, but calculating line integrals from reducing aliasing. Aliasing refers to any artifact that is more tractable. Several papers [GT96, JP00, GBAM11] results from sampling a signal at a frequency less than twice have described methods of approximating area integrals by the highest frequency in the signal. Without changing the calculating a one dimensional quadrature over line samples sampling frequency, the only way to reduce aliasing is to that are computed analytically. This approach reduces the di- filter the signal to remove frequencies that are higher than mensionality of the problem by one, and yields a rasteriza- half of the sampling frequency. Multisampling, anisotropic tion with fewer artifacts from the same number of samples. texture-filtering, mipmapping, and motion blur are all filter- One can also evaluate area integrals exactly. One of the ing techniques commonly used to reduce aliasing. first methods to do so [Cat78] solves both the visibility and When rasterizing curves, another form of aliasing is integration problems simultaneously. The method clips poly- present. Most rasterizers only draw polygons and approx- gons to pixels, and then against each other, so that the re- imate curved boundaries as many-sided polygons. Thus, maining list of polygons in a pixel are all completely visi- aliasing appears both when sampling points on the curve to ble. It then sums the areas of the polygons in the pixel times form a polygon and from polygon rasterization. Our paper their color, which is equivalent to sampling with a box filter. reduces both forms of aliasing simultaneously by directly Some other methods simplify cutting to pixels by first cut- rasterizing curved boundaries using high-order filters. We ting polygons into trapezoids aligned with scanlines [GT92]. show that analytic solutions for pixel values can be found us- These trapezoids are easier to cut into pixels than polygons ing polynomial filters to rasterize curved shapes with linear and one can easily find the area of a trapezoid. color gradients. We rasterize shapes with a variety of differ- Duff uses trapezoid decomposition to evaluate polynomial ent curves and have closed-form solutions for Bézier curves filters over polygons [Duf89]. Our method is more general, of arbitrary degree as well as rational quadratic Bézier because we are able to rasterize curved boundaries in addi- curves, which allows us to rasterize exact circles and el- tion to polygonal boundaries. Our derivation of closed-form lipses. In practice, this set of shapes encompasses most prim- rasterization equations also leads to a different rasterization itives that make up vector images. algorithm, because Duff integrates over areas perpendicu- lar to the scanline, whereas we integrate over the boundary 1.1. Related Work along the scanline. The simplest form of rasterization is point sampling, which Some methods rasterize polygons with radial filters. An simply determines if a point is inside of a polygon or not. early method [Cat84] clips polygons to pixels and adds each Calculating which polygon, if any, contains an arbitrary sam- edge’s contribution using a radial filter. If an edge forms a ple can be done using ray casting [App68]. One can also re- triangle with the center of the filter, that triangle is split into cursively cut the image into quadrants, subdividing around two right triangles. Each right triangle is parameterized by polygon edges [War69]. More typically, pixel values are cal- two values that index a lookup table to find the edge’s con- culated a scanline at a time [WREE67]. tribution. A more recent algorithm [LCSW05b] removes the The solution to reducing aliasing artifacts is to convolve need of clipping polygons to pixels by taking the modulo of the signal with a filter that removes frequencies that are final pixel values. The method also has analytic solutions for higher than half the sampling rate. This is equivalent to as- polynomial filters, but cannot use filters with negative val- signing pixel values by integrating the product of the image ues because of the modulo operation. The authors published and the filter centered at the pixel. Approximating this in- a paper describing positive filters that are suitable for their tegral by quadrature is called supersampling, and as more method [LCSW05a]. samples are used for each pixel, the quality of the rasteriza- There are also some rasterizers that are difficult to clas- tion improves. If subsamples are also on a regular grid, alias- sify. One method approximates the rasterization of self- ing artifacts can still occur for very high-frequency images. intersecting polygons [Doa04]. In this method, the con- In ray casting there is significant freedom in sample place- tours within pixels that contain intersections are simpli- ment, and several early papers [DW85, Coo86, Mit87] ana- fied and clipped against other contours. Another method lyze image sampling patterns. These works show that sam- calculates analytic rasterizations of shapes filtered by box ples should be random but have uniform density, and there splines [McC95]. Filters must be positive, and the method is renewed interest in such sampling patterns [JC99, HC06, only rasterizes triangles. Auzinger et al. [AGJ12] analyti- Kal07,GM09,Wei10,Fat11,EDP ∗11]. There is also research cally rasterize antialiased triangles and tetrahedra with linear on how to optimize the sampling pattern and weights simul- data defined over the simplices. We also handle linear gra- taneously [LA06]. dients, but we analytically rasterize complex, curved, two- Calculating prefiltered pixel values requires an integral dimensional shapes. A process similar to polygon rasteri- c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters zation has also been used to calculate surface irradiance in the area integral a raytracer by using Stokes’ theorem to evaluate incoming ZZ light from polygonal light sources [CA00, CA01]. I(x;y)h(x − `x;y − `y) dx dy: R2 The main contribution of our paper is prefiltered, an- We can simplify the expression by changing the domain of tialiased rasterization of shapes with curved boundaries. integration to be only over the interior of M because the im- There has been some work in directly rasterizing shapes age is zero outside of the boundary. with curved boundaries, but most rasterizers simply approxi- ZZ mate curved boundaries by subdividing the curves into many c(x;y)h(x − `x;y − `y) dx dy (1) x;y2M sided polygons [Cat74].