code wiki / (root) / nx_sdfrender_sss_gate.nx

nx_sdfrender_sss_gate.nx

buildroot/runtime/nx_sdfrender_sss_gate.nx

19764 B325 linesdepth 6pulls 17 transitivereach 0 importersview sourcekind gate/prooftopic sdfrender
docsdependenciesstructsconstsfunctions

about

nx_sdfrender_sss_gate.nx -- THE PRE-INTEGRATED-NORMAL HALF of Penner 2011, gated. [@penner2011] /compare/graphics row: "RENDER: pre-integrated SSS bound to baked normals" -- the rung that stops the clay read. The CURVATURE half (sr_sss_preint over N.L x curvature) already shipped and is pinned by nx_sdfrender_gate's T6; this gate owns the half that binds the shader to the BAKED NORMAL MAP: each colour channel lit by its own blur of DETAIL->GEOMETRIC normal, so fine relief SCATTERS. ★2026-08-25, THE SAMPLING RUNG: the mechanism above shipped bound to the baked map's CONSTANTS while the DETAIL normal was still a procedural stand-in (mat_height through a hand-picked 10/16 gain). Its reach was MEASURED at 18 against the law's 51, so the blur was competing with a signal of a different width. sdf_shade_ray now samples the BAKED MAP'S OWN HEIGHT FIELD -- literally the same rlf_noise3 the baker calls -- and the gain is the law instead of a number. T4/T9/T10 are that rung; T3's derivation and the whole curvature half are unchanged and still pinned. WHY THESE TEETH AND NOT A PICTURE DIFF: a render diff moves for a hundred reasons. Every tooth here is a property of the arithmetic that the WRONG implementations provably cannot satisfy -- * a PLAIN BLUR softens all three channels equally -> dies at T6 (neg-control, bite-proven) * a RED TINT raises red's level, not its contrast -> dies at T1 (neg-control, bite-proven) * the PRE-RUNG shader (wrap only) -> dies at T6, which measures it AS THE CONTROL * a dialled-in constant -> dies at T3/T9 (derivation + the law's gain) * a LOOK-ALIKE field of the shader's own -> dies at T4 (the baker's field, cross-checked) * the retired 10/16 gain -> dies at T9 (neg-control, bite-proven) T5 alone is NOT sufficient and that is measured, not assumed: a uniform blur PASSES T5 (the wrap already orders the channels) and FAILS T6. T6 is the load-bearing tooth for the MECHANISM, and its bar is not a magic number -- it is the SHIPPED wrap-only path, called at runtime as the incumbent control. T10 is the load-bearing tooth for the REACH, and its bar is the RETIRED procedural path, also called at runtime. Neither bar is ever a constant. license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26).

dependencies 5 imports · 0 importers

nx_syscalls.nx nx_gate_verdict.nx nx_relief_lib.nx nx_sdfrender.nx nx_nxa_texbake_lib.nx nx_sdfrender_sss_gate.nx

imports: nx_syscalls.nxnx_gate_verdict.nxnx_relief_lib.nxnx_sdfrender.nxnx_nxa_texbake_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main gv_ctr sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ gv_head gv_puts sys_write ↻ sr_relief_wrap rlf_tilt_full sr_sss_blur sr_relief_wrap ↻ gv_puts ↻ gv_num sys_mmap ↻ sys_write ↻ sys_munmap sr_sss_ndl gv_check gv_puts ↻ sg_breaks_identity sg_pre_real sr_sss_blur ↻ sr_sss_preint_n sr_sss_ndl ↻ sr_sss_preint sr_sss_preint_n ↻ sr_relief_cell

structs

none

consts

34const SG_PK: i64 = 1024 // the (wR,wG,wB) packing radix used by sr_sss_preint_n
35const SG_PK2: i64 = 1048576 // = SG_PK*SG_PK, the blue field's shift
36const SG_PERMIL: i64 = 1000
37const SG_TINT: i64 = 1 // a ONE-UNIT red tint: the smallest possible level change
38const SG_CH_R: i64 = 0
39const SG_CH_G: i64 = 1
40const SG_CH_B: i64 = 2
41const SG_CURV_STEP: i64 = 64 // curvature sweep step (0..SSS_CURV_MAX inclusive)
42const SG_NDL_STEP: i64 = 32 // N.L sweep over the full -SSS_N_FULL..SSS_N_FULL range
104const SG_REACH_N: i64 = 64 // samples along the sweep
105const SG_REACH_STRIDE: i64 = 7 // model-unit stride, coprime with the noise lattices (24/9/5 and 18)
106const SG_MT_HI: i64 = 8201 // the retired shader's +e central-difference offset
107const SG_MT_MID: i64 = 8192
108const SG_MT_LO: i64 = 8183 // ... and its -e offset
109const SG_OLD_GAIN_NUM: i64 = 10 // the RETIRED hand-picked gain. It exists here ONLY as a neg-control.
110const SG_OLD_GAIN_DEN: i64 = 16
139const SG_FIELD_N: i64 = 64
140const SG_FIELD_STRIDE2: i64 = 11 // second-axis stride, coprime with the first and with every lattice
141const SG_NEG_RES: i64 = 4096 // a real atlas resolution whose relief lattice is NOT the shader's
144const SG_ATLAS_RES_LO: i64 = 1024
145const SG_ATLAS_RES_MID: i64 = 2048
148const SG_CODOMAIN_GAP: i64 = 1

functions

44func sg_chan(v: i64, ch: i64) -> i64
49func sg_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
52func sg_pre_real(nd: i64, gd: i64, curv: i64) -> i64
59func sg_pre_uniform(nd: i64, gd: i64, curv: i64) -> i64
66func sg_contrast_real(gd: i64, tilt: i64, curv: i64, ch: i64) -> i64
called by 1: main calls 3: sg_abssg_chansg_pre_real
69func sg_contrast_uniform(gd: i64, tilt: i64, curv: i64, ch: i64) -> i64
called by 1: main calls 3: sg_abssg_chansg_pre_uniform
73func sg_contrast_wrap(gd: i64, tilt: i64, curv: i64, ch: i64) -> i64
called by 1: main calls 3: sg_abssg_chansr_sss_preint
79func sg_fails_ratio(cr: i64, cb: i64, wr: i64, wb: i64) -> i64
called by 1: main
87func sg_breaks_identity(tint: i64) -> i64
called by 1: main calls 2: sg_pre_realsr_sss_preint
111func sg_proc_tilt_max() -> i64
called by 1: main calls 2: mat_heightsg_abs
125func sg_baked_tilt_max() -> i64
called by 1: main calls 2: sg_abssr_relief_grad
149func sg_field_differs_at(cell: i64, res: i64) -> i64
called by 1: main calls 2: ntb_relief_hrlf_relief_h3
160func sg_gain_breaks_law(g: i64) -> i64 { if g != sr_relief_wrap() { return 1 } return 0 }
called by 1: main calls 1: sr_relief_wrap
161func sg_tilt_old_gain(dh: i64) -> i64 { return dh * SG_OLD_GAIN_NUM / SG_OLD_GAIN_DEN }
called by 1: main
163func main() -> i64