Mipmapping – Interactive 3D Graphics

Mipmapping – Interactive 3D Graphics

September 11, 2019 7 By Bernardo Ryan


With magnification we’ve found that if a texel covered too many pixels, we could just make our original checkered texter larger and larger so that about one texel covered one pixel. With minification we’d like each pixel to cover no more than one texel. The GPU has built into it, special functionality that implements an algorithm called mip mapping. With mip mapping the GPU computes approximately what the texel to pixel ratio is. If this ratio is less than one Magnification happens and the mag filter takes effect. If this ratio is greater than one, minification is happening. This is where mid mapping comes in. What the GPU does, is determines the ratio of texels to pixels. If this ratio gets much larger than one to one A lower resolution version of the texture is used instead. As this ratio gets higher and higher, a lower and lower resolution of the texture gets used. These textures can be thought of as forming a pyramid. For example, say a pixel needs the texture color. Instead of taking whatever texel happens to cover the center of the pixel down at the bottom level. The GPU determines the texel to pixel ratio for this pixel to see how high up the pyramid to go. The texture at this level of the pyramid is then sampled. Since the ratio of texels to pixels is about one to one for this lower resolution texture, the rendering looks much better without the noise we saw before. In fact, for even better quality rendering, we can set the GPU to linearly interpolate between levels. This is called trilinear filtering. Say our ratio is in between two pyramid levels. We then sample the texture above and below from where our sample is in the pyramid, and interpolate between these two samples. My example pyramid was not drawn to scale. Within the GPU, the pyramid is created and stored in powers of 2. That is, if you start with a texture that’s 64 by 64, the pyramid is formed with this texture, a 32 by 32 texture, a 16 by 16 texture, 8 by 8. Four by four, two by two and one by one at the end. This sort of textures is called the mipmap pyramid or the mipmap chain. Each smaller texture is derived from the larger one. One technique is to simply average the four texels of the larger texture to make the smaller which can be done in advance or by the GPU itself. There are some subtleties, such as gamma correction, that can change how these levels are formed. That’s for a later lesson. This is an important point, so pay attention. You want to make your textures to be powers of two in size, both in rows and columns. You will not be able to use mipmapping if you don’t. GPUs generally expect powers of two, so don’t disappoint them, unless you know what you’re doing and have a very good reason for doing so. Give the new version of the demo a try. You can now pick mipmapping as a filtering option for minification.