code wiki / (root) / nx_zbuf.nx

nx_zbuf.nx

buildroot/runtime/nx_zbuf.nx

10598 B287 linesdepth 5pulls 9 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_image.nx nx_raster.nx nx_zbuf.nx nx_render_pass.nx

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

main nx_image_alloc sys_mmap nx_image_s64_alloc sys_mmap ↻ nx_zbuf_clear nx_image_s64_get nx_image_set nx_zbuf_triangle _zbuf_edge nx_image_s64_get ↻ nx_image_set ↻ nx_image_s64_set nx_image_get nx_zbuf_verdict_is_valid

structs

none

consts

71const NX_ZBUF_FAR: i64 = 0x7FFFFFFFFFFFFFFF
75const NX_ZBUF_OK: nx_int = 0
76const NX_ZBUF_ERR_BAD_BUFFER: nx_int = 1
77const NX_ZBUF_ERR_DEGENERATE: nx_int = 2
78const NX_ZBUF_N_VERDICTS: nx_int = 3

functions

80func nx_zbuf_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
91func nx_zbuf_clear(zbuf: *ImageS64) -> nx_int
117func _zbuf_edge(ax: nx_int, ay: nx_int,
called by 1: nx_zbuf_triangle
129func nx_zbuf_triangle(img: *Image, zbuf: *ImageS64,
211func main() -> i64