Skip to main content

Module shading

Module shading 

Source
Expand description

shading — holographic cel lighting model for the Ling renderer.

The look the engine targets is anime / holographic cel: smooth shading over the surface (no faceted triangle edges) but with crisp posterised bands rather than a muddy Gouraud gradient. We get this by:

  1. lighting each vertex with smooth (averaged) normals — continuous across the mesh,
  2. interpolating the lit colour across the triangle (done by the rasteriser), then
  3. posterising per pixel (luminance banded, chroma preserved) so the band boundaries are smooth curves over the surface — the anime line.

On top of diffuse we add: • coloured lights — each light contributes its own RGB, • coloured shadows — unlit regions are tinted toward shadow (a complementary colour) instead of going flat black, • a Fresnel rim — a view-dependent edge glow for the holographic feel, • an optional normal-gradient sheen (holo) that shifts hue with the surface normal, like an iridescent film.

All colours here are linear [f32;3] in 0..1. The renderer converts to 0x00RRGGBB at the end.

Structs§

LightS
A coloured point light in world space (mirror of the engine’s Light).
ShadeParams
Tunable parameters for the cel/holo model.

Functions§

cel_ramp
Soft cel ramp for a single diffuse term: keeps smooth shading but gives the lit/shadow transition a gentle “step” so it reads as toon shading even before per-pixel posterisation. Smoothstep around two thresholds.
lit_vertex
Light one vertex. base, result in linear rgb 0..1. n = smooth world normal, pos = world position, eye = camera position.
pack
Pack linear 0..1 rgb into 0x00RRGGBB.
posterize
Posterise a colour into bands luminance levels while preserving chroma. This is what turns the smooth interpolated colour into crisp cel bands.
posterize_soft
posterize with a crossfade back toward the raw colour: softness = 0 is a crisp band edge, softness = 1 is fully smooth (no banding). Lets a material soften its toon step without reintroducing the per-vertex quantisation that pins band edges to mesh vertices.
unpack
Unpack 0x00RRGGBB into linear 0..1 rgb.
windwaker_cel_ramp
Wind Waker style 2-band toon diffuse step ramp with crisp shadow threshold.