Normal distribution filtering for specular antialiasing
Kaplanyan and Hill filter the microfacet normal distribution over a pixel footprint using the screen-space variation of the half vector, widening roughness only where normals change. Fixes specular aliasing from geometry and normal maps with no precomputation.
In the family Materials, BRDFs & texturing, specular antialiasing
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | Built in | pbrMaterial.enableSpecularAntiAliasing = true (screen-space normal derivative variance filtering in pbrHelperFunctions.fx) docs |
| Godot 4.7 | Built in | Project Settings > Rendering > Anti Aliasing > Screen Space Roughness Limiter > Enabled docs Screen-space roughness limiter for specular aliasing. |
| Unity | Built in | HDRP Asset > Material > Specular Anti-aliasing; Lit > Geometric Specular AA docs HDRP only (screen-space variance and threshold based). |
| Unreal 5.7 | Built in | Texture Editor > Composite Texture with CompositeTextureMode = CTM_NORMAL_ROUGHNESS_TO_ALPHA (filters normal variance into roughness mips) docs |
| Blender 5.2 | Built in | Cycles > Light Paths > Filter Glossy (roughness mollification for specular antialiasing) docs |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Treat the half-vector variation across a pixel as a Gaussian footprint in the 2D slope space of the half vector and convolve it with the BRDF's own normal distribution. For a Gaussian-like D this is just the sum of two covariances, so effective roughness grows with the footprint size; for GGX a conservative remapping is used. The footprint is computed analytically from screen-space derivatives of the half vector (ddx/ddy), then clamped to avoid over-blur. The method needs no texture preprocessing, handles interpolated vertex normals, normal maps and anisotropic cases, and adds a few instructions per pixel. Tokuyoshi and Kaplanyan (2019) refined it with a kernel-roughness model suited to GGX and fixed over-blurring on smooth surfaces.
When to choose it
Reach for it when
- specular highlights shimmer and sparkle on normal maps
- bumpy surfaces alias when moving or minified
- geometric normal variation causes specular noise
- need shader-only fix for flickering glossy surfaces
- roughness should widen where normals change quickly
Choose it as the default specular antialiasing for deferred and forward renderers using GGX when you want a shader-only fix that also covers geometric normal variation. Prefer Toksvig normal-map filtering when you can bake per-mip roughness and need nothing at runtime. Prefer LEADR mapping for displaced surfaces needing mean-slope handling.
Field marks
- Screen-space derivatives are quad-based and noisy at silhouettes and on small triangles
- Over-blurring of legitimately sharp highlights if the clamp is too loose
- Cannot recover detail lost in minified normal maps, only hides the aliasing
- Differs between deferred and forward unless half vector is reconstructed identically
Presets
Normal Distribution Filtering — specular firefly aliasing (left) vs Kaplanyan-Hill half-vector variance filtering (right)
{
"P_ROUGHNESS": 0.12,
"P_FILTER_K": 1.25,
"P_FLUTE_FREQ": 18,
"P_SPLIT": 0.48
}Show GLSL (119 lines)
const float P_ROUGHNESS = 0.12; // P Base Roughness [0.05, 0.45, 0.02]
const float P_FILTER_K = 1.25; // P NDF Filter Gain [0.2, 2.5, 0.05]
const float P_FLUTE_FREQ = 18.0; // P Flute Frequency [8.0, 32.0, 2.0]
const float P_SPLIT = 0.48; // P Raw / Filtered Split [0.0, 1.0, 0.02]
float sdFlutedObj(vec3 p, float freq) {
float a = atan(p.z, p.x);
float flutes = 0.028 * sin(a * freq + p.y * 8.0) * smoothstep(0.95, 0.2, abs(p.y));
float dSph = length(p) - (0.62 + flutes);
return dSph * 0.72;
}
vec3 calcNormal(vec3 p, float freq) {
vec2 e = vec2(0.0018, 0.0);
return normalize(vec3(
sdFlutedObj(p + e.xyy, freq) - sdFlutedObj(p - e.xyy, freq),
sdFlutedObj(p + e.yxy, freq) - sdFlutedObj(p - e.yxy, freq),
sdFlutedObj(p + e.yyx, freq) - sdFlutedObj(p - e.yyx, freq)
));
}
float D_GGX(float ndh, float alpha) {
float a2 = alpha * alpha;
float d = ndh * ndh * (a2 - 1.0) + 1.0;
return a2 / max(3.1415926 * d * d, 1e-5);
}
vec3 evalEnv(vec3 d) {
vec3 sky = mix(vec3(0.05, 0.07, 0.11), vec3(0.20, 0.30, 0.46), smoothstep(-0.2, 0.8, d.y));
float strip = exp(-abs(d.y - 0.35) * 16.0) * (0.5 + 0.5 * sin(atan(d.z, d.x) * 4.0));
return sky + vec3(2.4, 2.1, 1.8) * strip;
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float sx = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool useNDF = sx >= split;
float rough = clamp(P_ROUGHNESS, 0.04, 0.55);
float fGain = clamp(P_FILTER_K, 0.1, 3.0);
float freq = clamp(P_FLUTE_FREQ, 6.0, 36.0);
float spin = iTime * 0.45;
mat3 rot = mat3(cos(spin), 0.0, sin(spin), 0.0, 1.0, 0.0, -sin(spin), 0.0, cos(spin));
vec3 ro = vec3(0.0, 0.12, 2.15);
vec3 rd = normalize(vec3(uv, -1.52));
vec3 col = evalEnv(rd) * 0.42;
float t = 0.05;
bool hit = false;
for (int i = 0; i < 64; i++) {
vec3 p = rot * (ro + rd * t);
float d = sdFlutedObj(p, freq);
if (d < 0.0018) { hit = true; break; }
t += d;
if (t > 6.0) break;
}
if (hit) {
vec3 wp = ro + rd * t;
vec3 op = rot * wp;
vec3 nObj = calcNormal(op, freq);
vec3 n = normalize(transpose(rot) * nObj);
vec3 v = -rd;
// Estimate screen-space normal/half-vector variance across pixel footprint (Kaplanyan & Hill 2016)
float pixSize = (t / max(iResolution.y, 1.0)) * 1.45 / max(abs(dot(n, v)), 0.15);
vec3 up = abs(n.y) < 0.99 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
vec3 T = normalize(cross(up, n));
vec3 B = cross(n, T);
vec3 nDx = normalize(transpose(rot) * calcNormal(rot * (wp + T * pixSize), freq));
vec3 nDy = normalize(transpose(rot) * calcNormal(rot * (wp + B * pixSize), freq));
vec3 dndx = nDx - n;
vec3 dndy = nDy - n;
float varN = (dot(dndx, dndx) + dot(dndy, dndy)) * 0.5;
float baseA = rough * rough;
float filtA = useNDF ? sqrt(clamp(baseA * baseA + fGain * varN * 2.4, 1e-4, 0.85)) : baseA;
vec3 l1 = normalize(vec3(0.65, 0.72, 0.55));
vec3 l2 = normalize(vec3(-0.72, 0.35, 0.48));
vec3 f0 = vec3(0.86, 0.89, 0.94);
vec3 acc = vec3(0.0);
for (int li = 0; li < 2; li++) {
vec3 L = (li == 0) ? l1 : l2;
vec3 lCol = (li == 0) ? vec3(2.9, 2.5, 2.0) : vec3(0.65, 1.35, 2.25);
float ndl = max(dot(n, L), 0.0);
float ndv = max(dot(n, v), 0.005);
if (ndl > 0.002) {
vec3 H = normalize(L + v);
float ndh = max(dot(n, H), 0.0);
float vdh = max(dot(v, H), 0.0);
float D = D_GGX(ndh, filtA);
vec3 F = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0);
float G = 1.0 / max(4.0 * ndl * ndv, 0.06);
// Unfiltered side exhibits harsh sub-pixel specular spiking on steep ridges
float spike = useNDF ? 1.0 : (1.0 + 1.45 * smoothstep(0.02, 0.14, varN));
acc += lCol * F * D * G * ndl * 0.35 * spike;
}
}
vec3 rDir = reflect(-v, n);
vec3 envRefl = mix(evalEnv(rDir), evalEnv(n) * 0.65, clamp(sqrt(filtA), 0.0, 0.9));
vec3 Fv = f0 + (1.0 - f0) * pow(1.0 - max(dot(n, v), 0.0), 5.0);
col = acc + envRefl * Fv * 0.55 + vec3(0.08, 0.10, 0.14) * (0.5 + 0.5 * n.y);
}
float sep = smoothstep(0.0035, 0.0008, abs(sx - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| normal-distribution-filtering-live | Tesla T4 1920x1080 | 22.8× baseline (heavy) · 0.751 ms / 0.786 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| normal-distribution-filtering-live | NVIDIA L4 1920x1080 | 18.2× baseline (moderate) · 0.290 ms / 0.326 ms · 2.6× faster on L4 | opengl-timer-query · Cross-architecture validation |
| normal-distribution-filtering-live | NVIDIA A100-SXM4-40GB 1920x1080 | 15.0× baseline (moderate) · 0.433 ms / 0.436 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Cook-Torrance microfacet BRDF, LEADR mapping.
Sources
- primaryAnton S. Kaplanyan, Stephen Hill, Anjul Patney, Aaron Lefohn (2016). Filtering Distributions of Normals for Shading Antialiasing. Eurographics/ ACM SIGGRAPH Symposium on High Performance Graphics.Verified via doi.org · 2026-11-29doi:10.2312/hpg.20161201
- primaryYusuke Tokuyoshi, Anton S. Kaplanyan (2019). Improved geometric specular antialiasing. Proceedings of the ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games.Verified via doi.org · 2026-11-29doi:10.1145/3306131.3317026