code wiki / (root) / nx_sdfrender.nx

nx_sdfrender.nx

buildroot/runtime/nx_sdfrender.nx

109622 B1821 linesdepth 3pulls 5 transitivereach 120 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 4 imports · 63 importers

nx_syscalls.nx nx_itrig.nx nx_vecmath.nx nx_relief_lib.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_asset_material_candidate_t nx_char_custom_gate.nx

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

imports: nx_syscalls.nxnx_itrig.nxnx_vecmath.nxnx_relief_lib.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_asset_material_candidate_t340.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_feature_diag_t367.nxnx_face_feature_diag_t368.nxnx_face_feature_gate_t367.nxnx_face_feature_gate_t367r1.nxnx_face_feature_gate_t367r2.nxnx_face_feature_gate_t367r3.nxnx_face_feature_gate_t367r4.nxnx_face_feature_gate_t367r5.nxnx_face_r2.nxnx_face_vs_target.nxnx_faceanat.nxnx_gen_content.nxnx_gen_orchestrator.nxnx_gen_unified.nxnx_genloop_gate.nxnx_gltf_export_gate.nxnx_i2mesh_gate.nxnx_makeup.nxnx_makeup_gate.nxnx_meshgen.nxnx_meshgen_cell_audit_t337.nxnx_meshgen_connected_audit_t335.nxnx_meshgen_connected_locations_t335.nxnx_meshgen_domain_candidate_t337.nxnx_meshgen_domain_gate_t337.nxnx_meshgen_domain_locations_t337.nxnx_meshgen_gate.nxnx_meshgen_orientation_candidate_t336.nxnx_meshgen_orientation_gate_t336.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_sdf_attribution_gate_t344.nxnx_sdfrender_gate.nxnx_sdfrender_mt.nxnx_sdfrender_sss_gate.nxnx_t2mesh.nxnx_t2mesh_gate.nxnx_variant_mesh_gate.nx

structs

none

consts

11const PARTS_MAGIC_1206: i64 = 1206
12const PARTS_MAGIC_1330: i64 = 1330
13const PARTS_MAGIC_1024: i64 = 1024
18const SK_HASH_BIAS: i64 = 8192
24const PARTS_MAGIC_92821: i64 = 92821
25const PARTS_MAGIC_68917: i64 = 68917
26const PARTS_MAGIC_40503: i64 = 40503
34const MINSTD_MULT: i64 = 48271
35const MINSTD_MOD: i64 = 2147483647
36const PARTS_MAGIC_999999: i64 = 999999
37const PARTS_MAGIC_1048576: i64 = 1048576
38const PARTS_MAGIC_1250: i64 = 1250
39const PARTS_MAGIC_3600: i64 = 3600
40const PARTS_MAGIC_2600: i64 = 2600
41const PARTS_MAGIC_262144: i64 = 262144
42const PARTS_MAGIC_9000: i64 = 9000
43const PARTS_MAGIC_1445: i64 = 1445
44const PARTS_MAGIC_3400: i64 = 3400
45const PARTS_MAGIC_4200: i64 = 4200
46const PARTS_MAGIC_65536: i64 = 65536
47const PARTS_MAGIC_8201: i64 = 8201
48const PARTS_MAGIC_2048: i64 = 2048
50const W: i64 = 512
51const H: i64 = 384
52const HW: i64 = 256
53const HH: i64 = 192
54const FX: i64 = 1024 // fixed-point unit (1.0)
55const FOCAL: i64 = 586 // ray focal (fx1024 ndc scale) -- scaled with width to keep the FOV
56const KBLEND: i64 = 130 // smin blend radius: joints fuse smoothly but limbs stay DISTINCT (340 melted the whole figure into a blob)
57const NPART: i64 = 18
58const PARTS_CAP: i64 = 48 // physical part-array capacity (room for a carved face; side slots moved out)
76const SDF_I64: i64 = 8
77const SDF_FB_BYTES: i64 = W * H * SDF_I64 // the framebuffer IS the first field; its size is not a guess
78const SDF_PART_FIELDS: i64 = 6 // {cx,cy,cz,rx,ry,rz}
79const SDF_ROT_FIELDS: i64 = 2 // {cos256, sin256}
80const O_FB: i64 = 0
81const O_PARTS: i64 = O_FB + SDF_FB_BYTES // W*H*8 ; up to PARTS_CAP*6 i64 {cx,cy,cz,rx,ry,rz}
82const O_KBLEND: i64 = O_PARTS + PARTS_CAP * SDF_PART_FIELDS * SDF_I64 // per-body smin blend; 0 => default KBLEND
83const O_NPART: i64 = O_KBLEND + SDF_I64 // active part count (t2mesh objects vary); 0 => default NPART
84const O_OPS: i64 = O_NPART + SDF_I64 // PARTS_CAP i64: per-part op -- 0=union(add), 1=carve(smooth-subtract)
85const O_MATS: i64 = O_OPS + PARTS_CAP * SDF_I64 // PARTS_CAP i64: per-part MATERIAL -- 0=skin, 1=EYE
86const O_KB2: i64 = O_MATS + PARTS_CAP * SDF_I64 // PARTS_CAP i64: PER-PART smin blend radius; 0 = inherit.
89const O_ROT: i64 = O_KB2 + PARTS_CAP * SDF_I64 // PARTS_CAP*2 i64: per-part PITCH orientation (cos256, sin256); 0,0 =
92const O_FLOOR: i64 = O_ROT + PARTS_CAP * SDF_ROT_FIELDS * SDF_I64 // 1 i64: 1 = render a GROUND PLANE (figures only)
93const O_MTXAMP: i64 = O_FLOOR + SDF_I64 // 1 i64: micro-texture amplitude scale (256 = 1.0x) -- the reverse-judge knob
99const O_FTEX: i64 = O_MTXAMP + SDF_I64 // *u8 RGB8 rows (w*h*3); 0 = OFF
100const O_FTEXW: i64 = O_FTEX + SDF_I64
101const O_FTEXH: i64 = O_FTEXW + SDF_I64
102const O_FPUC: i64 = O_FTEXH + SDF_I64
103const O_FPVC: i64 = O_FPUC + SDF_I64
104const O_FPSU: i64 = O_FPVC + SDF_I64
105const O_FPSV: i64 = O_FPSU + SDF_I64
106const O_FPVLO: i64 = O_FPSV + SDF_I64 // photo-v projection BAND [vlo,vhi): reference-specific (hairline..chin);
107const O_FPVHI: i64 = O_FPVLO + SDF_I64 // vhi<=0 -> full [1,th-2). Photo-space, so transform-invariant (person path).
111const O_EYE: i64 = O_FPVHI + SDF_I64 // 1 i64: lateral eye offset (model units); 0 = centered/mono
118const O_ROLL: i64 = O_EYE + SDF_I64 // PARTS_CAP*2 i64: per-part ROLL orientation (cos256, sin256)
132const SDF_PRIM_FIELDS: i64 = 6
133const SDF_PR_HALFW: i64 = 0 // half the fissure width: the canthi sit at (-halfw, 0) and (+halfw, 0) before roll
134const SDF_PR_UP: i64 = 1 // rise of the upper lid arc above the canthal line
135const SDF_PR_LOW: i64 = 2 // drop of the lower lid arc below it
136const O_PRIM: i64 = O_ROLL + PARTS_CAP * SDF_ROT_FIELDS * SDF_I64 // PARTS_CAP*6 i64: per-part primitive parameters
137const SDF_ARENA_BYTES: i64 = O_PRIM + PARTS_CAP * SDF_PRIM_FIELDS * SDF_I64
138const SDF_OP_UNION: i64 = 0
139const SDF_OP_CARVE: i64 = 1
140const SDF_OP_LIDSHELL: i64 = 2
473const HS_BOB: i64 = 1 // the sdf_face default cap+nape (explicit id = a no-op, negative-control-provable)
474const HS_LONG: i64 = 2 // deep nape + a back-fall volume down the back
475const HS_PIXIE: i64 = 3 // tight cap hugging the skull, nape tucked short
476const HS_PONY: i64 = 4 // nape tucked + a high tail behind the crown
477const HS_BALD: i64 = 5 // hair parts collapsed inside the skull -> skin scalp renders
739const SDF_OP_LIPSWEEP: i64 = 3
740const SDF_PL_ARCH: i64 = 0 // how far back (+z) the commissure sits from the midline
741const SDF_PL_TAPER: i64 = 1 // commissure thickness, permil of the midline thickness
742const SDF_PL_NOTCH: i64 = 2 // cupid's bow: the dip of the upper outline at the midline, permil of this lip's height (0 on a lower lip)
743const SDF_PL_NOTCH_HW: i64 = 3 // half-width of that dip, permil of the half mouth width
744const SDF_PL_CURVE: i64 = 4 // rise (+) or drop (-) of the seam at the commissure
745const SDF_PL_SIDE: i64 = 5 // +1 = the half above the seam (upper lip), -1 = the half below
746const SDF_PERMIL: i64 = 1000
747const SDF_LIP_EDGE: i64 = 6 // the vermilion's colour edge fades over this many model units
748const SDF_LIP_FULL: i64 = 100
901const SDF_LASH_BAND: i64 = 7
955const SDF_AT_PART:i64=0
956const SDF_AT_MATERIAL:i64=1
957const SDF_AT_NEAREST:i64=2
958const SDF_AT_RUNNER:i64=3
959const SDF_AT_FIELD:i64=4
960const SDF_AT_COMPOSED:i64=5
961const SDF_AT_TIED:i64=6
962const SDF_AT_RUNNER_PART:i64=7
963const SDF_AT_WORDS:i64=8
1111const SSS_WRAP_R0: i64 = 120 // flat-surface wrap width, red (the proven terminator floor)
1112const SSS_WRAP_G0: i64 = 60
1113const SSS_WRAP_B0: i64 = 26
1114const SSS_CURV_GAIN_R: i64 = 96 // widening per unit curvature (curv 0..256), red widest
1115const SSS_CURV_GAIN_G: i64 = 40
1116const SSS_CURV_GAIN_B: i64 = 12
1117const SSS_CURV_MAX: i64 = 256
1118const SSS_CURV_SCALE: i64 = 24 // Laplacian sum (SDF units) -> 0..256 curvature; sized so a 1-block
1195const SSS_N_FULL: i64 = 256 // this renderer's unit-normal / N.L scale
1243const SR_RELIEF_E: i64 = 9 // the shader's OWN central-difference half-step. It was spelled as the

functions

141func sdf_set_facetex(base: i64, tex: i64, w: i64, h: i64, uc: i64, vc: i64, su: i64, sv: i64) -> i64
154func sdf_set_facetex_band(base: i64, vlo: i64, vhi: i64) -> i64
164func sdf_set_facetex_person(base: i64, tex: i64, w: i64, h: i64, uc: i64, vc: i64, su: i64, sv: i64) -> i64
calls 1: sdf_set_facetex
170func sdf_bytes() -> i64 { return SDF_ARENA_BYTES }
called by 45: mainmainmainmainmainmain+39
171func sdf_set_floor(base: i64, on: i64) -> i64 { let f: *i64 = (base + O_FLOOR) as *i64; f[0] = on; return 0 }
172func sdf_set_mtx_amp(base: i64, amp: i64) -> i64 { let f: *i64 = (base + O_MTXAMP) as *i64; f[0] = amp; return 0 }
173func sdf_set_eye(base: i64, dx: i64) -> i64 { let f: *i64 = (base + O_EYE) as *i64; f[0] = dx; return 0 }
174func fb_off() -> i64 { return O_FB }
175func ww() -> i64 { return W }
called by 11: mainmainmainmainmainmain+5
176func hh() -> i64 { return H }
called by 12: mainmainmainmainmainmain+6
178func sdf_isqrt(v: i64) -> i64 { return vm_isqrt(v) }
179func sdf_min(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 1: sdf_smin
180func sdf_abs(a: i64) -> i64 { if a < 0 { return 0 - a } return a }
182func 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 }
185func sdf_aces(v: i64) -> i64
called by 1: sdf_shade_ray
200func sk_hash(a: i64, b: i64, c: i64) -> i64
207func sk_vnoise(x: i64, y: i64, z: i64, C: i64) -> i64
232func sk_pore(x: i64, y: i64, z: i64) -> i64
called by 1: sdf_shade_ray calls 1: sk_hash
266func mat_height(qx: i64, qy: i64, qz: i64) -> i64
called by 1: sg_proc_tilt_max calls 1: sk_vnoise
272func sk_microtex(qx: i64, qy: i64, qz: i64) -> i64
called by 1: sdf_shade_ray calls 2: sk_vnoisesk_hash
280func sdf_clear_ops(base: i64, n: i64) -> i64
301func sdf_set_rot(base: i64, idx: i64, deg4096: i64) -> i64
307func sdf_set_op(base: i64, idx: i64, v: i64) -> i64 { let op: *i64 = (base + O_OPS) as *i64; op[idx] = v; return 0 }
308func sdf_set_mat(base: i64, idx: i64, v: i64) -> i64 { let mt: *i64 = (base + O_MATS) as *i64; mt[idx] = v; return 0 }
309func sdf_set_kb(base: i64, idx: i64, v: i64) -> i64 { let k2: *i64 = (base + O_KB2) as *i64; k2[idx] = v; return 0 }
313func sdf_body(base: i64) -> i64
364func sdf_head(base: i64) -> i64
called by 2: mainmain calls 1: sdf_clear_ops
395func sdf_face(base: i64) -> i64
478func sdf_face_hairstyle(base: i64, hs: i64) -> i64
533func sdf_person2(base: i64, scratch: i64, hs: i64) -> i64
574func sdf_person(base: i64, scratch: i64) -> i64 { return sdf_person2(base, scratch, 0) }
called by 1: main calls 1: sdf_person2
579func sdf_person_full(base: i64, scratch: i64, hs: i64) -> i64
620func sdf_shift_y(base: i64, dy: i64) -> i64
called by 1: main
636func sdf_ellip(px: i64, py: i64, pz: i64, cx: i64, cy: i64, cz: i64, rx: i64, ry: i64, rz: i64) -> i64
654func 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
675func sdf_smin(a: i64, b: i64, k: i64) -> i64
681func sdf_smax(a: i64, b: i64, k: i64) -> i64 { return 0 - sdf_smin(0 - a, 0 - b, k) }
called by 2: reference_evalsdf_eval calls 1: sdf_smin
684func sdf_set_roll(base: i64, idx: i64, deg4096: i64) -> i64
690func sdf_set_prim(base: i64, idx: i64, field: i64, v: i64) -> i64 { let pr: *i64 = (base + O_PRIM) as *i64; pr[idx * SDF_PRIM_FIELDS + field] = v; return 0 }
691func sdf_get_prim(base: i64, idx: i64, field: i64) -> i64 { let pr: *i64 = (base + O_PRIM) as *i64; return pr[idx * SDF_PRIM_FIELDS + field] }
697func sdf_lidshell(px: i64, py: i64, pz: i64, cx: i64, cy: i64, cz: i64, rin: i64, t: i64, cap: i64, halfw: i64, up: i64, low: i64, rc: i64, rs: i64) -> i64
750func sdf_lip_t(px: i64, cx: i64, halfw: i64) -> i64
758func sdf_lip_f(taper: i64, t: i64) -> i64
764func sdf_lip_h(hh: i64, taper: i64, notch: i64, notch_hw: i64, side: i64, t: i64) -> i64
774func sdf_lipsweep(px: i64, py: i64, pz: i64, cx: i64, cy: i64, cz: i64, halfw: i64, hh: i64, dd: i64, arch: i64, taper: i64, notch: i64, notch_hw: i64, curve: i64, side: i64) -> i64
802func sdf_lipsweep_part(base: i64, i: i64, px: i64, py: i64, pz: i64) -> i64
809func sdf_lip_vermilion(base: i64, px: i64, py: i64, pz: i64) -> i64
853func sdf_part_distance(base:i64,i:i64,px:i64,py:i64,pz:i64)->i64
870func sdf_eval(base: i64, px: i64, py: i64, pz: i64) -> i64
902func sdf_lid_lash(base: i64, idx: i64, px: i64, py: i64) -> i64
936func sdf_eval_part(base:i64,px:i64,py:i64,pz:i64)->i64
called by 2: mainsdf_shade_ray calls 1: sdf_part_distance
949func sdf_surface_material(base:i64,part:i64,px:i64,py:i64)->i64
967func sdf_part_attribution(base:i64,px:i64,py:i64,pz:i64,out:*i64,words:i64)->i64
988func 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
1011func 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
1037func sdf_gi(base: i64, px: i64, py: i64, pz: i64, nx: i64, ny: i64, nz: i64) -> i64
1127func sr_sss_preint_n(ndlr: i64, ndlg: i64, ndlb: i64, curv: i64) -> i64
1145func sr_sss_preint(ndl: i64, curv: i64) -> i64 { return sr_sss_preint_n(ndl, ndl, ndl, curv) }
1148func sr_curvature(base: i64, px: i64, py: i64, pz: i64, e: i64, f0: i64) -> i64
called by 1: sdf_shade_ray calls 1: sdf_eval
1198func sr_relief_wrap() -> i64 { return rlf_tilt_full(SSS_N_FULL) }
1200func sr_sss_blur(w: i64) -> i64 { return w * SSS_N_FULL / (w + sr_relief_wrap()) }
1206func sr_sss_ndl(nd: i64, gd: i64, blur: i64) -> i64 { return nd + (gd - nd) * blur / SSS_N_FULL }
1246func sr_relief_cell() -> i64 { return 2 * SR_RELIEF_E }
called by 2: sr_relief_hmain
1248func sr_relief_h(qx: i64, qy: i64, qz: i64) -> i64 { return rlf_relief_h3(qx, qy, qz, sr_relief_cell()) }
1251func sr_relief_tilt(dh: i64) -> i64 { return dh * rlf_tilt_full(SSS_N_FULL) / RLF_H_RANGE }
called by 2: sr_relief_gradmain calls 1: rlf_tilt_full
1254func sr_relief_grad(px: i64, py: i64, pz: i64, ax: i64) -> i64
1261func 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
1766func sdf_render_rows(base: i64, yaw: i64, camz_units: i64, skin_r: i64, skin_g: i64, skin_b: i64, y0: i64, y1: i64) -> i64
1819func sdf_render(base: i64, yaw: i64, camz_units: i64, skin_r: i64, skin_g: i64, skin_b: i64) -> i64