Image Mipmapping

August 19

1. Mipmap Basics

ItemDescription
PurposePre-generate multiple lower-resolution versions of textures to reduce aliasing and moiré patterns during distant sampling, and improve cache hits and performance.
Pyramid LevelsIf the original image size is (W×H)(W \times H), the (l)(l)-th level is usually (max(1,W/2l)×max(1,H/2l))(\max(1, \lfloor W/2^l \rfloor) \times \max(1, \lfloor H/2^l \rfloor)), down to 1x1.
Storage OverheadThe total area of all levels is about (13)(\frac{1}{3}) of the original image (more precisely, (k=14k=13)(\sum_{k=1}^{\infty} 4^{-k} = \frac{1}{3})), so the total texture memory is about (43)(\frac{4}{3}) of the original image.

2. Common Downsampling Algorithms

Algorithm/TypeApproachAdvantagesDisadvantages/Notes
Box Filter (Mean/Box Filter)Average every 2x2 pixels to generate the next level. Formula: C=14i=01j=01C2x+i,2y+jC' = \frac{1}{4}\sum_{i=0}^{1}\sum_{j=0}^{1} C_{2x+i,2y+j}Simple, fastPoor frequency roll-off, prone to aliasing; not smooth for high-frequency textures
Triangle/Bilinear Filter (Linear Kernel)Downsample after low-pass filtering with linear weights, or use triangle kernelSmoother than box, slightly better edge preservationSlightly higher cost than box
Gaussian FilterApply Gaussian blur before downsamplingCloser to ideal low-pass, better anti-aliasingHeavier computation, may blur details
Lanczos (Windowed sinc)Resample using Lanczos kernel (commonly a=2 or 3)Sharp and excellent anti-aliasingHighest cost, may cause slight ringing
Mitchell-Netravali / Catmull-Rom (Cubic Family)Resample with cubic convolution kernelGood balance of sharpness and smoothness, moderate costCommon in offline pipelines, texture baking
Gamma/Color Space HandlingAverage in linear space to avoid darkening in sRGB. Process: sRGB → linear; filter/downsample; linear → sRGB. Alpha: use premultiplied alpha before filtering/downsampling.Physically correct color-
Normal Map SpecificTransform to tangent space unit vectors, accumulate then normalize, remap offset if needed. Can weight (e.g. Z or curvature) to reduce bias.Physically correct normalsCannot linearly average RGB normals

3. Common Runtime Filtering Algorithms

Algorithm/TypeApproachAdvantagesDisadvantages/Notes
Nearest Mipmap Nearest (MMN)Selects the nearest mip level, uses nearest point samplingFastestBlocky appearance
Nearest Mipmap Linear (NML)Selects the nearest mip level, uses bilinear samplingSmoother than MMNMay jump when switching levels
Linear Mipmap Nearest (LMN)Samples two adjacent mip levels with nearest point, then linearly interpolates-Rarely used alone
Trilinear FilteringBilinear sampling on two levels, then linear interpolation by LOD fractionGood balance, commonly default-
Anisotropic FilteringMulti-point sampling along major axis in oblique view, suppresses blur/flicker. With mipmap: each candidate mip level samples along anisotropic direction. Parameter: anisotropy level (e.g. 4x, 8x, 16x) affects quality and performance.High quality for oblique viewsCost increases with level
LOD Control & BiasHardware estimates LOD by screen-space derivatives: λ=log2(max((u/x)2+(v/x)2, (u/y)2+(v/y)2))\lambda = \log_2 \left(\max \left(\sqrt{(\partial u/\partial x)^2 + (\partial v/\partial x)^2},\ \sqrt{(\partial u/\partial y)^2 + (\partial v/\partial y)^2}\right) \right). Bias can be added to control sharpness/noise tradeoff.Adjustable sharpness-

4. Special Mipmap Variants

TypeDescription
RipmapsIndependently downsample u and v to get a rectangular pyramid, suitable for strong anisotropic scaling.
Summed-Area Tables (SAT)Used for fast box filtering and variable-size region averaging, high storage cost.
Sparse/Virtual TexturesTile-based storage and on-demand loading of mip tiles. MegaTexture, Tiled Resources.
Specular/Gloss mip chainPre-filter roughness-related maps by physical model (e.g. prefiltered mipmap for environment reflection, BRDF-Convolved Env Map).
Alpha Coverage Preserving MipmapsAdjust alpha during downsampling of transparent textures to preserve coverage, reduce distant flicker.

Common Issues

  • Averaging in sRGB space: causes color shift and darkening.
  • Directly averaging normal or specular roughness maps: leads to physical inconsistency.
  • Not preserving coverage for transparent textures: distant flicker.
  • Mipmap level boundary seams: handle wrap/clamp and border pixel copy during generation to avoid seams.

© 2020 - 2026 Ruiyao Luo

26/03/04 15:15

PROD

#764ff88