{
 "id": "real-time-glints",
 "title": "Real-time glints (distributed binomial laws)",
 "aliases": [],
 "domain": "materials",
 "subdomain": "microfacet BRDF",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgpu",
  "desktop-gpu",
  "unreal",
  "unity"
 ],
 "year_introduced": 2023,
 "inputs": [
  "material-params",
  "normals",
  "uv-atlas"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "Renders sparkly surfaces such as glitter, metallic flakes and snow in real time by statistically evaluating how many discrete microfacets in a pixel footprint reflect toward the viewer. Deliot and Belcour use binomial laws over an anisotropic grid.",
 "how_it_works": "Smooth GGX hides the fact that bright sparkle comes from individual facets. Instead of storing a million microfacet normals, the method divides texture space into cells over an anisotropic grid in (position, slope) space aligned with the pixel footprint. In each cell the number of facets that point inside the half-vector footprint follows a binomial distribution whose parameters come from the surface's normal distribution. A hash gives a stable pseudo-random count per cell, so sparkles stay fixed to the surface and animate with the view. Tests across overlapping cells are combined with a closed-form cost independent of footprint size, avoiding per-facet loops. The glint lobe is added to or replaces the smooth specular lobe.",
 "when_to_use": "Choose it for car paint with metallic flakes, glitter, sand, snow, sequins and pearlescent surfaces where a smooth GGX looks lifeless. Prefer plain `ggx-trowbridge-reitz` with a normal map for gentle roughness. Prefer `anisotropic-ggx` for brushed surfaces without discrete sparkle.",
 "cost": {
  "class": "medium",
  "notes": "Several hashed grid lookups plus binomial evaluations per pixel; heavier than GGX but real-time."
 },
 "failure_modes": [
  "Temporal flicker when facets enter and exit the footprint under motion unless accumulated carefully",
  "Hash correlations show as visible grid patterns at extreme minification",
  "Facet density parameter has no direct mapping from measured flake data",
  "Increased cost on mobile GPUs; fewer samples cause noisier sparkles"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1111/cgf.14866",
   "type": "paper",
   "title": "Real‐Time Rendering of Glinty Appearances using Distributed Binomial Laws on Anisotropic Grids",
   "authors": [
    "T. Deliot",
    "L. Belcour"
   ],
   "year": 2023,
   "venue": "Computer Graphics Forum",
   "url": "https://doi.org/10.1111/cgf.14866",
   "ids": {
    "doi": "10.1111/cgf.14866"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.14866",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.14866",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.14866",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.14866",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.14866",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "deliot2023rendering"
  }
 ],
 "presets": [
  {
   "id": "real-time-glints-live",
   "title": "Stochastic microfacet glints — discrete metallic flake sparkles over smooth clearcoat",
   "runtime": "glsl-fragment",
   "params": {
    "FLAKE_DENSITY": 52,
    "ROUGHNESS": 0.24,
    "GLINT_INTENSITY": 3.2,
    "MICRO_ROUGH": 0.045
   },
   "basis": "original",
   "license_note": "MIT — written for this index",
   "code": "const float FLAKE_DENSITY = 52.0; // P\nconst float ROUGHNESS = 0.24; // P\nconst float GLINT_INTENSITY = 3.2; // P\nconst float MICRO_ROUGH = 0.045; // P\n\nvec3 hash32(vec2 p) {\n  vec3 q = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));\n  q += dot(q, q.yxz + 33.33);\n  return fract((q.xxy + q.yzz) * q.zyx);\n}\n\nfloat D_GGX(float nh, float a) {\n  float a2 = a * a;\n  float d = nh * nh * (a2 - 1.0) + 1.0;\n  return a2 / (3.14159265 * d * d + 1e-5);\n}\n\n// Multi-cell hashed discrete microfacet glint evaluator in tangent slope space\nvec3 evalGlints(vec2 uv, vec3 hTan, float density, float macroRough, float microRough) {\n  float dScale = max(density, 4.0);\n  vec2 gUv = uv * dScale;\n  vec2 cell = floor(gUv);\n  vec2 frac = fract(gUv);\n  vec2 targetSlope = hTan.xy / max(hTan.z, 0.15);\n  float mSig = max(microRough, 0.012);\n  float macSig = max(macroRough, 0.08);\n\n  vec3 glint = vec3(0.0);\n  for (int j = -1; j <= 1; j++) {\n    for (int i = -1; i <= 1; i++) {\n      vec2 cid = cell + vec2(float(i), float(j));\n      vec3 rnd = hash32(cid);\n      vec3 rnd2 = hash32(cid + vec2(37.2, 91.7));\n      vec2 center = vec2(float(i), float(j)) + 0.18 + 0.64 * rnd.xy;\n      float dist2 = dot(frac - center, frac - center);\n      float spatial = exp(-dist2 * 14.0);\n\n      // Discrete flake normal drawn from macro Gaussian slope distribution\n      float rAng = rnd.z * 6.2831853;\n      float rMag = sqrt(-2.0 * log(max(rnd2.x, 1e-4))) * macSig * 0.52;\n      vec2 flakeSlope = vec2(cos(rAng), sin(rAng)) * rMag;\n      vec2 ds = targetSlope - flakeSlope;\n      float angular = exp(-dot(ds, ds) / (2.0 * mSig * mSig));\n\n      // Subtle prismatic car-paint / metallic flake iridescence\n      vec3 tint = mix(vec3(0.92, 0.96, 1.0), 0.55 + 0.45 * cos(6.28318 * (rnd2.y + vec3(0.0, 0.18, 0.42))), 0.55);\n      glint += tint * spatial * angular * (0.7 + 0.6 * rnd2.z);\n    }\n  }\n  return glint;\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  vec3 ro = vec3(0.0, 0.12, 2.55);\n  vec3 rd = normalize(vec3(uv, -1.55));\n\n  vec3 bg = mix(vec3(0.02, 0.025, 0.04), vec3(0.07, 0.09, 0.14), clamp(uv.y + 0.5, 0.0, 1.0));\n  // Ray-sphere studio specimen\n  float rad = 0.84;\n  float b = dot(ro, rd), c = dot(ro, ro) - rad * rad, h = b * b - c;\n  if (h < 0.0) {\n    fragColor = vec4(pow(clamp(aces(bg), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n    return;\n  }\n\n  float t = -b - sqrt(h);\n  vec3 p = ro + rd * t;\n  vec3 n = normalize(p);\n  vec3 v = -rd;\n\n  // Rotate sphere surface coordinates slowly (or via mouse)\n  float rot = iTime * 0.28;\n  if (iMouse.z > 0.5 || length(iMouse.xy) > 1.0) {\n    rot = (iMouse.x / iResolution.x - 0.5) * 3.14159;\n  }\n  float cr = cos(rot), sr = sin(rot);\n  vec3 pr = vec3(cr * n.x - sr * n.z, n.y, sr * n.x + cr * n.z);\n  // Cubemap-like triplanar UV avoids pole pinching\n  vec2 surfUv = vec2(atan(pr.z, pr.x) * 0.31831, asin(clamp(pr.y, -0.999, 0.999)) * 0.63662);\n\n  vec3 up = abs(n.y) < 0.95 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);\n  vec3 T = normalize(cross(up, n));\n  vec3 B = cross(n, T);\n  mat3 worldToTan = transpose(mat3(T, B, n));\n\n  vec3 l1 = normalize(vec3(0.65 * cos(iTime * 0.4) + 0.2, 0.68, 0.65));\n  vec3 l2 = normalize(vec3(-0.75, 0.42, 0.55));\n  vec3 baseCol = vec3(0.08, 0.22, 0.54);\n  float rough = clamp(ROUGHNESS, 0.06, 0.95);\n  float ndv = max(dot(n, v), 0.001);\n  float fres = 0.04 + 0.96 * pow(1.0 - ndv, 5.0);\n\n  vec3 col = baseCol * (0.08 + 0.12 * (n.y * 0.5 + 0.5));\n  // Key light + fill light: smooth GGX + clearcoat + stochastic microfacet glints\n  for (int k = 0; k < 2; k++) {\n    vec3 L = (k == 0) ? l1 : l2;\n    vec3 lCol = (k == 0) ? vec3(1.85, 1.72, 1.55) : vec3(0.65, 0.85, 1.25);\n    float nl = max(dot(n, L), 0.0);\n    vec3 H = normalize(L + v);\n    float nh = max(dot(n, H), 0.0);\n    float specSmooth = D_GGX(nh, rough * rough) * 0.22;\n    float coat = D_GGX(nh, 0.045) * fres * 0.45;\n    vec3 hTan = worldToTan * H;\n    vec3 glints = evalGlints(surfUv, hTan, FLAKE_DENSITY, rough, MICRO_ROUGH) * max(GLINT_INTENSITY, 0.0);\n    col += lCol * nl * (baseCol * 0.65 + vec3(0.55, 0.72, 1.0) * specSmooth + coat + glints);\n  }\n  // Subtle studio rim environment reflection\n  vec3 R = reflect(-v, n);\n  vec3 env = mix(vec3(0.05, 0.08, 0.14), vec3(0.55, 0.68, 0.92), smoothstep(-0.2, 0.8, R.y));\n  col += env * fres * 0.65;\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": "real-time-glints",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:15:34.232Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5449,
      "std": 0.1624,
      "unique_colors": 214
     },
     "image": "/specimens/real-time-glints-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ggx-trowbridge-reitz",
  "anisotropic-ggx",
  "clearcoat-layer"
 ],
 "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/real-time-glints.json"
 },
 "solves": [
  "car paint flakes should sparkle",
  "glitter, snow and sand look dull and smooth",
  "metallic flakes need to glint while moving",
  "sequins and pearlescent surfaces lack sparkle",
  "discrete micro-reflections inside a pixel"
 ],
 "authority": "Deliot & Belcour, 2023",
 "url": "https://texelatlas.vercel.app/t/real-time-glints/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 21.45,
  "tier": "heavy",
  "p50_ms": 0.7057,
  "p95_ms": 0.7252,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "real-time-glints-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 18.64,
   "tier": "moderate",
   "p50_ms": 0.2964,
   "p95_ms": 0.2973,
   "speedup_x": 2.38,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 13.83,
   "tier": "moderate",
   "p50_ms": 0.3983,
   "p95_ms": 0.4009,
   "speedup_x": 1.77,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}