Skip to main content

Module material

Module material 

Source
Expand description

Voxel materials — per-voxel opacity + blend mode (alpha / additive) for transparent voxels (smoke, glass, water, spell glows). See material

  • PORTING-TRANSPARENCY.md. Voxel materials — opacity + blend mode for transparent voxels (TV stage).

Every voxel roxlap renders is opaque today: both backends are per-pixel front-to-back 3D-DDA raymarchers that stop at the first solid voxel. A material attaches an opacity and a blend mode to a voxel so the march can instead accumulate it front-to-back over what lies behind (the per-pixel DDA visits cells strictly front-to-back, so this is order-correct without any sorting — see PORTING-TRANSPARENCY.md).

Materials are kept out of the 0x80RRGGBB colour word: its high byte is voxlap’s lightmode-1 brightness, not alpha (see crate::kv6 and crate::vxl). Instead a voxel carries a one-byte material id that indexes a MaterialTable — a 256-entry global palette the renderer owns. Id 0 is permanently Material::OPAQUE, so a model or grid that carries no material data resolves every voxel to id 0 and renders exactly as before.

Structs§

Material
One material: an opacity and a blend mode, indexed out of a MaterialTable by a per-voxel material id.
MaterialTable
A 256-entry palette of Materials indexed by a per-voxel u8 material id. The renderer owns one table (a global palette); voxels reference materials by id rather than embedding them.

Enums§

BlendMode
How a voxel’s colour combines with what is already behind it along a ray.

Functions§

material_for_color
Resolve a voxel’s material id from a colour→material map — the authoring bridge for mixed-material models (TV.3). A model is colour-coded (e.g. cyan voxels = glass, grey = an opaque frame); map pairs an RGB colour (0xRRGGBB, the brightness byte is ignored) with the material id it maps to. A voxel whose colour isn’t in map resolves to 0 (Material::OPAQUE). Linear scan — map is tiny (a handful of material colours), so this stays cheap even called per voxel.