code wiki / _hdl_build / nx_raster3d_tex.nx
nx_raster3d_tex.nx
buildroot/runtime/_hdl_build/nx_raster3d_tex.nx
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
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
structs
| none |
consts
| 13 | const INVZ_MAGIC_5381: i64 = 5381 |
| 19 | const W: i64 = 64 |
| 20 | const H: i64 = 64 |
| 21 | const ZINF: i64 = 1000000000 |
| 22 | const INVZ_Q: i64 = 1048576 // 2^20: perspective inverse-depth fixed-point scale |
functions
| 15 | func 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 } |
| 16 | func 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 } |
| 17 | func 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 } |
| 24 | func 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 |
| 25 | func 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 |
| 26 | func 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 |
| 27 | func 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 |
| 32 | func 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 |
| 71 | func main() -> i64 |