Part IA Michaelmas Term
Textures and Mipmaps
Texture Types
| Type | Dimensions | Use Case |
|---|---|---|
| 1D | Linear array | Gradients, lookup tables |
| 2D | Width × height | Most common, images |
| 3D | Volume texture | Medical imaging, volumetric effects |
| Cube map | 6 faces | Environment mapping, skyboxes |
Texture Mapping Pipeline
- Define texture: Load image (TGA, PNG) as pixel data
- Specify UV mapping: Each vertex has texture coordinates
- Sampling: Look up texture colour using interpolated UV
Power-of-Two Textures
GPUs prefer dimensions that are powers of two (, 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:
Example: —the texture wraps.
Texture Filtering
Magnification
Pixel larger than texel (zooming in):
| Filter | Result |
|---|---|
| Nearest neighbour | Pick closest texel (blocky) |
| Bilinear | Weighted average of 4 texels (smooth) |
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:
- Used when textures are minified
Generating Mipmaps
glGenerateMipmap(GL_TEXTURE_2D);
Mipmap Filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
| Mode | Description |
|---|---|
GL_LINEAR_MIPMAP_NEAREST | Use nearest mipmap level, bilinear filtering |
GL_LINEAR_MIPMAP_LINEAR | Trilinear (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
| Mode | Behaviour |
|---|---|
GL_CLAMP_TO_EDGE | Clamp to edge texels |
GL_REPEAT | Tile texture |
GL_MIRRORED_REPEAT | Tile with mirroring |
Advanced Texture Techniques
| Technique | Description |
|---|---|
| Normal mapping | Perturb normals for fake surface detail |
| Displacement mapping | Modify geometry (requires tessellation) |
| Environment mapping | Cube 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.