Skip to main content

Module world_lighting

Module world_lighting 

Source
Expand description

Voxlap’s world-voxel lighting bake (updatelighting, voxlap5.c:10539).

Walks every visible voxel inside a 3D bounding box and rewrites its alpha byte (the per-voxel “brightness” channel that the rendering path mulhi’es against kv6colmul-style modulators) based on the engine’s current LightSrc set + lightmode.

Two modes:

  • lightmode == 1: cheap directional bake — every voxel gets shading from a single hardcoded sun direction (tp.y * 0.5 + tp.z) * 64 + 103.5 clamped to [0, 255].
  • lightmode == 2: per-light Lambertian bake — for each light in range, subtract g * h * sc where g = 1/(d·d²) - 1/(r·r²) (cube-falloff with hard cutoff at radius r), h = surface_normal · light_delta (negative ⇒ face front- lit, contributes; positive ⇒ self-shadowed, skipped). Result subtracts from a base (tp.y * 0.5 + tp.z) * 16 + 47.5.

The surface normal tp for each voxel comes from estnorm — a 5×5×5 voxel-solid neighbourhood vote (ESTNORMRAD == 2 in voxlap, the production path).

Structs§

EstNormCache
Pre-built expandbit256 grid covering a 2D bounding region — (x1 - x0 + 2*RAD) × (y1 - y0 + 2*RAD) columns. Trades 32 bytes per column of memory for O(1) bit-window lookups during the estnorm 5×5 neighbourhood vote.

Functions§

apply_lighting_with_cache
S4B.4.b: write half of update_lighting_chunk, split out so callers can build the EstNormCache separately (via EstNormCache::build_with_reader) and pass it in.
update_lighting
Bake per-voxel lighting into the world’s brightness bytes. Mirror of voxlap’s updatelighting (voxlap5.c:10539).
update_lighting_chunk
S4B.4.b: per-chunk variant of update_lighting.