{
 "id": "smith-masking-shadowing",
 "title": "Smith masking-shadowing function",
 "aliases": [],
 "domain": "materials",
 "subdomain": "microfacet BRDF",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot",
  "blender"
 ],
 "year_introduced": 2014,
 "inputs": [
  "material-params",
  "normals"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "The statistically grounded geometry term for microfacet BRDFs. Heitz's JCGT analysis shows how to pair Smith's G with the normal distribution, why height-correlated G is the right choice, and where the separable form falls short.",
 "how_it_works": "A microfacet only contributes if both the incoming and outgoing rays reach it unobstructed. Smith's model derives masking G1(v) from the normal distribution itself via the auxiliary function Lambda, which for GGX has a closed form involving sqrt(1 + a^2 tan^2 theta). The simplest combination multiplies G1(l)*G1(v) (separable, assumes uncorrelated visibility). Heitz showed that the height-correlated form, G2 = 1 / (1 + Lambda(l) + Lambda(v)), is more accurate because rays at similar heights are visible together, and the same paper clarifies the roles of height versus direction correlation. Real-time engines fold G2 and the 1/(4 n.l n.v) denominator into one visibility term V that is cheaper and better behaved. Approximations to Lambda avoid the square roots.",
 "when_to_use": "Choose it for the G term of any GGX-based shader; use the height-correlated form unless matching a legacy look. Prefer a simplified Schlick-GGX masking (as in early Unreal) only on very constrained mobile hardware. If bright rough metals look too dark, the missing piece is not G but `kulla-conty-multiscatter`.",
 "cost": {
  "class": "cheap",
  "notes": "Two sqrt-and-divide evaluations, or an approximation of Lambda; commonly merged into the visibility term."
 },
 "failure_modes": [
  "Separable G darkens grazing angles and slightly overestimates energy loss compared with the correlated form",
  "Fast Lambda approximations (e.g. fused sqrt-free forms) introduce small errors at high roughness",
  "Smith assumes uncorrelated microfacet heights and normals, so sharply structured surfaces such as scratches and brushed metals deviate from it",
  "Lost inter-facet bounces make rough conductors darker than reality"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://jcgt.org/published/0003/02/03",
   "type": "web",
   "title": "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs",
   "authors": [
    "Eric Heitz"
   ],
   "year": null,
   "venue": "JCGT 2014",
   "url": "https://jcgt.org/published/0003/02/03",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261021143625/https://jcgt.org/published/0003/02/03/",
     "timestamp": "20261021143625"
    },
    "page_title": null,
    "host": "jcgt.org",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://jcgt.org/published/0003/02/03 → 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": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "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": null,
   "__bib": "heitzunderstanding"
  }
 ],
 "presets": [
  {
   "id": "smith-masking-shadowing-specimen",
   "title": "GGX specular without (left) vs with (right) Smith masking-shadowing",
   "runtime": "glsl-fragment",
   "params": {
    "ROUGH": 0.45
   },
   "code": "// GGX specular with and without the Smith masking-shadowing term G (roughness 0.45), rim-lit from behind.\n// Left: G = 1, specular D*F/(4 NL NV) blows up at grazing angles. Right: height-correlated Smith G.\nconst float ROUGH = 0.45;\n\nfloat D_ggx(float nh, float a) { float a2 = a * a; float d = nh * nh * (a2 - 1.0) + 1.0; return a2 / (3.14159 * d * d); }\nfloat G_smith(float nl, float nv, float a) {\n  float a2 = a * a;\n  float gv = nl * sqrt((-nv * a2 + nv) * nv + a2), gl = nv * sqrt((-nl * a2 + nl) * nl + a2);\n  return 2.0 * nl * nv / max(gv + gl, 1e-5);\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 ro = vec3(0.0, 0.0, 4.0), rd = normalize(vec3(uv, -2.4));\n  vec3 col = vec3(0.02) + 0.02 * uv.y;\n  for (int i = 0; i < 2; i++) {\n    vec3 c = vec3(i == 0 ? -0.5 : 0.5, 0.0, 0.0);\n    vec3 oc = ro - c; float b = dot(oc, rd); float h = b * b - dot(oc, oc) + 0.46 * 0.46;\n    if (h < 0.0) continue;\n    float t = -b - sqrt(h); vec3 n = normalize(ro + rd * t - c); vec3 v = -rd;\n    vec3 tot = vec3(0.02, 0.03, 0.05);\n    for (int k = 0; k < 2; k++) {\n      vec3 l = k == 0 ? normalize(vec3(-0.3, 0.6, -0.75)) : normalize(vec3(0.2, 0.2, 1.0));\n      float nl = dot(n, l); if (nl <= 0.0) continue;\n      float nv = max(dot(n, v), 1e-3); vec3 hv = normalize(l + v);\n      float a = ROUGH * ROUGH; float F = 0.04 + 0.96 * pow(1.0 - max(dot(l, hv), 0.0), 5.0);\n      float G = i == 0 ? 1.0 : G_smith(nl, nv, a);\n      float spec = D_ggx(max(dot(n, hv), 0.0), a) * F * G / (4.0 * nl * nv);\n      tot += (k == 0 ? 2.5 : 1.2) * (spec + vec3(0.06, 0.09, 0.15) / 3.14159) * nl;\n    }\n    col = tot;\n  }\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": "smith-masking-shadowing",
     "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.216,
      "std": 0.0806,
      "unique_colors": 74
     },
     "image": "/specimens/smith-masking-shadowing-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ggx-trowbridge-reitz",
  "cook-torrance-brdf",
  "kulla-conty-multiscatter",
  "vndf-sampling"
 ],
 "extends": [
  "ggx-trowbridge-reitz"
 ],
 "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/smith-masking-shadowing.json"
 },
 "solves": [
  "specular looks too bright at grazing angles",
  "which geometry term pairs with ggx",
  "microfacet highlights lose energy or look wrong when rough",
  "need a correct shadowing-masking term in a pbr shader"
 ],
 "authority": "Heitz",
 "url": "https://texelatlas.vercel.app/t/smith-masking-shadowing/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 1.62,
  "tier": "feather",
  "p50_ms": 0.0533,
  "p95_ms": 0.0587,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "smith-masking-shadowing-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1.31,
   "tier": "feather",
   "p50_ms": 0.0208,
   "p95_ms": 0.0208,
   "speedup_x": 2.56,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.05,
   "tier": "feather",
   "p50_ms": 0.0302,
   "p95_ms": 0.0303,
   "speedup_x": 1.76,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}