On the Back of a Napkin: Part 3
Page 1 of 2
<1 | 2>
Single-page view
On the Back of a Napkin: Part 3

This article originally appeared in Dev.Mag Issue 4, released in June 2006

Now that we've got a solid foundation to work with, we can start looking at more relevant issues in 3D. This week we'll explore the idea of texture filtering and why it's a good thing. We'll find out what the various types of filtering actually do, how they do them and how much of a frame rate hit each one causes. Read on if you want to know the difference between bilinear, trilinear and anisotrophic filtering.

Why filter?

The reason that texture filtering is used is a small problem in the graphics industry called aliasing. Aliasing problems are very easy to spot and can ruin the visual illusion in a game.

Any computer screen is divided into pixels, duh. Each pixel can only be a single colour, it's impossible to have a pixel start off being red on one side and then fade to black on the other. The idea is that any image can be abstracted (See, it IS all lies, even your screen) by splitting it into enough individual pixels, unfortunately that doesn't always work very well: We notice "blockiness" on diagonal and nearly vertical/horizontal lines very easily.

Aliasing issues:

Aliasing is called that because it's the process of referring to one thing by a set of different handles or names. In this case, we're trying to get the pixels in a rendered image to refer to the pixels in a texture. As each pixel in our image is rasterised, (if you have no idea what that means, read the article on Vertices again) interpolation gives us a unique set of texture co-ordinates that tell us where on the texture to fetch the colour our pixel should be. That sounds complex, but it isn't: Rasteriser starts on a new pixel onscreen -> interpolation gives us the various values that pixel needs (by blending between the various vertices) -> texture co-ordinates give us an x and y point on our texture -> pixel is made that colour, with some adjustments for lighting and all that jazz.

Groovy. But textures are also made up of pixels (which we call texels to save on headaches), so they can have aliasing issues of their own. Damn. Here's a picture of one of the problems:

Aliasing issues on textures
Aliasing issues on textures

Bilinear filtering:

All you have to do to see the effects of bilinear filtering is to run almost any game in software mode and then again with hardware acceleration. Bilinear filtering makes textures "smoother" and less blocky by grabbing four texels near the sample point and averaging their values to get a blended colour for the screen pixel. It's this "blurring" that smoothes out the textures on the screen and avoids aliasing misses.

Bilinear filtering
Bilinear filtering

There are a few problems with bilinear filtering though. The first and most visible is caused by mipmapping. Mipmapping is a technique used to manually limit aliasing issues by providing smaller versions of textures that an engine uses when objects are far away, this means that there are less texels that it's possible to miss when there are large "gaps" between sample points. Some engines use many levels of mipmaps, especially if it's possible to see very far into the distance.

Quake
Quake's picmip setting

Trivia: The famous "picmip 5" setting that Quake3 pros used simply scales down all the textures in the game, making a 512x512 texture effectively a 64x64 or 32x32 image instead. This blurs all the textures like crazy, but that's not why the pros did it: They were after the small increase in FPS caused by having smaller textures and less texel lookups and a rather debatable "visibility increase". Oh what crap textures you have grandma! All the better to see you with dear.

So, mipmapping was invented before bilinear filtering as a way to deal with distance aliasing issues. The smaller textures (remember how the U and V texture coordinates only range from 0 to 1? The different sizes of mipmapped textures are one of the reasons for that) allow for less "misses" of texels because there are less texels in total. But, when you're using bilinear filtering AND mipmapping, the smaller textures are blurred a lot more by the bilinear filter:

Mipmapping/bilinear filtering artifacts
Mipmapping/bilinear filtering artifacts

This sudden increase in blur is what we see in games as a horizontal or vertical "line" on floors and walls, especially when moving. It ends up looking like there's an error that stays a certain distance ahead of us in the game, which can get very frustrating. That's why there's the option to turn on trilinear filtering.



Words from the readers
No comments posted for this article yet. Have something to say? Make yourself heard below.
Have your say: