{
 "id": "toksvig-mipmapping",
 "title": "Toksvig normal-map filtering",
 "aliases": [],
 "domain": "materials",
 "subdomain": "specular antialiasing",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 2005,
 "inputs": [
  "normals",
  "texture"
 ],
 "outputs": [
  "texture",
  "material-params"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Mipmapping a normal map shortens the averaged normal; Toksvig turns that shortening into extra roughness so minified bumpy surfaces blur their highlight instead of shimmering.",
 "how_it_works": "Averaging unit normals over a texel footprint produces a vector of length less than 1, and the shorter it is, the more the underlying normals disagree. Toksvig observes that for a Gaussian-like spread of normals the length encodes variance, and that the Blinn-Phong highlight over that distribution equals a broader lobe. So he adjusts the specular exponent by a factor ft = |Na| / (|Na| + s (1 - |Na|)) where s is the exponent. Modern variants apply the same idea to GGX by adding variance to roughness squared. The correction is either baked into per-mip roughness (or gloss) maps at texture-authoring time, or computed from the fetched normal's length when normal maps are stored unnormalised.",
 "when_to_use": "Choose it as a cheap baseline for stopping specular shimmering on normal-mapped surfaces under minification. Prefer `normal-distribution-filtering` or `leadr-mapping` when you also need correct handling of the visible-slope distribution (LEADR) or per-pixel variance filtering with screen-space derivatives. Needed whenever `normal-mapping-mikktspace` is used with glossy materials.",
 "cost": {
  "class": "cheap",
  "notes": "Baked into mip chain, or one length computation per pixel."
 },
 "failure_modes": [
  "Needs unnormalised normals in mips; normalised DXT/BC5 normals lose the length information",
  "Assumes isotropic Gaussian normal spread, so directional grooves lose their stretched highlight",
  "Only affects specular, not diffuse brightness changes with scale",
  "Roughness bake must be redone if texture is retiled or rescaled"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1080/2151237x.2005.10129203",
   "type": "paper",
   "title": "Mipmapping Normal Maps",
   "authors": [
    "Michael Toksvig"
   ],
   "year": 2005,
   "venue": "Journal of Graphics Tools",
   "url": "https://doi.org/10.1080/2151237x.2005.10129203",
   "ids": {
    "doi": "10.1080/2151237x.2005.10129203"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2005.10129203",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2005.10129203",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2005.10129203",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2005.10129203",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1080/2151237x.2005.10129203",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "toksvig2005mipmapping"
  }
 ],
 "presets": [
  {
   "id": "toksvig-mipmapping-specimen",
   "title": "Toksvig filtering of a sub-pixel bump normal field: aliased (left) vs filtered (right)",
   "runtime": "glsl-fragment",
   "params": {
    "SHININESS": 90,
    "BUMP_FREQ": 420,
    "BUMP_AMP": 0.55
   },
   "code": "// Toksvig specular antialiasing. A sphere with a very high-frequency bump normal field (sub-pixel period).\n// Left: Blinn-Phong on the single pixel-centre normal: highlights sparkle/alias.\n// Right: the 4x4 footprint average normal (what a mip would store) is shorter than 1; Toksvig\n// ft = |N| / (|N| + s (1 - |N|)) shrinks the exponent so the highlight blurs instead of sparkling.\nconst float SHININESS = 90.0;\nconst float BUMP_FREQ = 420.0;\nconst float BUMP_AMP = 0.55;\n\nvec3 bumpNormal(vec2 fc, out bool hit) {\n  vec2 uv = (fc - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 ro = vec3(0.0, 0.0, 4.0), rd = normalize(vec3(uv, -2.4));\n  float b = dot(ro, rd); float h = b * b - dot(ro, ro) + 0.64;\n  hit = h > 0.0; if (!hit) return vec3(0.0, 0.0, 1.0);\n  vec3 p = ro + rd * (-b - sqrt(h)); vec3 n = normalize(p);\n  vec3 t1 = normalize(cross(n, vec3(0.0, 1.0, 0.2))), t2 = cross(n, t1);\n  return normalize(n + BUMP_AMP * (sin(BUMP_FREQ * p.x + 3.0 * p.y) * t1 + sin(BUMP_FREQ * 1.3 * p.y - 2.0 * p.x) * t2));\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec3 v = vec3(0.0, 0.0, 1.0);\n  vec3 l = normalize(vec3(-0.4, 0.5, 0.8));\n  vec3 hv = normalize(l + v);\n  bool hit; vec3 n0 = bumpNormal(fragCoord, hit);\n  vec3 col = vec3(0.03) + 0.04 * (fragCoord.y / iResolution.y);\n  if (hit) {\n    vec3 avg = vec3(0.0);\n    for (int j = 0; j < 4; j++) for (int i = 0; i < 4; i++) {\n      bool hh; avg += bumpNormal(fragCoord + (vec2(float(i), float(j)) - 1.5) * 0.25 * 4.0 / 1.0 * 0.5, hh);\n    }\n    avg /= 16.0; float len = length(avg);\n    bool left = fragCoord.x < 0.5 * iResolution.x;\n    vec3 n = left ? n0 : normalize(avg);\n    float s = left ? SHININESS : SHININESS * len / (len + SHININESS * (1.0 - len));\n    float norm = (s + 8.0) / 25.13;\n    float nl = max(dot(n, l), 0.0);\n    col = vec3(0.35, 0.12, 0.1) * nl + vec3(1.0) * norm * pow(max(dot(n, hv), 0.0), s) * nl * 0.9;\n  }\n  if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);\n  col = col / (1.0 + col);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "toksvig-mipmapping",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.3047,
      "std": 0.1516,
      "unique_colors": 116
     },
     "image": "/specimens/toksvig-mipmapping-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "normal-distribution-filtering",
  "leadr-mapping",
  "normal-mapping-mikktspace",
  "ggx-trowbridge-reitz"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [],
 "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/toksvig-mipmapping.json"
 },
 "solves": [
  "normal-mapped highlights shimmer in the distance",
  "mip levels lose roughness from averaged normals",
  "specular sparkle on minified bump maps",
  "cheap baked fix for specular aliasing",
  "bumpy surfaces should blur out far away"
 ],
 "authority": "Toksvig, 2005",
 "url": "https://texelatlas.vercel.app/t/toksvig-mipmapping/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 12.88,
  "tier": "moderate",
  "p50_ms": 0.4236,
  "p95_ms": 0.4287,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "toksvig-mipmapping-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 9.36,
   "tier": "moderate",
   "p50_ms": 0.1489,
   "p95_ms": 0.1506,
   "speedup_x": 2.84,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 7.72,
   "tier": "moderate",
   "p50_ms": 0.2222,
   "p95_ms": 0.2227,
   "speedup_x": 1.91,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}