Skip to content
Part IA Michaelmas Term

Textures and Mipmaps

Texture Types

TypeDimensionsUse Case
1DLinear arrayGradients, lookup tables
2DWidth × heightMost common, images
3DVolume textureMedical imaging, volumetric effects
Cube map6 facesEnvironment mapping, skyboxes

1D, 2D, 3D textures and cube map

Texture Mapping Pipeline

  1. Define texture: Load image (TGA, PNG) as pixel data
  2. Specify UV mapping: Each vertex has texture coordinates (u,v)(u, v)
  3. Sampling: Look up texture colour using interpolated UV

Texture mapping from 3D model to 2D texture

Power-of-Two Textures

GPUs prefer dimensions that are powers of two (2n2^n, e.g., 256, 512, 1024):

  • Better caching and filtering performance
  • Required for mipmaps
  • Non-POT textures may have limited features

Texture Tiling

Repeating textures (brick, tile patterns) use wrapped coordinates:

T(u,v)=T(uu,vv)T(u, v) = T(u - \lfloor u \rfloor, v - \lfloor v \rfloor)

Example: T(1.1,0)=T(0.1,0)T(1.1, 0) = T(0.1, 0)—the texture wraps.

Texture Filtering

Magnification

Pixel larger than texel (zooming in):

FilterResult
Nearest neighbourPick closest texel (blocky)
BilinearWeighted average of 4 texels (smooth)

Nearest neighbour vs bilinear interpolation

Minification

Pixel smaller than texel (zooming out):

  • Many texels may map to one pixel
  • Causes aliasing and flickering
  • Solution: Use mipmaps

Mipmaps

A mipmap is a pre-filtered pyramid of textures at decreasing resolutions:

  • Each level is half the size of the previous
  • Only 1/3 additional storage required: 1+14+116+...=431 + \frac{1}{4} + \frac{1}{16} + ... = \frac{4}{3}
  • Used when textures are minified

Mipmap pyramid showing decreasing resolutions

Generating Mipmaps

glGenerateMipmap(GL_TEXTURE_2D);

Mipmap Filtering

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
ModeDescription
GL_LINEAR_MIPMAP_NEARESTUse nearest mipmap level, bilinear filtering
GL_LINEAR_MIPMAP_LINEARTrilinear (interpolate between mipmap levels)

Texture Parameters

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Wrap Modes

ModeBehaviour
GL_CLAMP_TO_EDGEClamp to edge texels
GL_REPEATTile texture
GL_MIRRORED_REPEATTile with mirroring

Advanced Texture Techniques

TechniqueDescription
Normal mappingPerturb normals for fake surface detail
Displacement mappingModify geometry (requires tessellation)
Environment mappingCube map stores reflections

Summary

  • Textures store image data sampled using UV coordinates
  • Filtering determines quality: nearest (fast), bilinear (smooth), trilinear (best)
  • Mipmaps pre-filter textures to prevent aliasing when minified
  • POT dimensions preferred for GPU efficiency

Past Paper Questions

2024 Paper 3 Question 4: Explain texture filtering. When would you use mipmaps?

2023 Paper 3 Question 4: What is the difference between GL_NEAREST and GL_LINEAR filtering?

2022 Paper 3 Question 4: Calculate the additional storage required for mipmaps on a 1024×1024 texture.