code wiki / _hdl_build / nx_ng_radiance.nx
nx_ng_radiance.nx
buildroot/runtime/_hdl_build/nx_ng_radiance.nx
about
nx_ng_radiance.nx -- CAP-RADIANCE-FIELD, generation 8: a tiny NeRF. The defining recipe of NeRF/instant-ngp:
a COORDINATE NETWORK (MLP queried at sample positions) whose outputs are VOLUME-RENDERED into observations,
trained by INVERSE-RENDERING loss to recover the field from rendered measurements. Composes the two rungs
just built -- the autograd gradient engine (nx_nofloat_autograd) and the volume compositor (nx_ng_volrender)
-- on ONE Q16 integer tape: the composite C = sum_i w_i*f(x_i) is nfa_cmul (scale by the fixed transmittance
weight) + nfa_vadd, so the WHOLE chain (coord-MLP -> volume render -> loss) backprops end-to-end. No float.
Honest gated proof (HARD evidence): a shared MLP f(x)=W2*relu(W1*x+b1)+b2 is applied at N sample coords ->
colors c_i; R observations C_r = sum_i w[r][i]*c_i (volume composite, weights = a fixed invertible
transmittance matrix) are matched to targets generated from a TRUE field. Gate:
T1 LEARNS -- inverse-rendering SSE loss collapses (the gradient flows MLP<-render<-loss),
T2 FIELD RECOVERED -- the trained net reproduces the true field at the samples (|f(x_i)-c*_i| small):
teeth = it learned the RIGHT field through the renderer, not just any loss drop,
T3 BIT-EXACT -- train twice from the same init -> identical integer weights (structural determinism),
T4 UNTRAINED -- the initial loss is genuinely large (not vacuous).
Sovereign: imports nx_nofloat_autograd + nx_syscalls (no float). license_tier: ORIGINAL expect_exit: 0
dependencies 3 imports · 0 importers
imports: nx_nofloat_autograd.nxnx_itoa_lib.nxnx_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
| 20 | const K_MAGIC_6553: i64 = 6553 |
| 21 | const K_MAGIC_1311: i64 = 1311 |
| 22 | const K_MAGIC_2048: i64 = 2048 |
| 23 | const K_MAGIC_9830: i64 = 9830 |
| 24 | const K_MAGIC_2000: i64 = 2000 |
| 25 | const K_MAGIC_8192: i64 = 8192 |
| 26 | const K_MAGIC_13107: i64 = 13107 |
| 27 | const K_MAGIC_26214: i64 = 26214 |
| 28 | const K_MAGIC_39321: i64 = 39321 |
| 29 | const K_MAGIC_52429: i64 = 52429 |
| 30 | const K_MAGIC_32768: i64 = 32768 |
| 31 | const K_MAGIC_16384: i64 = 16384 |
| 32 | const K_MAGIC_4096: i64 = 4096 |
| 34 | const RLOG: *u8 = "knowledge/status/ng_radiance.log" |
| 35 | const Q16: i64 = 65536 |
| 36 | const NC: i64 = 4 // sample coords along the field |
| 37 | const NH: i64 = 8 // hidden units |
| 38 | const NR: i64 = 4 // volume-rendered observations (invertible weight matrix -> field recoverable) |
| 39 | const EPOCHS: i64 = 6000 |
| 40 | const LRQ: i64 = 2048 // 1/32 |
functions
| 42 | func rp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 47 | func rpn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 48 | func r_abs(v: i64) -> i64 { if v<0 { return 0-v } return v } called by 1: main |
| 49 | func rl_ws(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } |
| 54 | func rl_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } |
| 58 | func rad_build(tape: *i64, vals: *i64, st: *i64, W1p: *i64, b1p: *i64, W2p: *i64, b2p: *i64, |
| 95 | func rad_init(W1p: *i64, b1p: *i64, W2p: *i64, b2p: *i64) -> i64 called by 1: rad_train |
| 108 | func rad_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, coords: *i64, wmat: *i64, targ: *i64, |
| 138 | func main() -> i64 |