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

Functions§

update_lighting
Bake per-voxel lighting into the world’s brightness bytes. Mirror of voxlap’s updatelighting (voxlap5.c:10539).