{
 "id": "mipmapping-anisotropic-filtering",
 "title": "Mipmapping and anisotropic texture filtering",
 "aliases": [
  "trilinear filtering",
  "EWA filtering",
  "mip chain"
 ],
 "domain": "materials",
 "subdomain": "texture filtering",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "cpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 1983,
 "inputs": [
  "texture",
  "uv-atlas"
 ],
 "outputs": [
  "texture"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Texture minification fundamentals: a prefiltered mip pyramid chosen by screen-space derivatives (bilinear, trilinear), then anisotropic sampling that takes several taps along the footprint's long axis, with EWA as the high-quality reference.",
 "how_it_works": "A mip chain stores the texture at half resolution repeatedly, each level a box or better prefiltered average. At shading time the hardware measures how many texels fall inside one pixel from the UV derivatives and picks level lambda = log2 of that footprint size; trilinear filtering blends the two nearest levels. The catch is that a pixel footprint on a receding floor is a long thin ellipse, while the mip level is sized for the long axis, so everything gets blurred in the short direction. Anisotropic filtering instead picks the level from the short axis and takes N taps spread along the long axis (N capped at 2x to 16x). Heckbert's elliptical weighted average fits an ellipse in texture space and sums texels with a Gaussian-like weight, the quality reference that hardware approximates. Compute-shader or ray-traced renderers must supply their own derivatives or ray differentials since implicit derivatives only exist in fragment quads.",
 "when_to_use": "Always enable mipmaps on sampled colour textures; add 8x-16x anisotropy for ground, roads and walls seen at grazing angles. Use `block-texture-compression` or `basis-universal-ktx2` so the mip chain stays small. Prefer `toksvig-mipmapping` or `normal-distribution-filtering` for normal maps and roughness, because plain averaged normals lose specular energy. Prefer virtual texturing or manual LOD when streaming matters more than filtering. For lookups inside ray-tracing shaders, compute ray differentials explicitly.",
 "cost": {
  "class": "cheap",
  "notes": "Hardware sampler cost; anisotropy multiplies texture taps and bandwidth by up to the max ratio."
 },
 "failure_modes": [
  "Textures not generated or non-power-of-two edge cases leave shimmering at distance",
  "Premultiplied alpha or sRGB data averaged in the wrong space darkens or tints lower mips",
  "Alpha-tested foliage fades out in higher mips unless alpha coverage is preserved",
  "Normal maps averaged naively flatten and remove highlights, see toksvig-mipmapping",
  "Anisotropic filtering cannot fix derivative problems such as non-uniform control flow, producing seams at discontinuities",
  "Tiled atlases bleed neighbour tiles into lower mips without gutters"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/964967.801126",
   "type": "paper",
   "title": "Pyramidal parametrics",
   "authors": [
    "Lance Williams"
   ],
   "year": 1983,
   "venue": "ACM SIGGRAPH Computer Graphics",
   "url": "https://doi.org/10.1145/964967.801126",
   "ids": {
    "doi": "10.1145/964967.801126"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964967.801126",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964967.801126",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964967.801126",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964967.801126",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964967.801126",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "williams1983pyramidal"
  },
  {
   "role": "primary",
   "key": "doi:10.1109/mcg.1986.276738",
   "type": "paper",
   "title": "Creating Raster Omnimax Images from Multiple Perspective Views Using the Elliptical Weighted Average Filter",
   "authors": [
    "Ned Greene",
    "Paul Heckbert"
   ],
   "year": 1986,
   "venue": "IEEE Computer Graphics and Applications",
   "url": "https://doi.org/10.1109/mcg.1986.276738",
   "ids": {
    "doi": "10.1109/mcg.1986.276738"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276738",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276738",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276738",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276738",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.1986.276738",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "greene1986creating"
  },
  {
   "role": "tutorial",
   "key": "url:https://www.pbr-book.org/4ed/Textures_and_Materials/Image_Texture",
   "type": "tutorial",
   "title": "Image Texture (pbrt-v4)",
   "authors": [
    "Matt Pharr",
    "Wenzel Jakob",
    "Greg Humphreys"
   ],
   "year": null,
   "venue": "pbr-book.org",
   "url": "https://www.pbr-book.org/4ed/Textures_and_Materials/Image_Texture",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260810024321/https://pbr-book.org/4ed/Textures_and_Materials/Image_Texture",
     "timestamp": "20260810024321"
    },
    "page_title": "Image Texture",
    "host": "pbr-book.org",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://www.pbr-book.org/4ed/Textures_and_Materials/Image_Texture → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.pbr-book.org/4ed/Textures_and_Materials/Image_Texture → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://www.pbr-book.org/4ed/Textures_and_Materials/Image_Texture → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "pharrimage"
  }
 ],
 "presets": [
  {
   "id": "mipmapping-anisotropic-filtering-live",
   "title": "Mipmapping & Anisotropic Filtering — blurry isotropic trilinear mips (left) vs crisp multi-tap anisotropic filtering (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_ANISO_TAPS": 8,
    "P_TEX_FREQ": 1.6,
    "P_CAM_PITCH": 0.22,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_ANISO_TAPS = 8.0; // P Anisotropic Taps [2.0, 16.0, 2.0]\nconst float P_TEX_FREQ = 1.60; // P Tile Frequency [0.8, 3.0, 0.1]\nconst float P_CAM_PITCH = 0.22; // P Grazing Pitch [0.08, 0.45, 0.02]\nconst float P_SPLIT = 0.48; // P Trilinear / Aniso Split [0.0, 1.0, 0.02]\n\n// Analytically band-limited procedural texture at a given isotropic mip level 'lod'\nvec3 evalTexMip(vec2 p, float lod) {\n  float blur = exp2(max(lod, 0.0)) * 0.065;\n  // Checkerboard filtered via analytical box/Gaussian attenuation per harmonic\n  vec2 s = sin(p * 6.2831853);\n  float att1 = exp(-blur * blur * 18.0);\n  float att2 = exp(-blur * blur * 65.0);\n  float chk = 0.5 + 0.5 * clamp((s.x * s.y) * 6.0, -1.0, 1.0) * att1;\n\n  // Fine architectural grout lines & calibration target rings inside each tile\n  vec2 f = fract(p) - 0.5;\n  float r = length(f);\n  float ring = exp(-pow((r - 0.26) / max(0.032 + blur * 0.4, 0.01), 2.0)) * att2;\n  float lines = (exp(-pow(abs(f.x) / max(0.018 + blur * 0.35, 0.01), 2.0))\n               + exp(-pow(abs(f.y) / max(0.018 + blur * 0.35, 0.01), 2.0))) * 0.5 * att2;\n\n  vec3 tileA = vec3(0.14, 0.20, 0.28);\n  vec3 tileB = vec3(0.84, 0.82, 0.76);\n  vec3 base = mix(tileA, tileB, chk);\n  base = mix(base, vec3(0.96, 0.44, 0.14), clamp(ring, 0.0, 1.0));\n  base = mix(base, vec3(0.12, 0.78, 0.88), clamp(lines * 0.75, 0.0, 1.0));\n  return base;\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float sx = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool useAniso = sx >= split;\n\n  float freq = clamp(P_TEX_FREQ, 0.5, 4.0);\n  float pitch = clamp(P_CAM_PITCH, 0.06, 0.55);\n  int taps = int(clamp(floor(P_ANISO_TAPS + 0.5), 2.0, 16.0));\n\n  // Camera skimming low over an infinite textured corridor floor\n  vec3 ro = vec3(0.28 * sin(iTime * 0.35), 0.52, iTime * 0.65);\n  float cp = cos(pitch), sp = sin(pitch);\n  vec3 rd0 = normalize(vec3(uv.x, uv.y, -1.35));\n  vec3 rd = vec3(rd0.x, rd0.y * cp - rd0.z * sp, rd0.y * sp + rd0.z * cp);\n\n  vec3 sky = mix(vec3(0.74, 0.82, 0.92), vec3(0.14, 0.28, 0.54), smoothstep(-0.02, 0.42, rd.y));\n  vec3 col = sky;\n\n  if (rd.y < -0.002) {\n    float t = -ro.y / rd.y;\n    vec3 p = ro + rd * t;\n    vec2 texUV = p.xz * freq;\n\n    // Analytical screen-space footprint Jacobian (dUV/dx, dUV/dy) via adjacent ray differentials\n    vec2 duvX = vec2(1.0 / max(iResolution.y, 1.0), 0.0);\n    vec2 duvY = vec2(0.0, 1.0 / max(iResolution.y, 1.0));\n    vec3 rdX0 = normalize(vec3(uv.x + duvX.x, uv.y, -1.35));\n    vec3 rdX = vec3(rdX0.x, rdX0.y * cp - rdX0.z * sp, rdX0.y * sp + rdX0.z * cp);\n    vec3 rdY0 = normalize(vec3(uv.x, uv.y + duvY.y, -1.35));\n    vec3 rdY = vec3(rdY0.x, rdY0.y * cp - rdY0.z * sp, rdY0.y * sp + rdY0.z * cp);\n\n    vec2 pX = (ro + rdX * (-ro.y / min(rdX.y, -0.001))).xz * freq;\n    vec2 pY = (ro + rdY * (-ro.y / min(rdY.y, -0.001))).xz * freq;\n    vec2 ddx = pX - texUV;\n    vec2 ddy = pY - texUV;\n\n    float lenX = length(ddx);\n    float lenY = length(ddy);\n    float majorLen = max(lenX, lenY);\n    float minorLen = max(min(lenX, lenY), 1e-5);\n    vec2 majorAxis = (lenX >= lenY) ? ddx : ddy;\n\n    if (!useAniso) {\n      // Isotropic trilinear mipmap: picks LOD from major axis -> wipes out sharp detail along minor axis!\n      float isoLod = log2(max(majorLen * 14.0, 1.0));\n      col = evalTexMip(texUV, isoLod);\n    } else {\n      // Anisotropic filtering: chooses LOD from minor axis and integrates N taps along major axis\n      float maxAniso = float(taps);\n      float ratio = min(majorLen / minorLen, maxAniso);\n      float anisoLod = log2(max((majorLen / max(ratio, 1.0)) * 14.0, 1.0));\n      vec3 acc = vec3(0.0);\n      for (int i = 0; i < 16; i++) {\n        if (i >= taps) break;\n        float fi = (float(i) + 0.5) / float(taps) - 0.5;\n        acc += evalTexMip(texUV + majorAxis * fi, anisoLod);\n      }\n      col = acc / float(taps);\n    }\n\n    // Subtle distance aerial fade\n    float fog = 1.0 - exp(-t * 0.042);\n    col = mix(col, sky, clamp(fog, 0.0, 1.0));\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(sx - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "mipmapping-anisotropic-filtering",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:15.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7653,
      "std": 0.0931,
      "min": 0.6402,
      "max": 0.9014
     },
     "image": "/specimens/mipmapping-anisotropic-filtering-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "toksvig-mipmapping",
  "normal-distribution-filtering",
  "block-texture-compression",
  "basis-universal-ktx2",
  "hex-tiling"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "toksvig-mipmapping",
   "why": "Mipped normal-map lengths shrink with distance; Toksvig converts that loss into extra roughness at each level."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/materials/mipmapping-anisotropic-filtering.json"
 },
 "solves": [
  "textures shimmer and sparkle in the distance",
  "ground texture blurry at grazing view angles",
  "moire patterns on checkerboard or fine patterns",
  "need to choose trilinear versus anisotropic sampling",
  "alpha tested leaves vanish when far away"
 ],
 "authority": "Williams, 1983",
 "url": "https://texelatlas.vercel.app/t/mipmapping-anisotropic-filtering/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 2.64,
  "tier": "light",
  "p50_ms": 0.0868,
  "p95_ms": 0.0912,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "mipmapping-anisotropic-filtering-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 2.28,
   "tier": "light",
   "p50_ms": 0.0362,
   "p95_ms": 0.0377,
   "speedup_x": 2.4,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.9,
   "tier": "feather",
   "p50_ms": 0.0547,
   "p95_ms": 0.0548,
   "speedup_x": 1.59,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}