{
 "id": "leadr-mapping",
 "title": "LEADR mapping",
 "aliases": [],
 "domain": "materials",
 "subdomain": "specular antialiasing",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 2013,
 "inputs": [
  "texture",
  "normals",
  "mesh"
 ],
 "outputs": [
  "texture",
  "material-params"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "Linear, Efficient, Antialiased Displacement and Reflectance mapping: pre-filters displaced surfaces with a linear mip-mappable representation so that shading under minification reproduces the average of the detailed surface's BRDF.",
 "how_it_works": "Displaced geometry or bump detail below pixel size should not be sampled; it should be folded into the BRDF. Dupuy et al. express the distribution of slopes of the displaced surface as a Beckmann-like lobe, whose first and second moments (mean slope, covariance of slope) are linear and so can be averaged in a mip pyramid. Moments of the height-field's slope are stored; at runtime the filtered moments rebuild a Gaussian slope distribution of the surface, convolved with the base roughness and fed into the shading model, and also used for tracing the displacement via ray marching on the filtered pyramid. The key advantage over Toksvig is that anisotropy and non-zero mean slope are retained, so a groove pattern remains anisotropic when minified.",
 "when_to_use": "Choose it for displacement-mapped or heavily bumped surfaces viewed over a wide range of scales (ocean waves, rock, rough metal) where specular detail must stay stable and plausible. Prefer `toksvig-mipmapping` as the simpler, isotropic baseline. Prefer `normal-distribution-filtering` for runtime-derived filtering without per-texture moment pyramids.",
 "cost": {
  "class": "medium",
  "notes": "Extra moment textures and a ray-march for displacement; heavier than normal mapping."
 },
 "failure_modes": [
  "Requires precomputed moment mip chains with 2-3 extra channels per displacement texture",
  "Gaussian slope model fails for multi-modal slope distributions like two facing facets",
  "Tracing displacement inherits the artifacts of heightfield ray marching",
  "Not implemented in mainstream engines, so use means custom pipeline"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/2508363.2508422",
   "type": "paper",
   "title": "Linear efficient antialiased displacement and reflectance mapping",
   "authors": [
    "Jonathan Dupuy",
    "Eric Heitz",
    "Jean-Claude Iehl",
    "Pierre Poulin",
    "Fabrice Neyret",
    "Victor Ostromoukhov"
   ],
   "year": 2013,
   "venue": "ACM Transactions on Graphics",
   "url": "https://doi.org/10.1145/2508363.2508422",
   "ids": {
    "doi": "10.1145/2508363.2508422"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2508363.2508422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2508363.2508422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2508363.2508422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2508363.2508422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2508363.2508422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "dupuy2013linear"
  }
 ],
 "presets": [
  {
   "id": "leadr-mapping-live",
   "title": "LEADR Mapping — point-sampled displaced surface aliasing (left) vs linear prefiltered slope-moment anisotropic BRDF (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_GROOVE_FREQ": 24,
    "P_SLOPE_AMP": 0.72,
    "P_BASE_ROUGH": 0.14,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_GROOVE_FREQ = 24.0; // P Groove Frequency [8.0, 48.0, 2.0]\nconst float P_SLOPE_AMP = 0.72; // P Displacement Slope [0.15, 1.2, 0.05]\nconst float P_BASE_ROUGH = 0.14; // P Base Roughness [0.06, 0.45, 0.02]\nconst float P_SPLIT = 0.48; // P Point / LEADR Split [0.0, 1.0, 0.02]\n\nvec3 evalEnv(vec3 d) {\n  vec3 sky = mix(vec3(0.06, 0.09, 0.14), vec3(0.26, 0.42, 0.66), smoothstep(-0.15, 0.75, d.y));\n  vec3 l1 = normalize(vec3(0.55, 0.48, -0.68));\n  vec3 l2 = normalize(vec3(-0.62, 0.36, -0.58));\n  float s1 = pow(max(dot(d, l1), 0.0), 48.0);\n  float s2 = pow(max(dot(d, l2), 0.0), 24.0);\n  return sky + vec3(2.8, 2.3, 1.7) * s1 + vec3(0.65, 1.25, 1.95) * s2;\n}\n\n// Analytical 2D anisotropic brushed + chevron micro-displacement height gradient\nvec2 evalSlope(vec2 uv, float freq, float amp) {\n  float a = uv.x * freq;\n  float b = uv.y * freq * 0.25 + sin(uv.x * freq * 0.12) * 1.4;\n  float gx = cos(a) * amp + 0.35 * cos(a * 2.13 + 0.8) * amp;\n  float gy = 0.28 * cos(b) * amp;\n  return vec2(gx, gy);\n}\n\n// Evaluate Gaussian anisotropic slope-distribution NDF from LEADR moments (Dupuy et al. 2013)\nfloat evalLEADR_NDF(vec2 hSlope, vec2 meanSlope, vec3 cov, float baseVar) {\n  vec2 d = hSlope - meanSlope;\n  float sxx = max(cov.x + baseVar, 1e-4);\n  float syy = max(cov.y + baseVar, 1e-4);\n  float sxy = clamp(cov.z, -0.95 * sqrt(sxx * syy), 0.95 * sqrt(sxx * syy));\n  float det = max(sxx * syy - sxy * sxy, 1e-6);\n  float invDet = 1.0 / det;\n  float quad = (syy * d.x * d.x - 2.0 * sxy * d.x * d.y + sxx * d.y * d.y) * invDet;\n  return exp(-0.5 * min(quad, 40.0)) / (6.2831853 * sqrt(det));\n}\n\nfloat beckmannLambda(float a) {\n  if (a >= 1.6) return 0.0;\n  return (1.0 - 1.259 * a + 0.396 * a * a) / max(3.535 * a + 2.181 * a * a, 1e-4);\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 useLEADR = sx >= split;\n\n  float freq = clamp(P_GROOVE_FREQ, 4.0, 64.0);\n  float amp = clamp(P_SLOPE_AMP, 0.05, 1.5);\n  float baseRough = clamp(P_BASE_ROUGH, 0.04, 0.6);\n  float baseVar = 0.5 * baseRough * baseRough;\n\n  vec3 ro = vec3(0.0, 0.62, 1.85);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.16, -1.42));\n  vec3 col = evalEnv(rd) * 0.45;\n\n  // Intersect receding grooved brass plane (y = -0.35) and a grooved hero sphere\n  vec3 sphC = vec3(0.0, 0.18, -0.55);\n  float sphR = 0.52;\n  vec3 oc = ro - sphC;\n  float b = dot(oc, rd);\n  float c = dot(oc, oc) - sphR * sphR;\n  float disc = b * b - c;\n  float tSph = (disc > 0.0 && (-b - sqrt(disc)) > 0.05) ? (-b - sqrt(disc)) : 1e5;\n  float tPl = (rd.y < -0.005) ? ((-0.35 - ro.y) / rd.y) : 1e5;\n  if (tPl < 0.05 || tPl > 45.0) tPl = 1e5;\n\n  float tHit = min(tSph, tPl);\n  if (tHit < 1e4) {\n    vec3 p = ro + rd * tHit;\n    vec3 nG;\n    vec3 T, B;\n    vec2 muv;\n    float footprint;\n\n    if (tSph < tPl) {\n      nG = normalize(p - sphC);\n      float phi = atan(nG.z, nG.x) + iTime * 0.18;\n      float th = acos(clamp(nG.y, -1.0, 1.0));\n      muv = vec2(phi * 1.15, th * 1.15);\n      T = normalize(vec3(-sin(phi), 0.0, cos(phi)));\n      B = cross(nG, T);\n      footprint = (tHit / max(iResolution.y, 1.0)) * 2.2 / max(abs(dot(nG, -rd)), 0.12);\n    } else {\n      nG = vec3(0.0, 1.0, 0.0);\n      T = vec3(1.0, 0.0, 0.0);\n      B = vec3(0.0, 0.0, 1.0);\n      muv = p.xz + vec2(0.0, -iTime * 0.25);\n      footprint = (tHit / max(iResolution.y, 1.0)) * 2.8 / max(abs(rd.y), 0.04);\n    }\n\n    vec3 v = -rd;\n    vec3 l1 = normalize(vec3(0.55 * cos(iTime * 0.35), 0.52, -0.65));\n    vec3 l2 = normalize(vec3(-0.62, 0.42, -0.52));\n    vec3 f0 = (tSph < tPl) ? vec3(0.95, 0.74, 0.36) : vec3(0.76, 0.78, 0.82);\n\n    // Filter strength grows linearly with footprint * frequency (mip level of LEADR moments!)\n    float filterK = clamp(footprint * freq * 0.48, 0.0, 1.0);\n    float envMip = smoothstep(0.0, 1.0, filterK);\n\n    // Instantaneous slope at pixel center\n    vec2 rawSlope = evalSlope(muv, freq, amp);\n    // LEADR linear moments: E[s] attenuates as footprint spans cycles, while covariance E[s*s^T] - E[s]E[s]^T absorbs the variance!\n    float atten = exp(-2.4 * filterK * filterK);\n    vec2 meanSlope = useLEADR ? (rawSlope * atten) : rawSlope;\n    // Exact variance of cos(a) + 0.35*cos(2.13a) is 0.5*(1 + 0.35^2)*amp^2 = 0.561*amp^2 along X, 0.039*amp^2 along Y\n    float varX = useLEADR ? (0.561 * amp * amp * (1.0 - atten * atten)) : 0.0;\n    float varY = useLEADR ? (0.039 * amp * amp * (1.0 - atten * atten)) : 0.0;\n    vec3 cov = vec3(varX, varY, 0.0);\n\n    vec3 acc = vec3(0.0);\n    for (int li = 0; li < 2; li++) {\n      vec3 L = (li == 0) ? l1 : l2;\n      vec3 lCol = (li == 0) ? vec3(2.8, 2.35, 1.75) : vec3(0.75, 1.25, 1.95);\n      float ndl = max(dot(nG, L), 0.0);\n      float ndv = max(dot(nG, v), 0.005);\n      if (ndl > 0.002) {\n        vec3 H = normalize(L + v);\n        float hN = max(dot(H, nG), 0.005);\n        vec2 hSlope = vec2(-dot(H, T) / hN, -dot(H, B) / hN);\n        float D = evalLEADR_NDF(hSlope, meanSlope, cov, baseVar) / pow(hN, 4.0);\n        // Anisotropic Smith masking-shadowing along projected slope variance\n        float sigV = sqrt(max(baseVar + varX * dot(v, T) * dot(v, T) + varY * dot(v, B) * dot(v, B), 1e-4));\n        float sigL = sqrt(max(baseVar + varX * dot(L, T) * dot(L, T) + varY * dot(L, B) * dot(L, B), 1e-4));\n        float tanV = sqrt(max(1.0 - ndv * ndv, 0.0)) / ndv;\n        float tanL = sqrt(max(1.0 - ndl * ndl, 0.0)) / ndl;\n        float G = 1.0 / (1.0 + beckmannLambda(1.0 / max(1.414 * sigV * tanV, 1e-4)) + beckmannLambda(1.0 / max(1.414 * sigL * tanL, 1e-4)));\n        float vdh = max(dot(v, H), 0.005);\n        vec3 F = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0);\n        acc += lCol * F * (D * G / max(4.0 * ndv, 0.04));\n      }\n    }\n\n    // Filtered ambient reflection using mean normal + effective roughness\n    vec3 effN = normalize(nG - T * meanSlope.x - B * meanSlope.y);\n    vec3 rDir = reflect(-v, effN);\n    float effRough = clamp(sqrt(baseVar + 0.5 * (varX + varY)), 0.05, 0.85);\n    vec3 envAmb = mix(evalEnv(rDir), evalEnv(nG) * 0.72, effRough);\n    vec3 Fv = f0 + (1.0 - f0) * pow(1.0 - max(dot(effN, v), 0.0), 5.0);\n    col = acc + envAmb * Fv * (0.48 + 0.25 * (1.0 - envMip));\n\n    if (tPl < tSph) {\n      col = mix(col, evalEnv(rd) * 0.45, 1.0 - exp(-tPl * 0.075));\n    }\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": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "leadr-mapping",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:13.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4146,
      "std": 0.2233,
      "min": 0.1661,
      "max": 1
     },
     "image": "/specimens/leadr-mapping-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "toksvig-mipmapping",
  "normal-distribution-filtering",
  "parallax-occlusion-mapping",
  "ggx-trowbridge-reitz"
 ],
 "extends": [
  "toksvig-mipmapping"
 ],
 "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/leadr-mapping.json"
 },
 "solves": [
  "normal map shimmers or aliases at distance",
  "fine bump detail disappears or sparkles when minified",
  "specular highlights flicker on tiny surface detail",
  "filter roughness for displaced geometry properly"
 ],
 "authority": "Dupuy et al., 2013",
 "url": "https://texelatlas.vercel.app/t/leadr-mapping/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 6.54,
  "tier": "moderate",
  "p50_ms": 0.2152,
  "p95_ms": 0.2224,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "leadr-mapping-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 5.97,
   "tier": "light",
   "p50_ms": 0.095,
   "p95_ms": 0.0953,
   "speedup_x": 2.27,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 4.35,
   "tier": "light",
   "p50_ms": 0.1254,
   "p95_ms": 0.1259,
   "speedup_x": 1.72,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}