code wiki / _hdl_build / nx_cube3d_lit_gate.nx
nx_cube3d_lit_gate.nx
buildroot/runtime/_hdl_build/nx_cube3d_lit_gate.nx
about
nx_cube3d_lit_gate.nx -- LIT 3D: per-face Lambert shading. Rotated face NORMALS (cross product of rotated
edges, forced OUTWARD via the centroid) dotted with a light direction L, modulating each face's base color.
This is the step from "flat-colored cube" to "a real lit object" -- the lighting axis toward photoreal.
Light L=(3,4,12) (|L|=13, a Pythagorean quad -> no sqrt). NLMAX=4*S^2*|L| is DERIVED from cube geometry
(every cube face-normal has magnitude 4*S^2), not a magic constant. Composes nx_depth_tri. license_tier: ORIGINAL expect_exit: 0
dependencies 4 imports · 0 importers
imports: nx_syscalls.nxnx_image.nxnx_depth_tri.nxnx_png_write.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
| 11 | const AMB: i64 = 105 // ambient floor (~41%): lifts shadowed faces to a pleasant level, directional term still shows |
functions
| 13 | func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 14 | func pn(v: i64) -> i64 { let t: *u8=sys_mmap(24); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let b: *u8=sys_mmap(24); var j: i64=0; while j<k{b[j]=t[k-1-j];j=j+1} sys_write(1,b,k); return 0 } |
| 16 | func isin(deg: i64) -> i64 |
| 24 | func icos(deg: i64) -> i64 { return isin(deg + 90) } |
| 27 | func rot3(vx: i64, vy: i64, vz: i64, ay: i64, ax: i64, out: *i64) -> i64 |
| 41 | func ndotl_face(rx: *i64, ry: *i64, rz: *i64, ia: i64, ib: i64, ic: i64, id: i64) -> i64 called by 1: face_r |
| 54 | func shade_of(ndl: i64, nlmax: i64) -> i64 called by 1: face_r |
| 61 | func face_r(fb: *Image, zb: *i64, rx: *i64, ry: *i64, rz: *i64, px: *i64, py: *i64, pz: *i64, ia: i64, ib: i64, ic: i64, id: i64, r: i64, g: i64, b: i64, nlmax: i64, lit: i64) -> i64 |
| 72 | func cube_lit(fb: *Image, zb: *i64, rx: *i64, ry: *i64, rz: *i64, px: *i64, py: *i64, pz: *i64, npix: i64, nlmax: i64, lit: i64) -> i64 |
| 86 | func main() -> i64 |