Hashed alpha testing / alpha-to-coverage for foliage
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.
Also known as hashed alpha, stochastic alpha testing, alpha to coverage, A2C
In the family Visibility, shadows & ambient occlusion, cutout transparency
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | material.alphaHash = true; material.alphaToCoverage = true docs |
| Babylon.js 9.38.0 | None found | PBRBaseMaterial uses fixed-threshold alphaCutOff alpha testing rather than stochastic hashed alpha testing. |
| Godot 4.7 | Built in | BaseMaterial3D.transparency = TRANSPARENCY_ALPHA_HASH; alpha_antialiasing_mode = ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE docs |
| Unity | None found | Alpha-to-coverage is built in (a related but different technique); there is no hashed alpha mode. |
| Unreal 5.7 | Built in | Material > Blend Mode = Masked with Dither Opacity Mask (dither_opacity_mask) or Alpha to Coverage (alpha_to_coverage) docs |
| Blender 5.2 | Built in | EEVEE Material > Surface > Render Method = Dithered (stochastic alpha) docs |
| WebGPU W3C | None found | Alpha-to-coverage is built in (a related but different technique); the hashed threshold is yours to write. |
| Metal | None found | Alpha-to-coverage is built in (a related but different technique); the hashed threshold is yours to write. |
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 choose it
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
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 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.
Field marks
- 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
Presets
Hard cutoff (left) vs hashed alpha (right) leaf field
{
"cutoff": 0.5,
"leaf_scale": 6
}Show GLSL (34 lines)
// 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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| hashed-alpha-vs-hard-cutoff | Tesla T4 1920x1080 | 2.26× baseline (light) · 0.074 ms / 0.076 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| hashed-alpha-vs-hard-cutoff | NVIDIA L4 1920x1080 | 1.82× baseline (feather) · 0.029 ms / 0.029 ms · 2.6× faster on L4 | opengl-timer-query · Cross-architecture validation |
| hashed-alpha-vs-hard-cutoff | NVIDIA A100-SXM4-40GB 1920x1080 | 1.50× baseline (feather) · 0.043 ms / 0.043 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Deferred shading (G-buffer), Unidirectional Path Tracing.
Crosses
- Temporal Anti-Aliasing: TAA integrates the per-pixel stochastic coverage over frames, turning noise into smooth soft edges.
Sources
- primaryChris Wyman, Morgan McGuire (2017). Hashed alpha testing. Proceedings of the 21st ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games.Verified via crossref · 2026-11-29doi:10.1145/3023368.3023370
- primaryChris Wyman, Morgan McGuire (2019). Improved Alpha Testing Using Hashed Sampling. IEEE Transactions on Visualization and Computer Graphics.Verified via crossref · 2026-11-29doi:10.1109/tvcg.2017.2739149
- implementationmrdoob (2010). mrdoob/three.js. JavaScript 3D Library.GitHub API · license MIT · 2026-11-29