Repository navigation
Renderer
ob_engine::render is a resolution-independent software renderer for Build-style worlds. It
has no fixed 320×200 assumptions: the same code draws 640×360 or 7680×4320.

- Wall pass. Each screen column casts one 2D ray through the sector/portal graph from the camera's sector. Walls, sloped floors and ceilings and parallax skies are drawn front to back into a column-major buffer, with a per-pixel depth (perpendicular distance in xy units).
- Sprite and masked-wall pass. Face sprites, wall- and floor-aligned sprites, voxels and masked (see-through) walls are drawn back to front with a depth test.
- Columns are independent, so both passes run in parallel on all cores (rayon).
The column-major layout keeps every column's pixels contiguous in memory; the frontend scaler reads it directly, so the frame is never transposed.
- Horizontal field of view uses Hor+ scaling: wider screens see more, never less vertically.
-
Renderer::y_stretchemulates the original's non-square pixels. Fitting renders against captures of the original gave1.0with the eye heightEYE_STAND = 0x3800. -
Camera::horizis the vertical look offset (200-line units; positive looks down).
- Walls: texture u from the position along the wall, v stepped in 32.32 fixed point. Flags handle x/y flip, bottom alignment, swapped bottom textures, one-way and translucent walls.
-
Flat planes: a flat floor's depth on a screen row is
height / k, wherekis the row's ray slope.Viewstores1 / kper row, so a pixel costs a multiply, not a divide. -
Sloped planes: plane equations from
geom::plane_eq, intersected per pixel. - Parallax skies: sampled by view angle with the map's sky tile offsets.
-
Texture wrapping: almost every Build texture is a power of two, so
wrap()masks instead of dividing. -
Shading: surface shade plus distance shading, looked up in the true-colour
ShadeLuts. Distance addsdistance × visibility / (5 × 65536)shade steps, where visibility is the map's global value scaled by the sector's own (sector_vis, used everywhere: walls, planes, surfaces seen through room-over-room portals, masked walls and sprites). The divisor was fitted to DOSBox captures of nine map starts (mean block-brightness error 7.4 → 4.3). - Sprite lighting: a sprite adds its sector's current floor shade, or the ceiling shade under an open sky, so enemies in a dark corridor are as dark as the corridor (E2M4) and a tree in a sunlit courtyard stays bright (E4M9).
-
Voxels: one voxel per sprite texel (
xrepeat / 4xy units), the model standing on the sprite's z. Fitted to the voxel crates visible at the E4M9 and E2M4 starts.
Game::sprite_draws builds a SpriteDraw list with animation and 8-direction rotation
frames already resolved and positions interpolated between ticks. The renderer projects them
by kind (face, wall, floor, voxel), then draws columns back to front:
- an opaque, no-portal fast loop with fixed-point texture rows for the common case;
- translucency (
SPR_TRANS,SPR_TRANS_REV) via 50/50 or reversed blends; - voxels are ray-cast per pixel against the KVX model's slabs. Pixels already covered by something nearer than the model's closest point skip the ray cast, and voxels completely behind the camera are culled.
Blood stacks rooms with marker sprites: looking through a floor or ceiling continues in a linked sector, offset by (dx, dy, dz). Water and goo links are opaque in Blood; stack links are see-through.
- While casting a column, the renderer marks pixels whose floor/ceiling is a see-through link
with a portal id (
portal_id(sector, floor)). - Those pixels are traced into the linked room. For the common case a lazily built per-column
sector list (
ColTrace+trace_column) is reused by every pixel of the column; nested portals inside the linked room fall back totrace_pixel. - Sprites standing in the linked room get the portal id and are only drawn on pixels that show that portal.
- The portal mask is cleared only for columns that marked portals in the previous frame.
Measured at 8K (7680×4320), pixel-identical before and after each change:
| Change | Effect |
|---|---|
| Lazy per-column ROR traversal instead of per-pixel tracing | E4M1 walls 109 → 22 ms |
| Clear only the portal-mask columns used last frame | E2M4 walls 9.7 → 7.1 ms |
| Fixed-point sprite rows + opaque fast loop | E2M4 close zombies 18.5 → 8.6 ms |
| Cull voxels entirely behind the camera | E1M7 112 → 29 ms |
Use openblood perf DATA MAP W H to measure a change, and compare shotg renders before and
after to make sure the output did not change.
OpenBlood is MIT licensed and contains no Blood game content. Blood is © 1997 Monolith Productions. This wiki is generated from the wiki/ folder; edit it there.