{
 "id": "hashed-alpha-testing",
 "title": "Hashed alpha testing / alpha-to-coverage for foliage",
 "aliases": [
  "hashed alpha",
  "stochastic alpha testing",
  "alpha to coverage",
  "A2C"
 ],
 "domain": "visibility",
 "subdomain": "cutout transparency",
 "stage": "visibility",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2017,
 "inputs": [
  "texture",
  "mesh"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Replaces the fixed alpha-test threshold with a per-pixel hashed random one, so cutout edges in foliage and fences keep expected coverage as they shrink in the distance.",
 "how_it_works": "A fixed threshold discards pixels whose alpha is below, say, 0.5. As mipmapping averages alpha and leaves shrink on screen, the surviving area drifts, so distant foliage thins out, and the hard step produces aliasing. Hashed alpha testing compares alpha against a pseudo-random threshold in (0,1] derived from a hash of the object-space position (rather than screen position) so the pattern sticks to the surface and does not swim when the object moves. To keep the density of the noise constant on screen, the hash input is quantised at a scale taken from the screen-space derivative of the position, with the threshold interpolated between two adjacent scales. The expected coverage then equals alpha, giving a stochastic approximation of true blending that needs no sorting. Alpha-to-coverage achieves similar results with MSAA by mapping alpha to a coverage mask, optionally with dithering; `temporal-anti-aliasing` averages the stochastic noise over frames.",
 "when_to_use": "Choose it for leaves, hair cards, grass, chain-link fences and anywhere alpha-tested cutouts must stay stable across mip levels and still write depth, so shadow maps and deferred buffers work. Prefer `weighted-blended-oit` or sorted blending for truly translucent surfaces such as glass or smoke, plain A2C when hardware MSAA is already on, and `blue-noise-dithering` thresholds if you want a smoother noise distribution and have a TAA resolve.",
 "cost": {
  "class": "cheap",
  "notes": "A small hash and a compare in the pixel shader, plus the depth-write benefits of discarding; the main cost is the noise which needs a resolve."
 },
 "failure_modes": [
  "Visible static noise on foliage when there is no TAA or MSAA to average it, especially in shadows",
  "Temporal shimmer when the hash input or scale changes with camera distance, if not quantised",
  "Shadow maps filled with noisy cutouts need extra filtering to avoid speckled shadows",
  "Thin geometry at distance can break up into isolated pixels instead of a coherent silhouette",
  "Per-pixel hash behaves poorly with skinned or UV-animated materials unless a stable key is chosen"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/3023368.3023370",
   "type": "paper",
   "title": "Hashed alpha testing",
   "authors": [
    "Chris Wyman",
    "Morgan McGuire"
   ],
   "year": 2017,
   "venue": "Proceedings of the 21st ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games",
   "url": "https://doi.org/10.1145/3023368.3023370",
   "ids": {
    "doi": "10.1145/3023368.3023370"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3023368.3023370",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3023368.3023370",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3023368.3023370",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3023368.3023370",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3023368.3023370",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "wyman2017hashed"
  },
  {
   "role": "primary",
   "key": "doi:10.1109/tvcg.2017.2739149",
   "type": "paper",
   "title": "Improved Alpha Testing Using Hashed Sampling",
   "authors": [
    "Chris Wyman",
    "Morgan McGuire"
   ],
   "year": 2019,
   "venue": "IEEE Transactions on Visualization and Computer Graphics",
   "url": "https://doi.org/10.1109/tvcg.2017.2739149",
   "ids": {
    "doi": "10.1109/tvcg.2017.2739149"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2017.2739149",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2017.2739149",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2017.2739149",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2017.2739149",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/tvcg.2017.2739149",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "wyman2019improved"
  },
  {
   "role": "implementation",
   "key": "gh:mrdoob/three.js",
   "type": "code",
   "title": "mrdoob/three.js",
   "description": "JavaScript 3D Library.",
   "authors": [
    "mrdoob"
   ],
   "year": 2010,
   "venue": "GitHub",
   "url": "https://github.com/mrdoob/three.js",
   "ids": {
    "repo": "mrdoob/three.js"
   },
   "license": "MIT",
   "extra": {
    "stars": 119718,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-29T11:39:51Z",
    "language": "JavaScript",
    "homepage": "https://threejs.org/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mrdoob2010mrdoob"
  }
 ],
 "presets": [
  {
   "id": "hashed-alpha-vs-hard-cutoff",
   "title": "Hard cutoff (left) vs hashed alpha (right) leaf field",
   "runtime": "glsl-fragment",
   "params": {
    "cutoff": 0.5,
    "leaf_scale": 6
   },
   "code": "// GLSL ES 3.0, Shadertoy-style. Left: hard alpha test at 0.5. Right: hashed alpha test (stochastic threshold per pixel).\n// The soft leafy alpha field is shown as black foliage over sky, so the hashed side has dithered soft edges.\nconst float CUTOFF = 0.5;\nconst float LEAF_SCALE = 6.0;\n\nfloat hash12(vec2 p) {\n  vec3 p3 = fract(vec3(p.xyx) * 0.1031);\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.x + p3.y) * p3.z);\n}\nfloat alphaField(vec2 uv) {\n  vec2 g = uv * LEAF_SCALE;\n  vec2 id = floor(g);\n  vec2 f = fract(g) - 0.5;\n  float r = hash12(id);\n  vec2 off = (vec2(hash12(id + 7.1), hash12(id + 3.7)) - 0.5) * 0.4;\n  float ang = r * 6.2831 + iTime * 0.1;\n  mat2 R = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));\n  vec2 q = R * (f - off) * vec2(1.0, 2.2);\n  float leaf = 1.0 - smoothstep(0.0, 0.45, length(q));   // soft alpha ramp 0..1 inside each leaf\n  return leaf;\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = fragCoord / iResolution.xy;\n  float a = alphaField(uv);\n  vec3 sky = mix(vec3(0.75, 0.88, 1.0), vec3(0.30, 0.55, 0.90), uv.y);\n  vec3 leafCol = mix(vec3(0.10, 0.35, 0.08), vec3(0.35, 0.60, 0.12), uv.y);\n  float threshold = (uv.x < 0.5) ? CUTOFF : hash12(floor(fragCoord));\n  float visible = step(threshold, a - 1e-4);\n  vec3 col = mix(sky, leafCol, visible);\n  if (abs(uv.x - 0.5) < 0.003) col = vec3(1.0);\n  fragColor = vec4(col, 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index; uses the Dave Hoskins-style hash without sine",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "hashed-alpha-testing",
     "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.6706,
      "std": 0.1279,
      "unique_colors": 43
     },
     "image": "/specimens/hashed-alpha-vs-hard-cutoff.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "weighted-blended-oit",
  "temporal-anti-aliasing",
  "blue-noise-dithering",
  "ordered-dithering-bayer",
  "smaa",
  "fxaa"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "temporal-anti-aliasing",
   "why": "TAA integrates the per-pixel stochastic coverage over frames, turning noise into smooth soft edges."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/visibility/hashed-alpha-testing.json"
 },
 "solves": [
  "tree leaves thin out and vanish as they get farther away",
  "alpha tested fences shimmer or alias at distance",
  "foliage cutouts look crunchy and swim when moving",
  "need cutout transparency that still writes depth for shadows",
  "alpha to coverage still shows banding on grass cards"
 ],
 "authority": "Wyman & McGuire, 2017",
 "url": "https://texelatlas.vercel.app/t/hashed-alpha-testing/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 2.26,
  "tier": "light",
  "p50_ms": 0.0744,
  "p95_ms": 0.0759,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "hashed-alpha-vs-hard-cutoff",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1.82,
   "tier": "feather",
   "p50_ms": 0.0289,
   "p95_ms": 0.0292,
   "speedup_x": 2.57,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.5,
   "tier": "feather",
   "p50_ms": 0.0432,
   "p95_ms": 0.0434,
   "speedup_x": 1.72,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}