code wiki / _hdl_build / nx_raster3d_tex.nx

nx_raster3d_tex.nx

buildroot/runtime/_hdl_build/nx_raster3d_tex.nx

9459 B128 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic raster3d
docsdependenciesstructsconstsfunctions

about

nx_raster3d_tex.nx -- GATE: PERSPECTIVE-CORRECT TEXTURE MAPPING, the SOTA upgrade to the 3D pipeline (closes the GRAPHICS-API "Polish: textures" gap). Extends the integer-deterministic rasterizer (nx_raster3d) with textured triangles that interpolate u/z, v/z, 1/z linearly in screen space and per-pixel divide to recover perspective- correct (u,v) -- the Quake-era SOTA technique. Affine mapping (interpolating u,v directly) WARPS under perspective; this gate PROVES the difference with an exact KAT: on an edge from a near vertex (u=0) to one 3x farther (u=8), the screen midpoint must sample the PERSPECTIVE value u=2 (the near vertex dominates), not the affine midpoint u=4. T1 perspective-correct KAT: midpoint samples u=2 (NOT affine 4). T2 a textured checkerboard quad renders (filled + both texture colors present). T3 (EXCEED) determinism -- render twice -> BIT-IDENTICAL framebuffer. T4 equal-depth sanity: with all z equal, perspective-correct REDUCES to affine (u=4) -- correct in both regimes. expect_exit: 0 Sovereign: nx_syscalls. NEVER-BRICK: software render, writes 0 GPU firmware.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_raster3d_tex.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 fb_clear draw_tri_tex edge g_pn sys_mmap ↻ sys_write ↻ ck g_puts ↻ fb_filled cksum sys_openat_append sys_write ↻ sys_close sys_exit

structs

none

consts

13const INVZ_MAGIC_5381: i64 = 5381
19const W: i64 = 64
20const H: i64 = 64
21const ZINF: i64 = 1000000000
22const INVZ_Q: i64 = 1048576 // 2^20: perspective inverse-depth fixed-point scale

functions

15func 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
16func 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
17func 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
24func 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 1: main
25func 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: main
26func cksum(fb: *i64) -> i64 { var h: i64=INVZ_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
27func 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_tri_tex
32func draw_tri_tex(fb: *i64, zb: *i64, x0: i64, y0: i64, z0: i64, u0: i64, v0: i64, x1: i64, y1: i64, z1: i64, u1: i64, v1: i64, x2: i64, y2: i64, z2: i64, u2: i64, v2: i64, tex: *i64, texw: i64, texh: i64) -> i64
called by 1: main calls 1: edge
71func main() -> i64