Toon / cel shading with lighting ramps
Quantizes diffuse lighting into a few flat tonal bands, usually via a 1D ramp texture or step functions, so a 3D surface reads as hand-inked cartoon colour.
Also known as cel shading, toon ramp, Toon Shading, Cartoon Shading
In the family Stylized & non-photorealistic rendering, lit shading ramps
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | new THREE.MeshToonMaterial({ gradientMap }) docs |
| Babylon.js 9.38.0 | Official add-on | new BABYLON.CellMaterial('m', scene) from @babylonjs/materials docs |
| Godot 4.7 | Built in | BaseMaterial3D.diffuse_mode = DIFFUSE_TOON; specular_mode = SPECULAR_TOON docs Single hard cutoff, no custom ramp texture without a shader. |
| Unity | Official add-on | Package Manager > Unity Toon Shader (com.unity.toonshader) > Universal Render Pipeline/Toon docs Official Unity Toon Shader package (UTS3); URP and HDRP. |
| Unreal 5.7 | None found | |
| Blender 5.2 | Built in | Shader Editor > Add > Shader > Toon BSDF (or Shader to RGB + Color Ramp in EEVEE) docs |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
The shader computes a scalar lighting term, typically N·L (often remapped as half-Lambert so the terminator is softer), and uses it to look up a ramp instead of feeding it straight to the output. The ramp is either a small 1D texture an artist can paint, or a handful of step/smoothstep thresholds blending between a shadow colour, a base colour and a highlight colour. Choosing hue-shifted shadow colours (cool and saturated rather than just darker) is what gives the look its character. Specular is usually a hard-edged blob from thresholding N·H, and a rim term from 1 − N·V adds a graphic edge light. Anti-aliasing the thresholds with fwidth prevents shimmering on the band borders. Outlines are a separate pass (see the outline entries).
When to choose it
Reach for it when
- want flat cartoon colour that reacts to light
- lighting gradients look too realistic for my stylised game
- need banded cel-shaded look
- 3d character should look hand-inked
Choose it when you want a flat-colour animated or comic look that still responds to a light direction. Prefer Gooch tone shading when the goal is legible technical or CAD-style depiction with warm-to-cool tone rather than banding. Prefer Guilty Gear Xrd anime-style 3D shading when you need a hand-authored, animator-controlled look where artists sculpt shadow shapes through vertex data rather than letting the light decide. Prefer Posterization for a purely image-space version.
Field marks
- Band borders crawl and alias on curved surfaces unless thresholds are filtered with screen-space derivatives
- Low-poly normals make the terminator follow facets; smooth or bake custom normals
- Self-shadowing and cast shadows must be thresholded too, or soft shadow gradients break the flat look
- A single N·L ramp cannot give artist-controlled shadow shapes on faces; shadows look noisy on small features
Presets
Three-band toon ramp on an SDF sphere
{
"bands": 3,
"t1": 0.45,
"t2": 0.75
}Show GLSL (51 lines)
// GLSL ES 3.0, Shadertoy-style: toon ramp on a raymarched SDF sphere
const vec3 LIGHT_DIR = vec3(0.6, 0.7, -0.4);
const vec3 SHADOW_COL = vec3(0.35, 0.18, 0.45);
const vec3 MID_COL = vec3(0.95, 0.45, 0.30);
const vec3 LIT_COL = vec3(1.00, 0.85, 0.55);
const float T1 = 0.45; // shadow / mid threshold on half-Lambert
const float T2 = 0.75; // mid / lit threshold
const float RIM_POWER = 3.0;
float sdScene(vec3 p){
float s = length(p - vec3(0.0, 0.1, 0.0)) - 1.0;
float f = p.y + 1.0;
return min(s, f);
}
vec3 calcN(vec3 p){
vec2 e = vec2(0.001, 0.0);
return normalize(vec3(sdScene(p+e.xyy)-sdScene(p-e.xyy),
sdScene(p+e.yxy)-sdScene(p-e.yxy),
sdScene(p+e.yyx)-sdScene(p-e.yyx)));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 uv = (fragCoord - 0.5*iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.3, -3.5);
vec3 rd = normalize(vec3(uv, 1.7));
float t = 0.0; bool hit = false;
for(int i=0;i<80;i++){
float d = sdScene(ro + rd*t);
if(d < 0.001){ hit = true; break; }
t += d;
if(t > 20.0) break;
}
vec3 bg = mix(vec3(0.97,0.90,0.78), vec3(0.62,0.78,0.92), uv.y + 0.5);
vec3 col = bg;
if(hit){
vec3 p = ro + rd*t;
vec3 n = calcN(p);
vec3 l = normalize(vec3(LIGHT_DIR.x*cos(iTime*0.3), LIGHT_DIR.y, LIGHT_DIR.z));
float ndl = dot(n, l) * 0.5 + 0.5;
float w = max(fwidth(ndl), 0.002); // antialias the ramp steps
float b1 = smoothstep(T1 - w, T1 + w, ndl);
float b2 = smoothstep(T2 - w, T2 + w, ndl);
vec3 base = (p.y < -0.99) ? vec3(0.75,0.85,0.70) : MID_COL;
vec3 ramp = mix(SHADOW_COL, base, b1);
ramp = mix(ramp, LIT_COL, b2 * step(-0.99, p.y));
float rim = pow(1.0 - max(dot(n, -rd), 0.0), RIM_POWER);
ramp += step(0.6, rim) * 0.25 * step(-0.99, p.y);
col = ramp;
}
fragColor = vec4(col, 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| toon-ramp-sdf-sphere | Tesla T4 1920x1080 | 8.88× baseline (moderate) · 0.292 ms / 0.303 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| toon-ramp-sdf-sphere | NVIDIA L4 1920x1080 | 6.72× baseline (moderate) · 0.107 ms / 0.109 ms · 2.7× faster on L4 | opengl-timer-query · Cross-architecture validation |
| toon-ramp-sdf-sphere | NVIDIA A100-SXM4-40GB 1920x1080 | 5.01× baseline (light) · 0.144 ms / 0.145 ms · 2.0× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): cited by Inverted-hull outlines.
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.
- Inverted-hull outlines: Hull pass supplies the ink line; toon pass supplies the flat colour bands on the mesh itself.
- Depth/normal Sobel edge outlines: Edge pass draws creases and silhouettes over the toon-shaded colour buffer.
Sources
- primaryAmy Gooch, Bruce Gooch, Peter Shirley, Elaine Cohen (1998). A non-photorealistic lighting model for automatic technical illustration. Proceedings of the 25th annual conference on Computer graphics and interactive techniques - SIGGRAPH '98.Verified via crossref · 2026-11-29doi:10.1145/280814.280950
- tutorialWikipedia. Cel shading (outline section). en.wikipedia.org.Verified via live page · 2026-11-29