code wiki / _hdl_build / nx_raster3d_gouraud.nx

nx_raster3d_gouraud.nx

buildroot/runtime/_hdl_build/nx_raster3d_gouraud.nx

8247 B110 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic raster3d
docsdependenciesstructsconstsfunctions

about

nx_raster3d_gouraud.nx -- GOURAUD (SMOOTH) SHADING, the third renderer pillar (geometry=perspective-correct, texture=bilinear, lighting=Gouraud). Interpolates per-VERTEX colors/intensities across the triangle (barycentric, screen-affine -- the correct Gouraud model), per channel, integer/fixed-point => BIT-EXACT, no GPU. Flat shading bands per face; Gouraud is smooth. KAT distinguishes them: an R/G/B triangle's centroid is the smooth blend (~85,85,85), NOT a flat vertex color. T1 Gouraud KAT: centroid of a red/green/blue triangle = the exact barycentric blend (86,86,82), not flat. T2 smooth: the shaded triangle emits MANY distinct colors (a gradient), which flat per-face shading never would. T3 Gouraud LIGHTING: a surface lit at the vertices (intensities 255/128/40) shades as a smooth ramp, not 3 bands. T4 (EXCEED) determinism -- bit-identical across runs. expect_exit: 0 Sovereign: nx_syscalls. NEVER-BRICK: software render, writes 0 GPU firmware.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_raster3d_gouraud.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_gouraud edge g_pn sys_mmap ↻ sys_write ↻ ck g_puts ↻ lit cksum sys_openat_append sys_write ↻ sys_close sys_exit

structs

none

consts

12const K_MAGIC_5381: i64 = 5381
13const K_MAGIC_4096: i64 = 4096
19const W: i64 = 64
20const H: i64 = 64
21const ZINF: i64 = 1000000000

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
23func 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
24func 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
25func 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_gouraud
28func draw_tri_gouraud(fb: *i64, zb: *i64, x0: i64, y0: i64, z0: i64, c0: i64, x1: i64, y1: i64, z1: i64, c1: i64, x2: i64, y2: i64, z2: i64, c2: i64) -> i64
called by 1: main calls 1: edge
61func lit(base: i64, inten: i64) -> i64 { let r: i64=((base>>16)&255)*inten/255; let g: i64=((base>>8)&255)*inten/255; let b: i64=(base&255)*inten/255; return (r<<16)|(g<<8)|b }
called by 1: main
63func main() -> i64