code wiki / (root) / nx_sdfrender.nx

nx_sdfrender.nx

buildroot/runtime/nx_sdfrender.nx

73702 B1296 linesdepth 2pulls 3 transitivereach 77 importersview sourcekind librarytopic sdfrender
docsdependenciesstructsconstsfunctions

about

nx_sdfrender.nx -- sovereign software GPU, SMOOTH-UNION path (operator 2026-07-04: make the body CONTINUOUS, not jointed ellipsoids). Instead of rasterizing separate ellipsoid surfaces, define the body as an IMPLICIT FIELD -- a smooth-minimum (smin) union of ellipsoid SDFs -- and RAY-MARCH it per pixel: the parts BLEND into one continuous surface (arm melts into shoulder, thigh into hip). Per-pixel normal from the SDF gradient -> Phong. ALL INTEGER fx1024 (deterministic, VM-vettable). This is the same technique modern GPUs use for metaball/organic surfaces -- built entirely on our own stack. license_tier: ORIGINAL

dependencies 2 imports · 42 importers

nx_syscalls.nx nx_itrig.nx nx_sdfrender.nx nx_assetvariant.nx nx_assetvariant_gate.nx nx_autorig.nx nx_autorig_gate.nx nx_body_figure.nx nx_body_figure_gate.nx nx_bodypose.nx nx_char_asset.nx nx_char_custom_gate.nx nx_char_layers.nx

diagram shows first 10 each side; +0 more imports, +32 more importers in the complete lists below.

imports: nx_syscalls.nxnx_itrig.nx

imported by: nx_assetvariant.nxnx_assetvariant_gate.nxnx_autorig.nxnx_autorig_gate.nxnx_body_figure.nxnx_body_figure_gate.nxnx_bodypose.nxnx_char_asset.nxnx_char_custom_gate.nxnx_char_layers.nxnx_char_layers_gate.nxnx_creature_motion.nxnx_creature_motion_gate.nxnx_critic_kernel.nxnx_critic_visual.nxnx_face_carve_gate.nxnx_face_r2.nxnx_face_vs_target.nxnx_faceanat.nxnx_gen_orchestrator.nxnx_genloop_gate.nxnx_gltf_export_gate.nxnx_i2mesh_gate.nxnx_makeup.nxnx_makeup_gate.nxnx_meshgen.nxnx_meshgen_gate.nxnx_meshtex.nxnx_motion_photo_gate.nxnx_natstat_optimize.nxnx_obj_export_gate.nxnx_outfit.nxnx_outfit_gate.nxnx_person_face_gate.nxnx_photoreal_critic.nxnx_recombine_novelty_gate.nxnx_render_amp_compare.nxnx_sdfrender_gate.nxnx_sdfrender_mt.nxnx_t2mesh.nxnx_t2mesh_gate.nxnx_variant_mesh_gate.nx

structs

none

consts

9const PARTS_MAGIC_1206: i64 = 1206
10const PARTS_MAGIC_1330: i64 = 1330
11const PARTS_MAGIC_1024: i64 = 1024
12const PARTS_MAGIC_4096: i64 = 4096
13const PARTS_MAGIC_92821: i64 = 92821
14const PARTS_MAGIC_68917: i64 = 68917
15const PARTS_MAGIC_40503: i64 = 40503
16const PARTS_MAGIC_48271: i64 = 48271
17const PARTS_MAGIC_2147483647: i64 = 2147483647
18const PARTS_MAGIC_999999: i64 = 999999
19const PARTS_MAGIC_1048576: i64 = 1048576
20const PARTS_MAGIC_1250: i64 = 1250
21const PARTS_MAGIC_3600: i64 = 3600
22const PARTS_MAGIC_2600: i64 = 2600
23const PARTS_MAGIC_262144: i64 = 262144
24const PARTS_MAGIC_9000: i64 = 9000
25const PARTS_MAGIC_1445: i64 = 1445
26const PARTS_MAGIC_3400: i64 = 3400
27const PARTS_MAGIC_4200: i64 = 4200
28const PARTS_MAGIC_65536: i64 = 65536
29const PARTS_MAGIC_8201: i64 = 8201
30const PARTS_MAGIC_8192: i64 = 8192
31const PARTS_MAGIC_8183: i64 = 8183
32const PARTS_MAGIC_2026: i64 = 2026
33const PARTS_MAGIC_2048: i64 = 2048
35const W: i64 = 512
36const H: i64 = 384
37const HW: i64 = 256
38const HH: i64 = 192
39const FX: i64 = 1024 // fixed-point unit (1.0)
40const FOCAL: i64 = 586 // ray focal (fx1024 ndc scale) -- scaled with width to keep the FOV
41const KBLEND: i64 = 130 // smin blend radius: joints fuse smoothly but limbs stay DISTINCT (340 melted the whole figure into a blob)
42const NPART: i64 = 18
43const PARTS_CAP: i64 = 48 // physical part-array capacity (room for a carved face; side slots moved out)
44const O_FB: i64 = 0
45const O_PARTS: i64 = 1572864 // W*H*8 ; up to PARTS_CAP*6 i64 {cx,cy,cz,rx,ry,rz}
46const O_KBLEND: i64 = 1575168 // = O_PARTS + PARTS_CAP*6*8 ; per-body smin blend; 0 => default KBLEND
47const O_NPART: i64 = 1575176 // active part count (t2mesh objects vary); 0 => default NPART
48const O_OPS: i64 = 1575184 // PARTS_CAP i64: per-part op -- 0=union(add), 1=carve(smooth-subtract)
49const O_MATS: i64 = 1575568 // PARTS_CAP i64: per-part MATERIAL -- 0=skin(default), 1=EYE (sclera/iris/pupil)
50const O_KB2: i64 = 1575952 // PARTS_CAP i64: PER-PART smin blend radius; 0 = inherit the body default.
53const O_ROT: i64 = 1576336 // PARTS_CAP * 2 i64: per-part PITCH orientation (cos256, sin256); 0,0 =
56const O_FLOOR: i64 = 1577104 // 1 i64 (in the O_ROT slack): 1 = render a GROUND PLANE (figures only)
57const O_MTXAMP: i64 = 1577112 // 1 i64: micro-texture amplitude scale (256 = 1.0x) -- the reverse-judge knob
63const O_FTEX: i64 = 1577120 // *u8 RGB8 rows (w*h*3); 0 = OFF
64const O_FTEXW: i64 = 1577128
65const O_FTEXH: i64 = 1577136
66const O_FPUC: i64 = 1577144
67const O_FPVC: i64 = 1577152
68const O_FPSU: i64 = 1577160
69const O_FPSV: i64 = 1577168
70const O_FPVLO: i64 = 1577176 // photo-v projection BAND [vlo,vhi): reference-specific (hairline..chin);
71const O_FPVHI: i64 = 1577184 // vhi<=0 -> full [1,th-2). Photo-space, so transform-invariant (person path).
75const O_EYE: i64 = 1577192 // 1 i64: lateral eye offset (model units); 0 = centered/mono
397const HS_BOB: i64 = 1 // the sdf_face default cap+nape (explicit id = a no-op, negative-control-provable)
398const HS_LONG: i64 = 2 // deep nape + a back-fall volume down the back
399const HS_PIXIE: i64 = 3 // tight cap hugging the skull, nape tucked short
400const HS_PONY: i64 = 4 // nape tucked + a high tail behind the crown
401const HS_BALD: i64 = 5 // hair parts collapsed inside the skull -> skin scalp renders

functions

76func sdf_set_facetex(base: i64, tex: i64, w: i64, h: i64, uc: i64, vc: i64, su: i64, sv: i64) -> i64
89func sdf_set_facetex_band(base: i64, vlo: i64, vhi: i64) -> i64
99func sdf_set_facetex_person(base: i64, tex: i64, w: i64, h: i64, uc: i64, vc: i64, su: i64, sv: i64) -> i64
called by 2: mainmain calls 1: sdf_set_facetex
105func sdf_bytes() -> i64 { return O_ROT + PARTS_CAP * 2 * 8 + PARTS_MAGIC_4096 }
called by 52: mainmainmainmainmainmain+46
106func sdf_set_floor(base: i64, on: i64) -> i64 { let f: *i64 = (base + O_FLOOR) as *i64; f[0] = on; return 0 }
107func sdf_set_mtx_amp(base: i64, amp: i64) -> i64 { let f: *i64 = (base + O_MTXAMP) as *i64; f[0] = amp; return 0 }
108func sdf_set_eye(base: i64, dx: i64) -> i64 { let f: *i64 = (base + O_EYE) as *i64; f[0] = dx; return 0 }
called by 1: main
109func fb_off() -> i64 { return O_FB }
called by 11: mainmainmainmainmainmain+5
110func ww() -> i64 { return W }
called by 11: mainmainmainmainmainmain+5
111func hh() -> i64 { return H }
called by 12: mainmainmainmainmainmain+6
113func sdf_isqrt(v: i64) -> i64 { if v <= 0 { return 0 } var x: i64 = v; var y: i64 = (x + 1) / 2; while y < x { x = y; y = (x + v / x) / 2 } return x }
114func sdf_min(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 1: sdf_smin
115func sdf_abs(a: i64) -> i64 { if a < 0 { return 0 - a } return a }
117func sdf_knee(v: i64) -> i64 { if v < 0 { return 0 } if v < 205 { return v } let x: i64 = v - 205; var o: i64 = 205 + x * 50 / (x + 85); if o > 255 { o = 255 } return o }
120func sdf_aces(v: i64) -> i64
called by 1: sdf_shade_ray
135func sk_hash(a: i64, b: i64, c: i64) -> i64
142func sk_vnoise(x: i64, y: i64, z: i64, C: i64) -> i64
167func sk_pore(x: i64, y: i64, z: i64) -> i64
called by 1: sdf_shade_ray calls 1: sk_hash
201func mat_height(qx: i64, qy: i64, qz: i64) -> i64
called by 1: sdf_shade_ray calls 1: sk_vnoise
207func sk_microtex(qx: i64, qy: i64, qz: i64) -> i64
called by 1: sdf_shade_ray calls 2: sk_vnoisesk_hash
215func sdf_clear_ops(base: i64, n: i64) -> i64
225func sdf_set_rot(base: i64, idx: i64, deg4096: i64) -> i64
231func sdf_set_op(base: i64, idx: i64, v: i64) -> i64 { let op: *i64 = (base + O_OPS) as *i64; op[idx] = v; return 0 }
232func sdf_set_mat(base: i64, idx: i64, v: i64) -> i64 { let mt: *i64 = (base + O_MATS) as *i64; mt[idx] = v; return 0 }
233func sdf_set_kb(base: i64, idx: i64, v: i64) -> i64 { let k2: *i64 = (base + O_KB2) as *i64; k2[idx] = v; return 0 }
237func sdf_body(base: i64) -> i64
288func sdf_head(base: i64) -> i64
called by 2: mainmain calls 1: sdf_clear_ops
319func sdf_face(base: i64) -> i64
402func sdf_face_hairstyle(base: i64, hs: i64) -> i64
457func sdf_person2(base: i64, scratch: i64, hs: i64) -> i64
498func sdf_person(base: i64, scratch: i64) -> i64 { return sdf_person2(base, scratch, 0) }
called by 3: mainmainmain calls 1: sdf_person2
503func sdf_person_full(base: i64, scratch: i64, hs: i64) -> i64
544func sdf_shift_y(base: i64, dy: i64) -> i64
called by 2: mainmain
556func sdf_ellip(px: i64, py: i64, pz: i64, cx: i64, cy: i64, cz: i64, rx: i64, ry: i64, rz: i64) -> i64
called by 2: sdf_evalsdf_eval_part calls 1: sdf_isqrt
568func sdf_ellip_rot(px: i64, py: i64, pz: i64, cx: i64, cy: i64, cz: i64, rx: i64, ry: i64, rz: i64, rc: i64, rs: i64) -> i64
called by 1: sdf_eval calls 1: sdf_isqrt
583func sdf_smin(a: i64, b: i64, k: i64) -> i64
called by 2: sdf_smaxsdf_eval calls 2: sdf_abssdf_min
589func sdf_smax(a: i64, b: i64, k: i64) -> i64 { return 0 - sdf_smin(0 - a, 0 - b, k) }
called by 1: sdf_eval calls 1: sdf_smin
591func sdf_eval(base: i64, px: i64, py: i64, pz: i64) -> i64
626func sdf_eval_part(base: i64, px: i64, py: i64, pz: i64) -> i64
called by 1: sdf_shade_ray calls 1: sdf_ellip
648func sdf_softshadow(base: i64, ox: i64, oy: i64, oz: i64, lx: i64, ly: i64, lz: i64) -> i64
called by 1: sdf_shade_ray calls 1: sdf_eval
671func sdf_ao(base: i64, ox: i64, oy: i64, oz: i64, nx: i64, ny: i64, nz: i64) -> i64
called by 1: sdf_shade_ray calls 1: sdf_eval
697func sdf_gi(base: i64, px: i64, py: i64, pz: i64, nx: i64, ny: i64, nz: i64) -> i64
757func sdf_shade_ray(base: i64, rox: i64, roy: i64, roz: i64, rdx: i64, rdy: i64, rdz: i64, skin_r: i64, skin_g: i64, skin_b: i64, misscol: i64) -> i64
1241func sdf_render_rows(base: i64, yaw: i64, camz_units: i64, skin_r: i64, skin_g: i64, skin_b: i64, y0: i64, y1: i64) -> i64
1294func sdf_render(base: i64, yaw: i64, camz_units: i64, skin_r: i64, skin_g: i64, skin_b: i64) -> i64
called by 14: mainmainmainmainmainmain+8 calls 1: sdf_render_rows