[TIPS] Mipmap Levels Debugging with a DDS Debug Texture

DDS debug texture
DDS debug texture (available in the GeeXLab demo)

DDS debugging in GeeXLab
Mipmapping debugging in GeeXLab

A mipmap is a collection of images with different resolutions. A mipmap is arranged in a chain where each image is half the size of the previous one. Each resolution is a level of detail or LOD. The first level (LOD 0) is the biggest image while the last level is the smallest image.

Mipmapping is a widely used technique in 3D programming and game development. Almost all games use mipmaping. When the camera is near a textured object, the level 0 of the mipmap is used. And when the camera moves away from the object, a smaller resolution is used (smaller resolution = higher level).

Debugging a mipmap chain can be made easier with the use of a debug DDS texture. This DDS texture (provided in the GeeXLab demo below) is made of 7 mipmap levels: level 0: red, level 1: green, level 2: blue, level 3: yellow, level 4: pink, level 5: black and level 6: white.

The simple GeeXLab demo I coded for this article uses a GLSL shader to render a textured plane.

The GLSL shader is very simple:

void main(void)
  gl_Position = ftransform();
  gl_TexCoord[0] = gl_MultiTexCoord0;
uniform sampler2D colorMap;
uniform float lod;
void main (void)
  vec4 base = texture2DLod(colorMap, gl_TexCoord[0].st, lod);
  //vec4 base = texture2D(colorMap, gl_TexCoord[0].st);
  gl_FragColor = base;	

The texture2DLod GLSL function makes it possible to fetch the texels of a particular mipmap level. You can select the level (lod) with the tweak bar:

DDS debugging in GeeXLab
Mipmap level 0

DDS debugging in GeeXLab
Mipmap level 1

DDS debugging in GeeXLab
Mipmap level 3

And when you replace texture2DLod by texture2D in the fragment shader, you can see how OpenGL does the transition between two levels when you move the camera away the plane:

DDS debugging in GeeXLab

DDS debugging in GeeXLab

DDS debugging in GeeXLab

And depending on the point of view, you can see all mipmap levels in the same time:

DDS debugging in GeeXLab

You can download the GeeXLab demo here
Download GXL - Mipmap level debugging demo Version 2010.03.11

You need the latest version of GeeXLab to play with the demo. You can download GeeXLab HERE.

Just drop the mipmap_debug.xml into GeeXLab and you’re ready.

For this demo, I used Lua as scripting language so if you don’t have Python or don’t want to install it, just download the version of GeeXLab without Python.

Some links about mipmapping:


↑ Grab this Headline Animator