Module 08

Stylized & art shaders

Toon shading with a fake light

You don't need real 3D geometry to fake a lit sphere. Take the SDF circle from Module 04, and treat normalize(p) — the direction from the center out to the current point — as a stand-in for a surface normal. dot() that against a light direction (Module 02's "how aligned" trick) and you get a smooth 0–1 lighting value, exactly like real diffuse lighting, without a single triangle.

The "toon" part is one extra step: instead of using that lighting value smoothly, snap it into a small number of hard bands with floor(lighting * bands) / bands. That's posterization — collapsing a continuous range into discrete steps — and it's the entire mechanism behind cel-shaded lighting.

smooth lighting floor(x·bands)/bands
Same input, four hard steps instead of a smooth ramp — that's the whole trick behind the toon look.

Blend modes are just more formulas

Multiply (a * b), screen (1.0 - (1.0 - a) * (1.0 - b)), overlay — these are the blend modes from every image editor you've used, and they're built from the exact same "combine two colors with a formula" idea as the alpha compositing from Module 07. The difference is intent: alpha compositing is about correctness (does this pixel show the foreground or background), blend modes are about style (how do these two colors interact visually).

Chromatic aberration

Real lenses bend different wavelengths of light by slightly different amounts, so edges pick up faint red/blue fringing. You can fake it cheaply by evaluating your scene three times — once per color channel — each with the sampling coordinate nudged a tiny amount outward from center, then taking red from one pass, green from another, blue from a third. That's exactly what you'll add to the toon-shaded ball on the right.

Predict the output

floor(lighting * bands) / bands does what to a smooth 0–1 lighting value?