nx_sdfrender_sss_gate.nx
buildroot/runtime/nx_sdfrender_sss_gate.nx
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
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
structs
| none |
consts
| 34 | const SG_PK: i64 = 1024 // the (wR,wG,wB) packing radix used by sr_sss_preint_n |
| 35 | const SG_PK2: i64 = 1048576 // = SG_PK*SG_PK, the blue field's shift |
| 36 | const SG_PERMIL: i64 = 1000 |
| 37 | const SG_TINT: i64 = 1 // a ONE-UNIT red tint: the smallest possible level change |
| 38 | const SG_CH_R: i64 = 0 |
| 39 | const SG_CH_G: i64 = 1 |
| 40 | const SG_CH_B: i64 = 2 |
| 41 | const SG_CURV_STEP: i64 = 64 // curvature sweep step (0..SSS_CURV_MAX inclusive) |
| 42 | const SG_NDL_STEP: i64 = 32 // N.L sweep over the full -SSS_N_FULL..SSS_N_FULL range |
| 104 | const SG_REACH_N: i64 = 64 // samples along the sweep |
| 105 | const SG_REACH_STRIDE: i64 = 7 // model-unit stride, coprime with the noise lattices (24/9/5 and 18) |
| 106 | const SG_MT_HI: i64 = 8201 // the retired shader's +e central-difference offset |
| 107 | const SG_MT_MID: i64 = 8192 |
| 108 | const SG_MT_LO: i64 = 8183 // ... and its -e offset |
| 109 | const SG_OLD_GAIN_NUM: i64 = 10 // the RETIRED hand-picked gain. It exists here ONLY as a neg-control. |
| 110 | const SG_OLD_GAIN_DEN: i64 = 16 |
| 139 | const SG_FIELD_N: i64 = 64 |
| 140 | const SG_FIELD_STRIDE2: i64 = 11 // second-axis stride, coprime with the first and with every lattice |
| 141 | const SG_NEG_RES: i64 = 4096 // a real atlas resolution whose relief lattice is NOT the shader's |
| 144 | const SG_ATLAS_RES_LO: i64 = 1024 |
| 145 | const SG_ATLAS_RES_MID: i64 = 2048 |
| 148 | const SG_CODOMAIN_GAP: i64 = 1 |
functions
| 44 | func sg_chan(v: i64, ch: i64) -> i64 |
| 49 | func sg_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } |
| 52 | func sg_pre_real(nd: i64, gd: i64, curv: i64) -> i64 |
| 59 | func sg_pre_uniform(nd: i64, gd: i64, curv: i64) -> i64 |
| 66 | func sg_contrast_real(gd: i64, tilt: i64, curv: i64, ch: i64) -> i64 |
| 69 | func sg_contrast_uniform(gd: i64, tilt: i64, curv: i64, ch: i64) -> i64 |
| 73 | func sg_contrast_wrap(gd: i64, tilt: i64, curv: i64, ch: i64) -> i64 |
| 79 | func sg_fails_ratio(cr: i64, cb: i64, wr: i64, wb: i64) -> i64 called by 1: main |
| 87 | func sg_breaks_identity(tint: i64) -> i64 |
| 111 | func sg_proc_tilt_max() -> i64 |
| 125 | func sg_baked_tilt_max() -> i64 |
| 149 | func sg_field_differs_at(cell: i64, res: i64) -> i64 |
| 160 | func sg_gain_breaks_law(g: i64) -> i64 { if g != sr_relief_wrap() { return 1 } return 0 } |
| 161 | func sg_tilt_old_gain(dh: i64) -> i64 { return dh * SG_OLD_GAIN_NUM / SG_OLD_GAIN_DEN } called by 1: main |
| 163 | func main() -> i64 |