code wiki / _hdl_build / nx_raster3d.nx

nx_raster3d.nx

buildroot/runtime/_hdl_build/nx_raster3d.nx

13187 B204 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic raster3d
docsdependenciesstructsconstsfunctions

about

nx_raster3d.nx -- GATE: the SOVEREIGN INTEGER-DETERMINISTIC 3D PIPELINE (closes the GRAPHICS-API "3D pipeline" gap -- the LAST software OS gap). Extends nx_raster (2D edge-function fill) to a real 3D renderer, 100% integer/ fixed-point => BIT-EXACT on ANY CPU (x86/RISC-V/no-FPU), NO GPU/driver. Stages: (1) TRANSFORM -- fixed-point (Q8) rotate-around-Y + translate (model->view). (2) PROJECT -- perspective projection: screen = center + focal*coord / view_z (the divide-by-z that makes 3D). (3) Z-BUFFER -- per-pixel depth test (barycentric-interpolated view-z); nearer occludes farther = hidden-surface removal, the defining 3D feature. (4) SHADE -- integer flat Lambert: intensity = dot(faceNormal, light) normalized by integer isqrt. T1 projection KAT (a view point projects to the exact screen pixel). T2 Z-BUFFER occlusion is ORDER-INDEPENDENT (near occludes far whether drawn near-first or far-first). T3 full pipeline renders a tetrahedron (transform->project->z-buffer); a real image, front faces occlude back. T4 (EXCEED) determinism -- render twice -> BIT-IDENTICAL framebuffer + z-buffer checksum. T5 flat-shading KAT (normal-toward-light=full, perpendicular=dark) + bounds (no OOB writes). expect_exit: 0 Sovereign: nx_syscalls. NEVER-BRICK: software render, writes 0 GPU firmware.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_raster3d.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write sys_mmap project g_pn sys_mmap ↻ sys_write ↻ ck g_puts ↻ fb_clear draw_tri3d edge render_tetra fb_clear ↻ sys_mmap ↻ transform project ↻ shade isqrt draw_tri3d ↻ fb_filled cksum shade ↻ fb_get sys_openat_append sys_write ↻ sys_close sys_exit

structs

none

consts

16const K_MAGIC_5381: i64 = 5381
22const W: i64 = 64
23const H: i64 = 64
24const SCALE: i64 = 256 // Q8 fixed-point
25const FOCAL: i64 = 350
26const CAMZ: i64 = 420 // push the model in front of the camera
27const CX: i64 = 32
28const CY: i64 = 32
29const ZINF: i64 = 1000000000
31const SIN30: i64 = 128
32const COS30: i64 = 222

functions

18func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: ckmain calls 1: sys_write
19func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 }
called by 1: main calls 2: sys_mmapsys_write
20func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
called by 1: main calls 1: g_puts
34func isqrt(n: i64) -> i64 { if n<=0 { return 0 } var x: i64=n; var y: i64=(x+1)/2; while y<x { x=y; y=(x+n/x)/2 } return x }
called by 1: shade
35func fb_clear(fb: *i64, zb: *i64) -> i64 { var i: i64=0; while i<W*H { fb[i]=0; zb[i]=ZINF; i=i+1 } return 0 }
called by 2: render_tetramain
36func fb_get(fb: *i64, x: i64, y: i64) -> i64 { return fb[y*W+x] }
called by 1: main
37func zb_get(zb: *i64, x: i64, y: i64) -> i64 { return zb[y*W+x] }
38func fb_filled(fb: *i64) -> i64 { var c: i64=0; var i: i64=0; while i<W*H { if fb[i]!=0 { c=c+1 } i=i+1 } return c }
called by 1: render_tetra
39func cksum(fb: *i64) -> i64 { var h: i64=K_MAGIC_5381; var i: i64=0; while i<W*H { h=((h<<5)+h)+fb[i]; i=i+1 } return h }
called by 1: main
42func transform(wx: i64, wy: i64, wz: i64, vout: *i64) -> i64
called by 1: render_tetra
49func project(vx: i64, vy: i64, vz: i64, sout: *i64) -> i64
called by 2: render_tetramain
56func edge(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> i64 { return (bx-ax)*(py-ay) - (by-ay)*(px-ax) }
called by 1: draw_tri3d
59func draw_tri3d(fb: *i64, zb: *i64, x0: i64, y0: i64, z0: i64, x1: i64, y1: i64, z1: i64, x2: i64, y2: i64, z2: i64, color: i64) -> i64
called by 2: render_tetramain calls 1: edge
90func shade(cr: i64, ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64, cx: i64, cy: i64, cz: i64, lx: i64, ly: i64, lz: i64) -> i64
called by 2: render_tetramain calls 1: isqrt
106func render_tetra(fb: *i64, zb: *i64) -> i64
140func main() -> i64