Toksvig normal-map filtering × Toon / cel shading with lighting ramps
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.
Open in StudioReproduced3.09× · 0.096 ms
Verified proof

Split-screen WebGL2 proof comparing raw normal-mapped toon shading (left) against Toksvig normal-length variance widening both diffuse cel ramp transitions and energy-conserving specular blobs at grazing/minified footprints (right).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · eliminates high-frequency normal-map toon band shimmer at distance while preserving crisp near-field ramp edges
Show GLSL proof (53 lines)
const float VARIANCE_GAIN = 2.6; // P
const float SPEC_THRESH = 0.88; // P
const float BUMP_FREQ = 26.0; // P
vec3 bumpNormal(vec2 uv, float lod) {
float f = BUMP_FREQ;
float atten = exp(-lod * 1.45);
vec2 g = vec2(cos(uv.x * f) * cos(uv.y * f), -sin(uv.x * f) * sin(uv.y * f)) * 0.65 * atten;
return vec3(g.x, g.y, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.35, 2.3), rd = normalize(vec3(uv, -1.55));
// Intersect tilted ground plane (y = -0.35) and foreground sphere
float tSphere = -1.0;
vec3 sc = vec3(0.0, 0.08, 0.0);
vec3 oc = ro - sc;
float b = dot(oc, rd), c = dot(oc, oc) - 0.62 * 0.62, disc = b * b - c;
if (disc > 0.0) tSphere = -b - sqrt(disc);
float tPlane = rd.y < -0.01 ? (-0.54 - ro.y) / rd.y : -1.0;
bool hitSphere = tSphere > 0.0 && (tPlane < 0.0 || tSphere < tPlane);
vec3 col = mix(vec3(0.86, 0.90, 0.94), vec3(0.55, 0.66, 0.78), clamp(uv.y + 0.5, 0.0, 1.0));
if (hitSphere || tPlane > 0.0) {
vec3 pos = hitSphere ? ro + rd * tSphere : ro + rd * tPlane;
vec3 baseN = hitSphere ? normalize(pos - sc) : vec3(0.0, 1.0, 0.0);
vec2 suv = hitSphere ? vec2(atan(baseN.x, baseN.z), asin(clamp(baseN.y, -1.0, 1.0))) * 1.6 : pos.xz * 0.55;
float dist = hitSphere ? length(pos - ro) * 0.35 : clamp(length(pos - ro) * 0.42, 0.0, 3.2);
// Analytic Toksvig average-normal shortening proxy from footprint mip level
vec3 rawAvg = bumpNormal(suv, dist);
float avgLen = clamp(length(rawAvg) / 1.18, 0.25, 1.0);
float variance = clamp((1.0 - avgLen) / max(avgLen, 0.15), 0.0, 1.2);
vec3 T = normalize(cross(abs(baseN.y) > 0.9 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0), baseN));
vec3 B = cross(baseN, T);
vec3 microN = normalize(rawAvg.x * T + rawAvg.y * B + rawAvg.z * baseN);
vec3 L = normalize(vec3(0.55 * cos(iTime * 0.25), 0.78, 0.62));
vec3 V = -rd;
vec3 H = normalize(L + V);
float ndl = dot(microN, L);
float ndh = max(dot(microN, H), 0.0);
bool useToksvig = uv.x > 0.0;
float aa = 0.025 + (useToksvig ? variance * VARIANCE_GAIN * 0.22 : 0.0);
float band1 = smoothstep(0.15 - aa, 0.15 + aa, ndl);
float band2 = smoothstep(0.58 - aa, 0.58 + aa, ndl);
vec3 baseAlb = hitSphere ? vec3(0.84, 0.36, 0.24) : vec3(0.32, 0.50, 0.46);
vec3 lit = baseAlb * (0.28 + 0.40 * band1 + 0.36 * band2);
float specEdge = SPEC_THRESH - (useToksvig ? variance * VARIANCE_GAIN * 0.12 : 0.0);
float specAa = 0.015 + (useToksvig ? variance * VARIANCE_GAIN * 0.10 : 0.0);
float specBlob = smoothstep(specEdge - specAa, specEdge + specAa, ndh);
float specEnergy = useToksvig ? 1.0 / (1.0 + variance * VARIANCE_GAIN * 1.4) : 1.0;
col = lit + vec3(1.0, 0.96, 0.88) * specBlob * 0.72 * specEnergy;
}
if (abs(uv.x) < 0.003) col = vec3(0.08);
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Why they connect
Toksvig normal-map filtering reads the mipped normal map and outputs material-params: a variance value per texel derived from the shortened average normal. Toon / cel shading with lighting ramps consumes material-params alongside normals: the variance widens the smoothstep transition of each ramp threshold, and enlarges the hard specular blob while lowering its intensity so the total highlight stays similar. Up close, variance is near zero and bands stay hard; far away, the bands soften exactly where hidden bumps would otherwise alias.
How to build it
In a three.js material via onBeforeCompile, a Godot spatial shader or a Unity Shader Graph custom node. Store normals unnormalised in the mips, or bake per-mip variance into a spare channel when BC5 compression renormalises them. In the toon function, set band softness to the screen-space derivative term already used for antialiasing plus k times the variance. For specular, lower the N·H threshold as variance grows and scale its brightness so the blob's energy stays similar. Tune k per material and compare a slow camera pull-back with and without the term.
Field marks
- Compressed normal maps lose the length information unless variance is baked separately.
- Too much softening makes distant toon objects look airbrushed.
- Isotropic variance ignores directional grooves.
- Some materials want deliberate sparkle, so the effect needs a per-material switch.
Prior art
No prior art found on 2026-11-29.
Searches run (4)
- arXiv: all:"toon shading" AND all:"specular aliasing" → 0 results
- GitHub repos: "toon shading" "specular aliasing" → 0 results
- arXiv: all:"cel shading" AND all:"normal map" AND all:"filtering" → 0 results
- GitHub repos: "cel shading" "normal map" filtering → 0 results