nx_gpe_marschner_gate.nx source
↩ module page · 101 lines · 6376 B
1// nx_gpe_marschner_gate.nx -- referee for hr_marschner_lobe (graphics.matrix watch contract,
2// 2026-08-30): the NPC hair fragment path must carry the Karis-2016 closed-form Marschner
3// R/TT/TRT lobes with melanin-derived absorption, in BOTH the emitter SOURCE
4// (buildroot/runtime/nx_game_page_emit.nx) and the SERVED beach page
5// (sites/nishifamily/world/beach.html). Teeth are arithmetic + byte-binding: the pheomelanin
6// discriminator (a red-genome lock absorbs less red per melanin unit than a dark-genome lock,
7// so its TT forward-transmission lobe is strictly brighter backlit) is proven in integer
8// milli-units over the SAME H8 palette rows the page ships, and binding teeth pin those
9// constants to the subject bytes so the gate's arithmetic and the shader cannot drift apart
10// silently. DECLARED IMPRECISION, so the next reader does not trust this as exact: the
11// discriminator and angular teeth are FORMULA-level, never pixel-level -- a rendered-pixel A/B
12// needs a browser rig this gate does not have; what IS provable here is the formula over the
13// shipped constants plus the byte binding of every constant to both subjects.
14// license_tier: ORIGINAL No hw writes (Rule 26).
15import "nx_syscalls.nx"
16import "nx_gate_verdict.nx"
17
18const GMG_SRC: *u8 = "buildroot/runtime/nx_game_page_emit.nx"
19const GMG_PAGE: *u8 = "sites/nishifamily/world/beach.html"
20
21func gmg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
22// flag-carried bounded scan (the cursor-sentinel idiom erases answers; nx_srclint hunts it)
23func gmg_find(b: *u8, n: i64, pat: *u8) -> i64 {
24 let pl: i64 = gmg_slen(pat)
25 var i: i64 = 0
26 while i + pl <= n {
27 var k: i64 = 0
28 var hit: i64 = 1
29 while k < pl {
30 if b[i+k] != pat[k] { hit = 0; k = pl } else { k = k + 1 }
31 }
32 if hit == 1 { return i }
33 i = i + 1
34 }
35 return 0 - 1
36}
37func gmg_has(b: *u8, n: i64, pat: *u8) -> i64 { if gmg_find(b, n, pat) >= 0 { return 1 } return 0 }
38func gmg_absent(b: *u8, n: i64, pat: *u8) -> i64 { if gmg_find(b, n, pat) >= 0 { return 0 } return 1 }
39
40func main() -> i64 {
41 let ctr: *i64 = gv_ctr()
42 gv_head("nx_gpe_marschner_gate -- hr_marschner_lobe: Marschner R/TT/TRT hair shading, melanin-parameterised, in emitter source AND served beach page" as *u8)
43
44 let lps: *i64 = sys_mmap(16) as *i64
45 let src: *u8 = sys_read_file(GMG_SRC, lps)
46 var sn: i64 = 0
47 if (src as i64) != 0 { sn = lps[0] }
48 if gv_subjects("emitter-source-bytes" as *u8, sn, ctr) == 1 {
49 gv_check("T1 src-carries-hr_marschner_lobe-block" as *u8, gmg_has(src, sn, "hr_marschner_lobe" as *u8), ctr)
50 gv_check("T2 src-TT-azimuthal-fit-present (Karis 2016 exp(-3.65*cPhi-3.98))" as *u8, gmg_has(src, sn, "exp(-3.65*cPhi-3.98)" as *u8), ctr)
51 gv_check("T3 src-TRT-azimuthal-fit-present (Karis 2016 exp(17.*cPhi-16.78))" as *u8, gmg_has(src, sn, "exp(17.*cPhi-16.78)" as *u8), ctr)
52 gv_check("T4 src-eumelanin-sigma-present (d'Eon 2011 .419,.697,1.37)" as *u8, gmg_has(src, sn, ".419,.697,1.37" as *u8), ctr)
53 gv_check("T5 src-pheomelanin-sigma-present (d'Eon 2011 .187,.40,1.05)" as *u8, gmg_has(src, sn, ".187,.40,1.05" as *u8), ctr)
54 gv_check("T6 src-cuticle-tilt-shift-present (Marschner 2003 radians(-3.))" as *u8, gmg_has(src, sn, "radians(-3.)" as *u8), ctr)
55 gv_check("T7 neg-control-retired-flat-halfvector-spec-absent-from-src" as *u8, gmg_absent(src, sn, "pow(max(0.,1.-th8*th8),26.)*.048" as *u8), ctr)
56 gv_check("T9 src-ships-the-H8-rows-the-discriminator-arithmetic-uses (red [.65,.33,.18], dark [.16,.14,.18])" as *u8, gmg_has(src, sn, "[.65,.33,.18]" as *u8) * gmg_has(src, sn, "[.16,.14,.18]" as *u8), ctr)
57 }
58
59 // T8: the pheomelanin discriminator, integer milli-units over the SHIPPED H8 rows: red genome
60 // H8[1]=(.65,.33,.18), dark genome H8[3]=(.16,.14,.18); luminance weights .299/.587/.114 and
61 // the pheomelanin map (r-max(g,b)+.08)*3.5 are the shader's own (bound to bytes by T2..T9).
62 // mel = -log(lum) is monotone DECREASING in lum, so lumR > lumD proves melR < melD without a
63 // log table; per-melanin-unit red absorption mix(419,187,phr) then strictly lower for red
64 // => sigmaA.r(red) < sigmaA.r(dark) => TT red transmission strictly brighter. Both factors.
65 let lumR: i64 = (650*299 + 330*587 + 180*114) / 1000
66 let lumD: i64 = (160*299 + 140*587 + 180*114) / 1000
67 var phrR: i64 = ((650 - 330 + 80) * 35) / 10
68 if phrR > 1000 { phrR = 1000 }
69 if phrR < 0 { phrR = 0 }
70 var phrD: i64 = ((160 - 180 + 80) * 35) / 10
71 if phrD > 1000 { phrD = 1000 }
72 if phrD < 0 { phrD = 0 }
73 let mixR: i64 = (419*(1000-phrR) + 187*phrR) / 1000
74 let mixD: i64 = (419*(1000-phrD) + 187*phrD) / 1000
75 var d8: i64 = 0
76 if lumR > lumD { if phrR > phrD { if mixR < mixD { d8 = 1 } } }
77 gv_check("T8 pheomelanin-discriminator-arithmetic: red genome lum higher AND per-melanin-unit red absorption lower => backlit TT strictly brighter than dark genome" as *u8, d8, ctr)
78
79 // T10: TT angular delta from the SHIPPED fit constant: exponent(-3.65*cPhi-3.98) at backlit
80 // (cPhi=-1) minus frontlit (cPhi=+1) = 7300 milli, nonzero BY CONSTRUCTION of the constant;
81 // a flat/albedo-only shader's angular delta is 0. FORMULA-level, declared above.
82 let ebk: i64 = ((0-3650)*(0-1000))/1000 - 3980
83 let efr: i64 = ((0-3650)*1000)/1000 - 3980
84 var t10: i64 = 0
85 if ebk - efr == 7300 { t10 = 1 }
86 gv_check("T10 TT-angular-delta-7300-milli-backlit-vs-frontlit (flat shader reads 0)" as *u8, t10, ctr)
87
88 let lpp: *i64 = sys_mmap(16) as *i64
89 let pg: *u8 = sys_read_file(GMG_PAGE, lpp)
90 var pn: i64 = 0
91 if (pg as i64) != 0 { pn = lpp[0] }
92 if gv_subjects("served-beach-page-bytes" as *u8, pn, ctr) == 1 {
93 gv_check("T11 served-page-carries-hr_marschner_lobe" as *u8, gmg_has(pg, pn, "hr_marschner_lobe" as *u8), ctr)
94 gv_check("T12 served-page-carries-TT-fit" as *u8, gmg_has(pg, pn, "exp(-3.65*cPhi-3.98)" as *u8), ctr)
95 gv_check("T13 neg-control-served-page-retired-flat-spec-absent" as *u8, gmg_absent(pg, pn, "pow(max(0.,1.-th8*th8),26.)*.048" as *u8), ctr)
96 }
97
98 let rc: i64 = gv_verdict("GPE-MARSCHNER" as *u8, ctr, "formula+byte-level proof; the pixel-level A/B belongs to the browser rig" as *u8)
99 sys_exit(rc)
100 return rc
101}