nx_zbuf.nx
buildroot/runtime/nx_zbuf.nx
about
nx_zbuf.nx -- depth buffer + Z-tested triangle rasterizer.
Composes nx_raster (b3f83291) + nx_image.ImageS64 (depth buffer
container) to close the 3D-RENDERING gap on top of 2D rasterization.
Pure i64 substrate -- no FPU, no GPU. Software 3D renderer
minimum: depth buffer + per-vertex Z interpolation + depth test.
Composes:
nx_image.Image (color framebuffer, L1)
nx_image.ImageS64 (depth buffer, L1 -- signed i64 storage)
nx_raster._rast_edge (canonical edge function from L2)
nx_loop.LoopVerdict (bounded loops)
===== Math ======================================================
Per-vertex depth values z_a / z_b / z_c are provided by the
caller (in raw i64 -- caller chooses units; typically the
view-space Z * Q10 fixed-point). At pixel (px, py) the
interpolated depth is:
z_interp = (w0 * z_a + w1 * z_b + w2 * z_c) / area
where w_i are the same edge functions nx_raster uses for the
inside test. Smaller z = closer to viewer (standard
less-than-or-equal depth test).
Depth test: write color iff z_interp < z_buf[px, py].
===== Initial value =============================================
The depth buffer starts at "infinity." i64 max = 0x7FFFFFFFFFFFFFFF.
First write of any triangle's pixel is always accepted because
any real Z < INFINITY. Caller must clear the buffer to FAR
at the start of each frame via nx_zbuf_clear.
Per the bits-up cardinal: no inline rasterizer here -- we
COMPOSE _rast_edge from nx_raster.nx (NOT duplicate the algorithm).
genealogy_id: catmull_1974_subdivision_z_buffer + pineda_1988_edge_function +
blinn_1996_painters_algorithm_critique
dependencies 5 imports · 1 importers
imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_image.nxnx_raster.nx
imported by: nx_render_pass.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 71 | const NX_ZBUF_FAR: i64 = 0x7FFFFFFFFFFFFFFF |
| 75 | const NX_ZBUF_OK: nx_int = 0 |
| 76 | const NX_ZBUF_ERR_BAD_BUFFER: nx_int = 1 |
| 77 | const NX_ZBUF_ERR_DEGENERATE: nx_int = 2 |
| 78 | const NX_ZBUF_N_VERDICTS: nx_int = 3 |
functions
| 80 | func nx_zbuf_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 91 | func nx_zbuf_clear(zbuf: *ImageS64) -> nx_int |
| 117 | func _zbuf_edge(ax: nx_int, ay: nx_int, called by 1: nx_zbuf_triangle |
| 129 | func nx_zbuf_triangle(img: *Image, zbuf: *ImageS64, |
| 211 | func main() -> i64 |