---
id: "normal-distribution-filtering"
title: "Normal distribution filtering for specular antialiasing"
domain: "materials"
stage: "material"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender]
year_introduced: 2016
inputs: [normals, gbuffer]
outputs: [material-params]
style: "photoreal"
dynamic: "both"
cost: "cheap"
authority: "Kaplanyan et al., 2016"
url: "https://texelatlas.vercel.app/t/normal-distribution-filtering/"
sources_verified_at: "2026-11-29"
---
# Normal distribution filtering for specular antialiasing (Kaplanyan et al., 2016)

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

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

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

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](https://texelatlas.vercel.app/t/toksvig-mipmapping.md) when you can bake per-mip roughness and need nothing at runtime. Prefer [LEADR mapping](https://texelatlas.vercel.app/t/leadr-mapping.md) for displaced surfaces needing mean-slope handling.

## Cost

cheap — Derivative-based footprint estimate and a couple of arithmetic operations per pixel.
Measured GPU Weight: 22.83× baseline (heavy) — 0.751 ms median / 0.7857 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 18.22× baseline (moderate) — 0.2897 ms median (2.59× faster on L4).
Ampere A100 scaling: 15.04× baseline (moderate) — 0.4332 ms median (1.73× faster on A100).

## Failure modes

- 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

## Engine support

- babylonjs: builtin — `pbrMaterial.enableSpecularAntiAliasing = true (screen-space normal derivative variance filtering in pbrHelperFunctions.fx)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.pure.ts, checked 2026-12-01)
- blender: builtin — `Cycles > Light Paths > Filter Glossy (roughness mollification for specular antialiasing)` (evidence: https://docs.blender.org/manual/en/5.2/render/cycles/render_settings/light_paths.html, checked 2026-12-01)
- godot: builtin — `Project Settings > Rendering > Anti Aliasing > Screen Space Roughness Limiter > Enabled` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/ProjectSettings.xml, checked 2026-12-01) — Screen-space roughness limiter for specular aliasing.
- unity: builtin — `HDRP Asset > Material > Specular Anti-aliasing; Lit > Geometric Specular AA` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Documentation~/Geometric-Specular-Anti-Aliasing.md, checked 2026-12-01) — HDRP only (screen-space variance and threshold based).
- unreal: builtin — `Texture Editor > Composite Texture with CompositeTextureMode = CTM_NORMAL_ROUGHNESS_TO_ALPHA (filters normal variance into roughness mips)` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/python-api/class/CompositeTextureMode, checked 2026-12-01)

## Dataflow

- Inputs: normals, gbuffer
- Outputs: material-params
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender

## Presets

### Normal Distribution Filtering — specular firefly aliasing (left) vs Kaplanyan-Hill half-vector variance filtering (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_ROUGHNESS": 0.12,
  "P_FILTER_K": 1.25,
  "P_FLUTE_FREQ": 18,
  "P_SPLIT": 0.48
}
```

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

## Lineage

- extends [Toksvig normal-map filtering](https://texelatlas.vercel.app/t/toksvig-mipmapping.md)

## Sources

1. [primary] Anton S. Kaplanyan, Stephen Hill, Anjul Patney, Aaron Lefohn (2016) Filtering Distributions of Normals for Shading Antialiasing. Eurographics/ ACM SIGGRAPH Symposium on High Performance Graphics. https://doi.org/10.2312/hpg.20161201 (verified via doi.org on 2026-11-29)
2. [primary] Yusuke Tokuyoshi, Anton S. Kaplanyan (2019) Improved geometric specular antialiasing. Proceedings of the ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games. https://doi.org/10.1145/3306131.3317026 (verified via doi.org on 2026-11-29)

## Cite this entry

Texel. "Normal distribution filtering for specular antialiasing." https://texelatlas.vercel.app/t/normal-distribution-filtering/ (accessed 2026-12-01).
