Bilinear Accelerated Filter Approximation
Total Page:16
File Type:pdf, Size:1020Kb
Eurographics Symposium on Rendering 2014 Volume 33 (2014), Number 4 Wojciech Jarosz and Pieter Peers (Guest Editors) Bilinear Accelerated Filter Approximation Paper 1019 (a) Input (b) Exact Lánczos 2 (c) Trilinear interpolation (d) CCTF (e) Our method Figure 1: Approximations of downsampling a high-resolution input image (a) to 1002 pixels using a Lánczos 2 filter are compared. The result from exact evaluation is shown in (b) and the approximations by (c) trilinear interpolation, (d) Cardinality- Constrained Texture Filtering (CCTF), and (e) our method all use the same mipmap. Trilinear interpolation appears blurry, whereas our approximation of the Lánczos 2 downsampled image is similar to the exact evaluation of a Lánczos 2 filter and CCTF. However, our method runs twice as fast as CCTF by constructing a filter from hardware accelerated bilinear texture samples. Abstract Our method approximates exact texture filtering for arbitrary scales and translations of an image while taking into account the performance characteristics of modern GPUs. Our algorithm is fast because it accesses textures with a high degree of spatial locality. Using bilinear samples guarantees that the texels we read are in a regular pattern and that we use a hardware accelerated path. We control the texel weights by manipulating the u;v parameters of each sample and the blend factor between the samples. Our method is similar in quality to Cardinality-Constrained Texture Filtering [MS13] but runs two times faster. Categories and Subject Descriptors (according to ACM CCS): I.3.3 [Computer Graphics]: Picture/Image Generation—Antialiasing 1. Introduction 3D scenes, perspective projection creates a nonuniform dis- tortion between 2D textures and the image rendered on the High-quality texture filtering is important to the appearance screen, so anisotropic filtering is commonly used to filter of a rendered image because filtering reduces aliasing arti- textures in 3D scenes. However, anisotropic filters are typ- facts when textures are downsampled. Aliasing occurs when ically generated using multiple isotropic samples [MPFJ99, a scene contains higher-frequency details than are repre- MS13], so isotropic filters are important in both 2D and sentable at the resolution of the screen. Antialiasing is of- 3D rendering. In this paper, we only consider optimizing ten associated with smoothing jagged edges of polygons, but isotropic filtering, but we show examples of our method ap- texture sampling provides an even more noticeable source of plied to anisotropic filtering in Section4. aliasing. Drawing antialiased edges only improves the pro- file of objects, whereas improved texture filtering benefits Even isotropic filters are difficult to evaluate efficiently every textured pixel that is drawn. at arbitrary scales s and translations t. The ideal low-pass filter, sinc, is too expensive to evaluate because it has infi- Resizing an image requires only an isotropic filter. For nite support, so smaller filters such as the tent, Gaussian, and submitted to Eurographics Symposium on Rendering (2014) 2 Paper 1019 / Bilinear Accelerated Filter Approximation Lánczos filters are used. Even filters with small support may of precision. However, summed-area tables can evaluate the sum hundreds of texels under modest scales. For example, a average pixel color within any rectangular region of texels Lánczos 2 filter covers an area of 4×4 pixels, so downsam- using 4 table lookups, which, because of the quadrupled in- pling by a factor of s = 5 sums over 42×52 = 400 texels for teger size, is equivalent to reading 16 texels. Constant-time a single sample. evaluation with different filters can also be done by sam- pling from a mipmap level that has a resolution only a few Precalculated pyramids of downsamplings at different res- factors higher than the sample being approximated [Hec89]. olutions, called mipmaps [Wil83], keep the cost of evaluat- The sampled mipmap needs to be of sufficiently high reso- ing a texture sample constant. The position and scale of a lution to capture features of the filter, and Heckbert suggests new sample are unlikely to be identical to a precalculated reading between 9 and 36 texels per sample. Another method sample in the mipmap, so the data is interpolated by trilinear that samples from a single mipmap level [HS99] stores a ta- interpolation. Trilinear interpolation is simple, defines a con- ble of weights to approximate affine transforms of a box fil- tinuous transition between colors, and never reads more than ter. 8 texels, which results in an interpolant that is fast enough for real-time rendering and that has been the de facto standard Methods that combine texels from multiple mipmap res- in computer graphics for the past 30 years. olutions are more efficient. NIL mapping [FFB88] uses adaptive quadrature to approximate the more-important A natural question arises: is it possible to devise a bet- parts of a filter with high-resolution texels and approxi- ter approximant than trilinear interpolation? Cardinality- mates the remainder of the filter with low-resolution texels. Constrained Texture Filtering (CCTF) [MS13] improves CCTF [MS13] performs a linear cardinality-constrained op- upon trilinear interpolation, but CCTF requires scattered timization to determine which set of texel basis functions texture reads that are inefficient for cached texture mem- in a mipmap best reproduce a given filter. Any set of basis ory. Our method addresses this shortcoming by using bilin- functions can be chosen, which means that texel reads are ear samples to improve memory coherence while using the scattered both in position and mipmap resolution. Therefore, same memory bandwidth as trilinear interpolation. Combin- CCTF violates the data locality assumptions that are criti- ing GPU accelerated bilinear samples allows us to double cal for cache performance. Scattered reads increase mem- the performance obtained with CCTF while accurately ap- ory bandwidth because memory is read at the resolution of proximating filters. The result is high-quality renderings, as cache lines rather than texels. In contrast, our method uses demonstrated in Figure1. Like trilinear interpolation, we use cache-friendly bilinear reads, at the cost of precomputing the two bilinear samples, but we solve for the best u;v coordi- result of a nonlinear optimization. Although the trilinear in- nates and coefficients of each of the samples for different terpolant is also composed of two bilinear reads, we produce filter parameters s;t. By optimizing parameters and coeffi- higher quality images than trilinear interpolation because we cients of bilinear reads, we achieve a 4×reduction in approx- perform a nonlinear optimization to find the best u, v param- imation error compared to trilinear interpolation while read- eters and coefficients for the bilinear samples. ing only eight texels per sample. Several papers on texture filtering improve the qual- ity of anisotropic filtering [Gla86, GH86, Hec89, SKS96, 2. Related Work CS97, HS99, MPFJ99, CS00, CDK04, ZLW06, MP11]. We do not directly consider anisotropic filters because multi- The simplest method for sampling a mipmap is to return ple isotropic samples can be used to construct an anisotropic the color of the nearest neighbor. This method reads one sample [MPFJ99]. A similar method of combining isotropic texel and is fast, but the image is blocky because the near- samples used in GPUs is called N× anisotropic filtering, est neighbor interpolant is discontinuous. Trilinear interpo- which means that up to N isotropic samples are taken along lation [Wil83, BA83] produces continuous changes in color, a line to approximate an anisotropic filter. By improving the which looks better than nearest-neighbor interpolation, but quality of isotropic samples with our method, we automati- it reads eight texels. Increasing the order of the interpolant cally improve the quality of anisotropic filtering, as demon- to tricubic interpolation provides little visual benefit when strated in the results section. downsampling an image because increasing smoothness does not necessarily reduce approximation error. However, bicubic interpolation does increase the quality of upsampled 3. Filter Optimization images [SH05]. Sampling an image function I(x) with a spacing s between A few methods improve the quality of isotropically down- samples can be modeled by multiplying by the Dirac comb 1 sampled images. Summed-area tables store the integral of function Xs(x) = ∑t=−∞ d(x − st) so that the sampled pixel colors instead of a mipmap [Cro84]. These tables take function is Xs(x)I(x). We can represent a function by its significantly more space to store than the original image be- frequency spectrum using the Fourier transform Z 1 cause each color component needs 32 bits in order to sup- −2pixw 2 Iˆ(w) = FfI(x)g = I(x)e dx: port texture sizes up to 4096 texels while maintaining 8 bits −∞ submitted to Eurographics Symposium on Rendering (2014) Paper 1019 / Bilinear Accelerated Filter Approximation 3 The Fourier transform of Xs is FfXs(x)g = X1=s(w). Be- same logic applies in 2D. The difference is that, in 2D, we cause multiplication becomes convolution under the Fourier sample the image I(x;y) over a 2D grid by a filter hstutv (x;y). transform Ff f (x)g(x)g = ( fˆ∗ gˆ)(w), the frequencies in our To provide good caching behavior, we want to approximate sampled function are the filter using a small number of coefficients, and the coef- ficients should be clustered in space. 1 t FfXs(x)I(x)g = ∑ Iˆ(w − ): t=−∞ s GPUs provide hardware acceleration for bilinear interpo- lated texture reads, which return a weighted combination of a ˆ If the spectrum of the sampled function I(w) contains fre- quad of adjacent texels. Bilinear interpolation reads a single 1 1 quencies outside the range w 2 [− 2s ; 2s ], then interference mipmap level at scale s and is controlled by the u;v parame- ˆ between shifted copies of I(w) can occur.