nx_nxa_texbake_region_lib.nx
buildroot/runtime/nx_nxa_texbake_region_lib.nx
about
nx_nxa_texbake_region_lib.nx -- PER-REGION SKIN ATLAS + PERIODIC MICRO-RELIEF TILE, written INTO the
asset as a TEXR section (2026-08-30, /compare/graphics GR29 gpe_skin_microsurface -- the ASSET half).
THE OPERATOR'S BAR, VERBATIM: "for per region we need texture ... make sure we aren't just doing more
smooth surface painting." So this organ bakes RELIEF -- a 16-bit height channel in MICRONS and a normal
DERIVED from that height by finite differences -- and it MEASURES, per region, what the chart footprint
can actually carry before it prints carried=1 for anything.
WHAT WAS MEASURED BEFORE A BYTE WAS BAKED. The estate's adequacy ruler (nx_craft_emit cw_atlas_adequate)
is span-based: texel = 1.7m / res, 830um at the shipped 2048. But TEXC (nx_nxa_texc_lib) is a per-JOINT
cylindrical unwrap: each bone owns one tile of a g x g grid, u runs the FULL circumference, v the bone
length. The physical footprint of a texel is therefore (bone circumference / tile px) on u, and a chest
bone's circumference is a metre. The `measure` verb below solves the UV->3D Jacobian on every triangle
and reports, per region, the area-weighted footprint and the FRACTION OF SURFACE AREA that carries each
band -- the honest number. A per-region UNIQUE atlas at 2048 raises the tile px by ~g/gR and carries
the primary band on more of the body; it CANNOT carry the 250um secondary band around a torso at any
resolution this estate ships. That is arithmetic, and it is why the three finer bands ride a PERIODIC
MICRO TILE (nx_relief_lib rlf_relief_um2_tile): a texel pitch that is physical by construction (two per
pore orifice), repeated by the shader per chart at (chart extent / tile repeat) using the per-joint
circumference and length this section publishes. This is the field's practice for exactly this case:
Epic's skin guidance keeps wrinkles in the unique normal and puts pore detail in a tiling texture
[@ue-skin], MetaHuman carries a separate Micro Skin Detail normal layer [@mh-materials], the scan vendors
ship the micro band as its own displacement channel [@txyz-vface], Disney's procedural micro-wrinkle
synthesis places pores first and grows the furrow graph between them [@disney23], and Nagano et al.
measured that microstructure is a DISPLACEMENT that smooths under stretch and roughens under compression
[@nagano15] -- the next contract this file names (ntr_tension_attenuate) and does not fake.
THE AREOLA IS ANATOMY, NOT A DISC. The torso region's albedo and height carry the nipple-areola complex
at the MESH-DERIVED bust apex (nx_nxa_dyna's lateral anchors, then the most anterior vertex near each):
nipple radius and projection from published anthropometry and the areola from the published 1:3
nipple-to-areola ratio [@nac-review21], the areola darker than the surrounding skin by a lightness step
DERIVED from the estate's own referee band against a published breast-skin tone [@nac-tattoo24],
Montgomery glands as a discrete dome field. Every one of those numbers is a ROW in
knowledge/areola_relief.conf with its source; this organ READS them (nx_lane_conf, the shared getter)
and REFUSES to bake anatomy when a row is missing -- an unsourced default is the magic number rule 11
forbids. The registry row nx_anatomy an_add(AF_MONTGOMERY ...) is the vocabulary; the ledger is the
provenance.
TEXR PAYLOAD (i64 words). ADDITIVE: TEXM (map set 0) is carried byte-for-byte, never touched -- the
shipped page reads TEXM's blob at a hard-coded +144, so growing TEXM would break the live sampler.
dependencies 9 imports · 11 importers
diagram shows first 10 each side; +0 more imports, +1 more importers in the complete lists below.
imports: nx_syscalls.nxnx_nxa.nxnx_nxa_texc_lib.nxnx_nxa_texbake_lib.nxnx_relief_lib.nxnx_png.nxnx_skin_ita.nxnx_lane_conf.nxnx_fsops_lib.nx
imported by: nx_normal_decode_gate_t279.nxnx_nxa_texbake_region.nxnx_nxa_texbake_region_gate.nxnx_region_capacity_gate_t278.nxnx_region_edge_audit_t278.nxnx_region_edge_compare_t278.nxnx_region_edge_gate_t278.nxnx_texr_boundary_gate_t285.nxnx_texr_chart_candidate_t279.nxnx_texr_descriptor_t279.nxnx_texr_images_gate_t278.nx
structs
| none |
consts
| 61 | const NTR_HDR_WORDS: i64 = 16 |
| 62 | const NTR_JOINT_WORDS: i64 = 4 |
| 63 | const NTR_SET_META: i64 = 16 |
| 64 | const NTR_NMAPS: i64 = 5 |
| 65 | const NTR_MAPREC: i64 = 3 |
| 66 | const NTR_VERSION: i64 = 1 |
| 67 | const NTR_REGIONS: i64 = 4 |
| 68 | const NTR_MAP_ALBEDO: i64 = 0 |
| 69 | const NTR_MAP_DISP: i64 = 1 |
| 70 | const NTR_MAP_NORMAL: i64 = 2 |
| 71 | const NTR_MAP_TDISP: i64 = 3 |
| 72 | const NTR_MAP_TNORMAL: i64 = 4 |
| 74 | const NTR_W_NSETS: i64 = 0 |
| 75 | const NTR_W_RES: i64 = 1 |
| 76 | const NTR_W_MODEL: i64 = 2 |
| 77 | const NTR_W_SEED: i64 = 3 |
| 78 | const NTR_W_HUE: i64 = 4 |
| 79 | const NTR_W_BLOBW: i64 = 5 |
| 80 | const NTR_W_NMAPS: i64 = 6 |
| 81 | const NTR_W_MPX: i64 = 7 |
| 82 | const NTR_W_MREP: i64 = 8 |
| 83 | const NTR_W_RANGE: i64 = 9 |
| 84 | const NTR_W_NJ: i64 = 10 |
| 85 | const NTR_W_SETW: i64 = 11 |
| 86 | const NTR_W_JW: i64 = 12 |
| 87 | const NTR_W_VER: i64 = 13 |
| 89 | const NTR_S_REGION: i64 = 0 |
| 90 | const NTR_S_GR: i64 = 1 |
| 91 | const NTR_S_NJR: i64 = 2 |
| 92 | const NTR_S_TPX: i64 = 3 |
| 93 | const NTR_S_FMEAN: i64 = 4 |
| 94 | const NTR_S_FWORST: i64 = 5 |
| 95 | const NTR_S_BANDS_U: i64 = 6 |
| 96 | const NTR_S_BANDS_M: i64 = 7 |
| 97 | const NTR_S_PERIOD: i64 = 8 |
| 98 | const NTR_S_ALX: i64 = 9 |
| 99 | const NTR_S_ALY: i64 = 10 |
| 100 | const NTR_S_ARX: i64 = 11 |
| 101 | const NTR_S_ARY: i64 = 12 |
| 102 | const NTR_S_ARPX: i64 = 13 |
| 103 | const NTR_S_DL: i64 = 14 |
| 104 | const NTR_S_CARRIED: i64 = 15 |
| 106 | const NTR_MODEL_SPECGLOSS: i64 = 1 |
| 111 | const NTR_DISP_RANGE_UM: i64 = 16384 |
| 112 | const NTR_Q16: i64 = 65536 |
| 113 | const NTR_U16_HALF: i64 = 32768 |
| 114 | const NTR_U16_MAX: i64 = 65535 |
| 115 | const NTR_BYTE: i64 = 256 |
| 116 | const NTR_BYTE_MAX: i64 = 255 |
| 117 | const NTR_RGB: i64 = 3 |
| 118 | const NTR_WORD: i64 = 8 |
| 119 | const NTR_SUB: i64 = 16 // rasterizer sub-pixel scale |
| 120 | const NTR_PI_E3: i64 = 3142 |
| 121 | const NTR_E3: i64 = 1000 |
| 122 | const NTR_E6: i64 = 1000000 |
| 123 | const NTR_MISS: i64 = 0 - 1 |
| 125 | const NTR_TEXELS_PER_BAND: i64 = 2 |
| 127 | const NTR_NGON: i64 = 16 |
| 129 | const NTR_CTL_RELIEF: i64 = 1 // unique-atlas micro-relief bands |
| 130 | const NTR_CTL_ANATOMY: i64 = 2 // nipple dome + Montgomery glands in the height channel |
| 131 | const NTR_CTL_PIGMENT: i64 = 4 // areola lightness step in the albedo |
| 132 | const NTR_CTL_MICRO: i64 = 8 // micro tile carries secondary+pore (else primary only = smooth control) |
| 133 | const NTR_CTL_SETS: i64 = 16 // write the region sets at all (0 = nsets 0, the adequacy neg-control) |
| 134 | const NTR_CTL_ALL: i64 = 31 |
| 135 | const NTR_CTL_ONLY_TORSO: i64 = 32 // bake only the torso set (the gate's 2048 probe run); NOT in ALL |
| 137 | const NTR_OK: i64 = 0 |
| 138 | const NTR_E_IO: i64 = 1 |
| 139 | const NTR_E_BAD: i64 = 3 |
| 140 | const NTR_E_NOSEC: i64 = 4 |
| 141 | const NTR_E_MISMATCH: i64 = 5 |
| 142 | const NTR_E_CONF: i64 = 6 |
| 144 | const NTR_CONF_REL: *u8 = "knowledge/areola_relief.conf" |
| 145 | const NTR_CONF_ABS: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/areola_relief.conf" |
| 147 | const NTR_AN_RA: i64 = 0 |
| 148 | const NTR_AN_RN: i64 = 1 |
| 149 | const NTR_AN_HN: i64 = 2 |
| 150 | const NTR_AN_DL: i64 = 3 |
| 151 | const NTR_AN_NMONT: i64 = 4 |
| 152 | const NTR_AN_RG: i64 = 5 |
| 153 | const NTR_AN_HG: i64 = 6 |
| 154 | const NTR_AN_SEED: i64 = 7 |
| 155 | const NTR_AN_N: i64 = 8 |
| 157 | const NTR_HP_PAD: i64 = 1 |
| 159 | const CX_W: i64 = 0 |
| 160 | const CX_VWO: i64 = 1 |
| 161 | const CX_TWO: i64 = 2 |
| 162 | const CX_XWO: i64 = 3 |
| 163 | const CX_SWO: i64 = 4 |
| 164 | const CX_NV: i64 = 5 |
| 165 | const CX_NTR: i64 = 6 |
| 166 | const CX_NJ: i64 = 7 |
| 167 | const CX_G: i64 = 8 |
| 168 | const CX_RES: i64 = 9 |
| 169 | const CX_UNUM: i64 = 10 |
| 170 | const CX_UDEN: i64 = 11 |
| 171 | const CX_REGS: i64 = 12 |
| 172 | const CX_JRANK: i64 = 13 |
| 173 | const CX_AX: i64 = 14 |
| 174 | const CX_APEX: i64 = 15 |
| 175 | const CX_N: i64 = 16 |
functions
| 196 | func ntr_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } |
| 197 | func ntr_max(a: i64, b: i64) -> i64 { if a > b { return a } return b } |
| 198 | func ntr_min(a: i64, b: i64) -> i64 { if a < b { return a } return b } |
| 199 | func ntr_clamp(v: i64, lo: i64, hi: i64) -> i64 { if v < lo { return lo } if v > hi { return hi } return v } |
| 200 | func ntr_copy(dst: *u8, src: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { dst[i] = src[i]; i = i + 1 } return 0 } called by 1: ntr_dup |
| 201 | func ntr_dup(src: *u8, n: i64) -> i64 { let d: *u8 = sys_mmap(n + 64); ntr_copy(d, src, n); return d as i64 } |
| 203 | func ntr_conf(key: *u8) -> i64 { return lc_geti(NTR_CONF_REL, NTR_CONF_ABS, key, NTR_MISS) } |
| 205 | func ntr_region_name(r: i64) -> *u8 called by 1: ntr_run |
| 213 | func ntr_bands_at_footprint(f_um: i64) -> i64 |
| 226 | func ntr_normal_chart(hq:*i64,res:i64,tp:i64,x:i64,y:i64,footprint_um:i64,out3:*i64)->i64 |
| 236 | func ntr_h_enc(h_um: i64) -> i64 |
| 239 | func ntr_h_dec(v: i64) -> i64 { return (v - NTR_U16_HALF) * NTR_DISP_RANGE_UM / NTR_U16_HALF } |
| 243 | func ntr_source_safe(b:*u8,flen:i64)->i64 |
| 282 | func ntr_blob_capacity(res:i64,mpx:i64,nsets:i64)->i64 |
| 292 | func ntr_png_checked(rgb:*u8,w:i64,h:i64,fbp:*i64,fb_pixels:i64,out:*u8,capacity:i64)->i64 |
| 303 | func ntr_png(rgb: *u8, w: i64, h: i64, fbp: *i64, out: *u8) -> i64 calls 1: write_png_buf |
| 313 | func ntr_cos16(s: i64) -> i64 |
| 331 | func ntr_sin16(s: i64) -> i64 { return ntr_cos16((s + 12) % NTR_NGON) } |
| 337 | func ntr_axes(w: *i64, vwo: i64, nv: i64, out: *i64) -> i64 |
| 377 | func ntr_layout(b: *u8, flen: i64, regs: *i64, jrank: *i64, gR: *i64, njr: *i64, rj: *i64) -> i64 |
| 406 | func ntr_joint_extents(cx: *i64, upax: i64, circ: *i64, blen: *i64, nown: *i64) -> i64 |
| 485 | func ntr_px_sub(uv: i64, j: i64, axis: i64, mode: i64, g: i64, gR: i64, tpR: i64, rank: i64, res: i64) -> i64 |
| 502 | func ntr_footprint(cx: *i64, mode: i64, gRt: *i64, tpRt: *i64, fsum: *i64, asum: *i64, fmax: *i64, carea: *i64, rarea: *i64, straddle: *i64) -> i64 |
| 582 | func ntr_region_footprint(r: i64, nj: i64, regs: *i64, fsum: *i64, asum: *i64, out: *i64) -> i64 called by 1: ntr_run |
| 608 | func ntr_apex(cx: *i64, dwo: i64, out: *i64) -> i64 |
| 678 | func ntr_raster(cx: *i64, reg: i64, gRr: i64, tpRr: i64, fa: *i64, fb: *i64, cov: *u8) -> i64 |
| 791 | func ntr_anat_h(a: i64, b: i64, an: *i64) -> i64 |
| 831 | func ntr_bake_tile(seed: i64, mask: i64, hq: *i64, nrgb: *u8, drgb: *u8) -> i64 called by 2: mainntr_run calls 9: rlf_tile_pxrlf_relief_um2_tile_bandsntr_h_encntr_h_decsys_mmaprlf_tile_texel_um+3 |
| 872 | func ntr_mean_slope_e3(hq: *i64, px: i64, run_um: i64, per: i64) -> i64 |
| 894 | func ntr_mean_slope_sel_e3(hq: *i64, res: i64, run_um: i64, sel: *u8) -> i64 |
| 920 | func ntr_pore_period(hq: *i64, px: i64, repeat_um: i64, out: *i64) -> i64 |
| 991 | func ntr_toc_index(b: *u8, ns: i64, tag: *u8) -> i64 |
| 997 | func ntr_read_ledger(an: *i64) -> i64 |
| 1022 | func ntr_run(inp: *u8, outp: *u8, res_in: i64, seed: i64, hue: i64, ctl: i64, mode: i64) -> i64 called by 3: ntr_measurentr_applyntr_apply_ctl calls 50: sys_mmapsys_read_filent_errntr_source_safent_rd64nxa_magic+44 |
| 1544 | func ntr_measure(inp: *u8, res: i64) -> i64 { return ntr_run(inp, inp, res, 0, 0, NTR_CTL_ALL, 0) } |
| 1545 | func ntr_apply(inp: *u8, outp: *u8, res: i64, seed: i64, hue: i64) -> i64 { return ntr_run(inp, outp, res, seed, hue, NTR_CTL_ALL, 1) } |
| 1546 | func ntr_apply_ctl(inp: *u8, outp: *u8, res: i64, seed: i64, hue: i64, ctl: i64) -> i64 { return ntr_run(inp, outp, res, seed, hue, ctl, 1) } |
| 1554 | func ntr_texr_validate(b:*u8,flen:i64)->i64 |
| 1605 | func ntr_texr_find(b: *u8, flen: i64) -> i64 { return ntr_texr_validate(b, flen) } called by 13: mainnr_inspectrg_texr_nsetsmainntr_texr_adequatentr_texr_set+7 calls 1: ntr_texr_validate |
| 1606 | func ntr_texr_adequate(b: *u8, flen: i64) -> i64 |
| 1624 | func ntr_texr_set(b: *u8, flen: i64, region: i64) -> i64 |