Skip to main content

Module dda_sprite

Module dda_sprite 

Source
Expand description

Clean-room KV6 sprite raycaster for the DDA backend (Substage DDA.8).

Renders KV6 sprites by per-pixel ray casting: for every screen pixel the sprite covers, transform the camera ray into the sprite’s local voxel space, 3D-DDA through the KV6, and depth-composite the first solid voxel against the shared z-buffer. Clean-room (no voxlap code), the sprite counterpart to the terrain renderer in crate::dda.

Depth parity. Transforming the ray by the inverse sprite basis leaves the ray parameter unchanged in world units — a hit at local parameter t is at world point cam.pos + dir·t — so the perpendicular depth is t · (dir·forward), exactly the convention crate::dda writes for terrain. Sprites therefore occlude and are occluded by DDA terrain correctly.

Shading reads the KV6 voxel’s baked brightness byte (high byte of the packed colour) via [crate::dda::shade] — the clean-room brightness model, not voxlap’s dir-LUT reflection shading.

Structs§

ClipFlipbook
CPU-side decoded animated voxel clip: every frame’s SpriteDense is cached at construction, so per-frame playback is a grid select — not the per-frame voxel-volume decode draw_sprite_dda pays each call. The CPU counterpart to the GPU flipbook (VCL.2). Build once from a DecodedClip, then draw_frame the active frame each render.
SpriteDense
Dense occupancy + colour grid for one sprite frame, plus its pivot — the decoded form the per-pixel raycaster marches. Built once from a Kv6 (SpriteDense::from_kv6) or a voxel-clip VoxelFrame (SpriteDense::from_voxel_frame); the latter lets an animated clip cache every frame’s grid up front instead of rebuilding per frame.
SpriteShade
Material context for a translucent sprite draw (TV stage): the global MaterialTable plus this instance’s uniform material id and per-frame alpha multiplier. Passed (as Some) to draw_sprite_dense_shaded / ClipFlipbook::draw_frame_shaded to enable front-to-back accumulate-and-continue compositing; None (or an all-opaque effective material) takes the existing first-hit opaque path byte-for-byte.

Functions§

draw_sprite_dda
Draw one KV6 Sprite into (fb, zb) by per-pixel ray casting, depth-compositing against whatever the terrain pass already wrote. Returns the number of pixels written.
draw_sprite_dda_shaded
Draw one KV6 Sprite, optionally with a translucent material (TV stage) — the draw_sprite_dense_shaded counterpart of draw_sprite_dda. shade_ctx == None (or an opaque effective material) renders the sprite opaque, byte-for-byte unchanged.
draw_sprite_dense
Draw a pre-decoded SpriteDense at a world pose — the generalised core of draw_sprite_dda, shared by the KV6 path and animated ClipFlipbook frames. pos is the world pivot; s/h/f are the model→world basis columns (local +x/+y/+z); flags honours SPRITE_FLAG_INVISIBLE / SPRITE_FLAG_NO_Z. Returns pixels written.
draw_sprite_dense_shaded
Draw a pre-decoded SpriteDense at a world pose, optionally with a translucent material (TV stage). shade_ctx: