---
id: "toon-shading"
title: "Toon / cel shading with lighting ramps"
aliases: [cel shading, toon ramp, Toon Shading, Cartoon Shading]
domain: "npr"
stage: "lighting"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot]
inputs: [normals, material-params]
outputs: [ldr-image]
style: "stylized"
dynamic: "dynamic"
cost: "cheap"
authority: "Gooch et al., 1998"
url: "https://texelatlas.vercel.app/t/toon-shading/"
sources_verified_at: "2026-11-29"
---
# Toon / cel shading with lighting ramps (Gooch et al., 1998)

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

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

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

Choose it when you want a flat-colour animated or comic look that still responds to a light direction. Prefer [Gooch tone shading](https://texelatlas.vercel.app/t/gooch-shading.md) 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](https://texelatlas.vercel.app/t/guilty-gear-xrd-shading.md) 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](https://texelatlas.vercel.app/t/posterization.md) for a purely image-space version.

## Cost

cheap — Qualitatively a few ALU ops per pixel plus one tiny ramp lookup; negligible next to any physically based shading pass.
Measured GPU Weight: 8.88× baseline (moderate) — 0.2921 ms median / 0.3031 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 6.72× baseline (moderate) — 0.1068 ms median (2.74× faster on L4).
Ampere A100 scaling: 5.01× baseline (light) — 0.1443 ms median (2.02× faster on A100).

## Failure modes

- 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

## Engine support

- babylonjs: official — `new BABYLON.CellMaterial('m', scene) from @babylonjs/materials` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/materials/src/cell/cellMaterial.ts, checked 2026-12-01)
- blender: builtin — `Shader Editor > Add > Shader > Toon BSDF (or Shader to RGB + Color Ramp in EEVEE)` (evidence: https://docs.blender.org/manual/en/5.2/render/shader_nodes/shader/toon.html, checked 2026-12-01)
- godot: builtin — `BaseMaterial3D.diffuse_mode = DIFFUSE_TOON; specular_mode = SPECULAR_TOON` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/BaseMaterial3D.xml, checked 2026-12-01) — Single hard cutoff, no custom ramp texture without a shader.
- threejs: builtin — `new THREE.MeshToonMaterial({ gradientMap })` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/materials/MeshToonMaterial.js, checked 2026-12-01)
- unity: official — `Package Manager > Unity Toon Shader (com.unity.toonshader) > Universal Render Pipeline/Toon` (evidence: https://github.com/Unity-Technologies/com.unity.toonshader, checked 2026-12-01) — Official Unity Toon Shader package (UTS3); URP and HDRP.

## Dataflow

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

## Presets

### Three-band toon ramp on an SDF sphere (glsl-fragment; rendered 2026-11-29)

```json
{
  "bands": 3,
  "t1": 0.45,
  "t2": 0.75
}
```

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

## Combines with

- [Inverted-hull outlines](https://texelatlas.vercel.app/t/inverted-hull-outline.md): Hull pass supplies the ink line; toon pass supplies the flat colour bands on the mesh itself.
- [Depth/normal Sobel edge outlines](https://texelatlas.vercel.app/t/screen-space-edge-outline.md): Edge pass draws creases and silhouettes over the toon-shaded colour buffer.

## Combination ideas

- [Toon highlights that do not sparkle](https://texelatlas.vercel.app/ideas/variance-aware-toon-bands/)

## Sources

1. [primary] Amy 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. https://doi.org/10.1145/280814.280950 (verified via crossref on 2026-11-29)
2. [tutorial] Wikipedia Cel shading (outline section). en.wikipedia.org. https://en.wikipedia.org/wiki/Cel_shading (verified via http on 2026-11-29)

## Cite this entry

Texel. "Toon / cel shading with lighting ramps." https://texelatlas.vercel.app/t/toon-shading/ (accessed 2026-12-01).
