Toksvig normal-map filtering
Mipmapping a normal map shortens the averaged normal; Toksvig turns that shortening into extra roughness so minified bumpy surfaces blur their highlight instead of shimmering.
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 | None found | Specular antialiasing uses screen-space normal derivatives (enableSpecularAntiAliasing), not Toksvig normal-map mip variance. |
| Godot 4.7 | None found | Specular antialiasing uses screen-space normal derivatives (screen_space_roughness_limiter), not Toksvig normal-map mip variance. |
| Unity | None found | |
| Unreal 5.7 | Built in | Texture Editor > Composite Texture > CompositeTextureMode = CTM_NORMAL_ROUGHNESS_TO_ALPHA (converts normal-map mip variance into roughness) docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Averaging unit normals over a texel footprint produces a vector of length less than 1, and the shorter it is, the more the underlying normals disagree. Toksvig observes that for a Gaussian-like spread of normals the length encodes variance, and that the Blinn-Phong highlight over that distribution equals a broader lobe. So he adjusts the specular exponent by a factor ft = |Na| / (|Na| + s (1 - |Na|)) where s is the exponent. Modern variants apply the same idea to GGX by adding variance to roughness squared. The correction is either baked into per-mip roughness (or gloss) maps at texture-authoring time, or computed from the fetched normal's length when normal maps are stored unnormalised.
When to choose it
Reach for it when
- normal-mapped highlights shimmer in the distance
- mip levels lose roughness from averaged normals
- specular sparkle on minified bump maps
- cheap baked fix for specular aliasing
- bumpy surfaces should blur out far away
Choose it as a cheap baseline for stopping specular shimmering on normal-mapped surfaces under minification. Prefer Normal distribution filtering for specular antialiasing or LEADR mapping when you also need correct handling of the visible-slope distribution (LEADR) or per-pixel variance filtering with screen-space derivatives. Needed whenever Normal mapping with MikkTSpace is used with glossy materials.
Field marks
- Needs unnormalised normals in mips; normalised DXT/BC5 normals lose the length information
- Assumes isotropic Gaussian normal spread, so directional grooves lose their stretched highlight
- Only affects specular, not diffuse brightness changes with scale
- Roughness bake must be redone if texture is retiled or rescaled
Presets
Toksvig filtering of a sub-pixel bump normal field: aliased (left) vs filtered (right)
{
"SHININESS": 90,
"BUMP_FREQ": 420,
"BUMP_AMP": 0.55
}Show GLSL (41 lines)
// Toksvig specular antialiasing. A sphere with a very high-frequency bump normal field (sub-pixel period).
// Left: Blinn-Phong on the single pixel-centre normal: highlights sparkle/alias.
// Right: the 4x4 footprint average normal (what a mip would store) is shorter than 1; Toksvig
// ft = |N| / (|N| + s (1 - |N|)) shrinks the exponent so the highlight blurs instead of sparkling.
const float SHININESS = 90.0;
const float BUMP_FREQ = 420.0;
const float BUMP_AMP = 0.55;
vec3 bumpNormal(vec2 fc, out bool hit) {
vec2 uv = (fc - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.0, 4.0), rd = normalize(vec3(uv, -2.4));
float b = dot(ro, rd); float h = b * b - dot(ro, ro) + 0.64;
hit = h > 0.0; if (!hit) return vec3(0.0, 0.0, 1.0);
vec3 p = ro + rd * (-b - sqrt(h)); vec3 n = normalize(p);
vec3 t1 = normalize(cross(n, vec3(0.0, 1.0, 0.2))), t2 = cross(n, t1);
return normalize(n + BUMP_AMP * (sin(BUMP_FREQ * p.x + 3.0 * p.y) * t1 + sin(BUMP_FREQ * 1.3 * p.y - 2.0 * p.x) * t2));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec3 v = vec3(0.0, 0.0, 1.0);
vec3 l = normalize(vec3(-0.4, 0.5, 0.8));
vec3 hv = normalize(l + v);
bool hit; vec3 n0 = bumpNormal(fragCoord, hit);
vec3 col = vec3(0.03) + 0.04 * (fragCoord.y / iResolution.y);
if (hit) {
vec3 avg = vec3(0.0);
for (int j = 0; j < 4; j++) for (int i = 0; i < 4; i++) {
bool hh; avg += bumpNormal(fragCoord + (vec2(float(i), float(j)) - 1.5) * 0.25 * 4.0 / 1.0 * 0.5, hh);
}
avg /= 16.0; float len = length(avg);
bool left = fragCoord.x < 0.5 * iResolution.x;
vec3 n = left ? n0 : normalize(avg);
float s = left ? SHININESS : SHININESS * len / (len + SHININESS * (1.0 - len));
float norm = (s + 8.0) / 25.13;
float nl = max(dot(n, l), 0.0);
col = vec3(0.35, 0.12, 0.1) * nl + vec3(1.0) * norm * pow(max(dot(n, hv), 0.0), s) * nl * 0.9;
}
if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);
col = col / (1.0 + col);
fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| toksvig-mipmapping-specimen | Tesla T4 1920x1080 | 12.9× baseline (moderate) · 0.424 ms / 0.429 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| toksvig-mipmapping-specimen | NVIDIA L4 1920x1080 | 9.36× baseline (moderate) · 0.149 ms / 0.151 ms · 2.8× faster on L4 | opengl-timer-query · Cross-architecture validation |
| toksvig-mipmapping-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 7.72× baseline (moderate) · 0.222 ms / 0.223 ms · 1.9× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): cited by Voxel Cone Tracing.
Crosses
- Toon highlights that do not sparkle: Toon specular blobs and band edges that stay crisp up close but stop shimmering on normal-mapped surfaces at distance. Normal variance from mip filtering widens the toon thresholds, where a PBR shader would widen its lobe.
Sources
- primaryMichael Toksvig (2005). Mipmapping Normal Maps. Journal of Graphics Tools.Verified via crossref · 2026-11-29doi:10.1080/2151237x.2005.10129203