code wiki / _hdl_build / nx_ng_volrender.nx
nx_ng_volrender.nx
buildroot/runtime/_hdl_build/nx_ng_volrender.nx
about
nx_ng_volrender.nx -- CAP-VOLUME-RENDER, generation 7 on the neural-graphics ladder (nx_ng_gap named it
the next missing generation after CAP-DIFF-RENDER). The volumetric ALPHA-OVER compositing operator that is
the actual render op of NeRF (after the density->alpha map) AND the core of 3D Gaussian Splatting:
T_0 = 1 ; C = sum_i T_i * alpha_i * c_i ; T_{i+1} = T_i * (1 - alpha_i)
i.e. front-to-back "over" compositing along a ray. Q16 fixed-point, no float, sovereign syscalls only.
Honest gated proof (HARD evidence per the genealogy ladder):
T1 FORWARD correctness -- opaque front occludes the rest (C==c0); all-transparent shows background (C==0);
half-opaque samples composite to the hand-checked weighted sum (transmittance chain is right).
T2 DIFFERENTIABLE -- the per-sample compositing weight w_i = T_i*alpha_i IS dC/dc_i; GD on the sample
colors drives the composited C -> a target C*, loss -> ~0 (gradients flow through the render).
T3 NEG-CONTROL -- ascending that gradient DIVERGES (the gradient has correct direction/teeth).
T4 GRADCHECK -- sign(analytic dLoss/dc0) == sign(L(c0+e)-L(c0-e)).
NOTE: the NeRF density form alpha=1-exp(-sigma*delta) is a thin wrapper over this (exp helper already in
nx_nofloat_autograd); the alpha/sigma gradient is the follow-on rung. license_tier: ORIGINAL expect_exit: 0
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
| 17 | const K_MAGIC_13107: i64 = 13107 |
| 18 | const K_MAGIC_26214: i64 = 26214 |
| 19 | const K_MAGIC_39321: i64 = 39321 |
| 20 | const K_MAGIC_52429: i64 = 52429 |
| 21 | const K_MAGIC_49000: i64 = 49000 |
| 22 | const K_MAGIC_49300: i64 = 49300 |
| 23 | const K_MAGIC_104856: i64 = 104856 |
| 25 | const Q: i64 = 65536 |
| 26 | const H: i64 = 32768 // 0.5 |
| 27 | const NS: i64 = 4 // samples along the ray |
| 28 | const LR: i64 = 65536 // 1.0 (Q16); composite is linear in c -> stable |
| 29 | const NSTEP: i64 = 40 |
| 30 | const NASC: i64 = 6 // neg-control ascent steps (bounded: ascent grows error ~1.66x/step -> avoid i64 overflow) |
| 31 | const CSTAR: i64 = 26214 // target composited color = 0.4 |
| 32 | const EPS: i64 = 655 // finite-diff step = 0.01 |
functions
| 34 | func vp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 35 | func vpn(v: i64) -> i64 |
| 44 | func vqm(a: i64, b: i64) -> i64 { return (a * b) >> 16 } |
| 47 | func vr_forward(alpha: *i64, col: *i64, w: *i64) -> i64 |
| 58 | func vr_loss(C: i64, cstar: i64) -> i64 { let d: i64 = C - cstar; return vqm(d, d) } |
| 60 | func main() -> i64 |