A straightfoward implementation of bi- or tricubic texture filtering requires lots of texture lookups. As texture lookups are slow on current graphics hardware, reducing their number greatly improves the performance of high-order filtering kernels. In contrast, linear interpolation is relatively cheap as it is supported by the hardware. This fact has been exploited by Sigg and Hadwiger (2005) to make cubic interpolation much faster by performing a series of linear texture lookups. In this article, an in-depth explanation of their technique is given, starting with some general information on linear interpolation and approximation using cubic B-splines.

At first, we will focus on the one dimensional case. Suppose we have two data points and and we want to interpolate the values between these points. Using linear interpolation, this results in the following equation:

,

where . The functions and determine the filtering weight for each point. The values are interpolated such that is at and at . The following images show the liner basis functions (left) and the result of interpolating some points (right):

The formula is automatically evaluated on the GPU if linear filtering is activated in OpenGL and, for example, `texture`

is used in the fragment shader to fetch a texel from texture memory.

If we want to use cubic filtering, we have to use the following formula:

,

where are now third-order polynomials. We will choose weightings based on uniform cubic B-splines, so the weighting functions become

.

Although four points are used, the function constructs only points between and for . This range is called a segment of the curve. However, rather than interpolating the points and as above, only approximates the values now. That means that at and , does not pass through the data points and . Nevertheless, the resulting function is geometrically continuous, as the approximated value at of a segment is the same as the approximated value at of the next segment. This is shown on the following image on the right (left: cubic B-spline basis functions). Note that the curve does not pass through the blue dots and that the first and last segment is missing.

As we can see from the equation for cubic interpolation, four texture lookups are necessary. This becomes even worse in two and three dimensions, where 16 and 64 lookups are required, respectively. As mentioned in the introduction, it is possible to replace a cubic interpolation by a sequence of linear interpolations. As a result, in 1D the 4 lookups can be reduced to 2 linear lookups. The 16 lookups in 2D can be replaced by 4 linear lookups, the 64 lookups in 3D by 8. In general, lookups are replaced by linear lookups.

Now, let’s focus on how the optimization works. Actually, it is pretty simple: just write the cubic interpolation as the sum of two linear interpolations:

.

For this purpose, let’s first find a notation for the operation that the graphics card executes when performing a linear texture lookup:

.

That shows that when we want to interpolate between two texels, we just extract a constant from texture memory at . However, that is not sufficient if we want to write weighted sums with two weights and as linear interpolation. So, we have to scale and , resulting in the new variables and with :

.

Then, we write the sum as follows:

.

Notice that this looks exactly like an ordinary linear interpolation, scaled by the factor . Using the above notation, the weighted sum becomes

.

There is a small restriction: it only works if . Fortunately, that is satisfied when using cubic B-splines.

Finally, third-order texture filtering is obtained by the following two linear interpolations:

.

In conclusion, this post has presented an efficient technique for third-order texture filtering in 1D based on hardware-accelerated linear interpolation. In the next post, this will be extended to two and three dimensions, where the performance gain is much more significant.

References:

## 2 thoughts on “Third-Order Texture Filtering using Linear Interpolation”