---
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"
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"
cost: "cheap"
authority: "Wyman & McGuire, 2017"
url: "https://texelatlas.vercel.app/t/hashed-alpha-testing/"
sources_verified_at: "2026-11-29"
---
# Hashed alpha testing / alpha-to-coverage for foliage (Wyman & McGuire, 2017)

> 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.

## Reach for it when

- 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

## 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](https://texelatlas.vercel.app/t/temporal-anti-aliasing.md) averages the stochastic noise over frames.

## When to use it

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 order-independent transparency](https://texelatlas.vercel.app/t/weighted-blended-oit.md) or sorted blending for truly translucent surfaces such as glass or smoke, plain A2C when hardware MSAA is already on, and [Blue-noise dithering](https://texelatlas.vercel.app/t/blue-noise-dithering.md) thresholds if you want a smoother noise distribution and have a TAA resolve.

## Cost

cheap — 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.
Measured GPU Weight: 2.26× baseline (light) — 0.0744 ms median / 0.0759 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 1.82× baseline (feather) — 0.0289 ms median (2.57× faster on L4).
Ampere A100 scaling: 1.5× baseline (feather) — 0.0432 ms median (1.72× faster on A100).

## 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

## Engine support

- blender: builtin — `EEVEE Material > Surface > Render Method = Dithered (stochastic alpha)` (evidence: https://docs.blender.org/manual/en/5.2/render/eevee/material_settings.html, checked 2026-12-01)
- godot: builtin — `BaseMaterial3D.transparency = TRANSPARENCY_ALPHA_HASH; alpha_antialiasing_mode = ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/BaseMaterial3D.xml, checked 2026-12-01)
- threejs: builtin — `material.alphaHash = true; material.alphaToCoverage = true` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/materials/Material.js, checked 2026-12-01)
- unreal: builtin — `Material > Blend Mode = Masked with Dither Opacity Mask (dither_opacity_mask) or Alpha to Coverage (alpha_to_coverage)` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/python-api/class/Material, checked 2026-12-01)

## Dataflow

- Inputs: texture, mesh
- Outputs: visibility-mask
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot

## Presets

### Hard cutoff (left) vs hashed alpha (right) leaf field (glsl-fragment; rendered 2026-11-29)

```json
{
  "cutoff": 0.5,
  "leaf_scale": 6
}
```

```glsl
// GLSL ES 3.0, Shadertoy-style. Left: hard alpha test at 0.5. Right: hashed alpha test (stochastic threshold per pixel).
// The soft leafy alpha field is shown as black foliage over sky, so the hashed side has dithered soft edges.
const float CUTOFF = 0.5;
const float LEAF_SCALE = 6.0;

float hash12(vec2 p) {
  vec3 p3 = fract(vec3(p.xyx) * 0.1031);
  p3 += dot(p3, p3.yzx + 33.33);
  return fract((p3.x + p3.y) * p3.z);
}
float alphaField(vec2 uv) {
  vec2 g = uv * LEAF_SCALE;
  vec2 id = floor(g);
  vec2 f = fract(g) - 0.5;
  float r = hash12(id);
  vec2 off = (vec2(hash12(id + 7.1), hash12(id + 3.7)) - 0.5) * 0.4;
  float ang = r * 6.2831 + iTime * 0.1;
  mat2 R = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));
  vec2 q = R * (f - off) * vec2(1.0, 2.2);
  float leaf = 1.0 - smoothstep(0.0, 0.45, length(q));   // soft alpha ramp 0..1 inside each leaf
  return leaf;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = fragCoord / iResolution.xy;
  float a = alphaField(uv);
  vec3 sky = mix(vec3(0.75, 0.88, 1.0), vec3(0.30, 0.55, 0.90), uv.y);
  vec3 leafCol = mix(vec3(0.10, 0.35, 0.08), vec3(0.35, 0.60, 0.12), uv.y);
  float threshold = (uv.x < 0.5) ? CUTOFF : hash12(floor(fragCoord));
  float visible = step(threshold, a - 1e-4);
  vec3 col = mix(sky, leafCol, visible);
  if (abs(uv.x - 0.5) < 0.003) col = vec3(1.0);
  fragColor = vec4(col, 1.0);
}

```

Attribution: written for this index; uses the Dave Hoskins-style hash without sine

## Combines with

- [Temporal Anti-Aliasing](https://texelatlas.vercel.app/t/temporal-anti-aliasing.md): TAA integrates the per-pixel stochastic coverage over frames, turning noise into smooth soft edges.

## Sources

1. [primary] Chris Wyman, Morgan McGuire (2017) Hashed alpha testing. Proceedings of the 21st ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games. https://doi.org/10.1145/3023368.3023370 (verified via crossref on 2026-11-29)
2. [primary] Chris Wyman, Morgan McGuire (2019) Improved Alpha Testing Using Hashed Sampling. IEEE Transactions on Visualization and Computer Graphics. https://doi.org/10.1109/tvcg.2017.2739149 (verified via crossref on 2026-11-29)
3. [implementation] mrdoob (2010) mrdoob/three.js. https://github.com/mrdoob/three.js License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Hashed alpha testing / alpha-to-coverage for foliage." https://texelatlas.vercel.app/t/hashed-alpha-testing/ (accessed 2026-12-01).
