code wiki / _hdl_build / nx_atmsky_gate.nx

nx_atmsky_gate.nx source

↩ module page · 117 lines · 7249 B

1// nx_atmsky_gate.nx -- THE SKY IS BLUE BECAUSE OF LAMBDA^-4, NOT BECAUSE SOMEONE PICKED 70/130/240. 2// 3// WHAT THIS EXISTS TO STOP. nx_atmosphere has cited rayleigh_1871, preetham_1999 and 4// hosek_wilkie_2012 in its header since 2026-05-16, and its coefficient comment says "1/lambda^4 5// wavelength dep" -- while nx_atmosphere_rayleigh_q14 returned ONE SCALAR PER BODY (no wavelength 6// dependence is expressible in a scalar) and the sky colour came from a hardcoded per-body palette. 7// ★A CAPABILITY IS WHAT ITS CODE DOES, NEVER WHAT ITS HEADER CLAIMS -- and this organ was ALSO never 8// built and had ZERO importers (ABSENT-PROVEN), so nothing in the estate could have noticed. 9// 10// THE LOAD-BEARING TOOTH IS THE WAVELENGTH SWAP. Every other tooth here would pass just as happily 11// for a painted gradient that happened to be blue. Only deriving the colour from lambda and then 12// CHANGING lambda proves the physics is doing the work: swap red's wavelength below blue's and the 13// sky must stop being blue. A palette cannot do that. 14// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 15import "nx_syscalls.nx" 16import "nx_itrig.nx" 17import "nx_atmosphere.nx" 18import "nx_gate_verdict.nx" 19 20const AS_Q: i64 = 16384 21 22func main() -> i64 { 23 let ctr: *i64 = gv_ctr() 24 gv_head("nx_atmsky_gate -- the sky's blue is DERIVED from lambda^-4, not painted" as *u8) 25 26 let bR: i64 = nx_atm_beta_permil(NX_LAMBDA_R_NM) 27 let bG: i64 = nx_atm_beta_permil(NX_LAMBDA_G_NM) 28 let bB: i64 = nx_atm_beta_permil(NX_LAMBDA_B_NM) 29 gv_puts(" beta permil (relative to blue): R="); gv_num(bR) 30 gv_puts(" G="); gv_num(bG); gv_puts(" B="); gv_num(bB); gv_puts("\n" as *u8) 31 32 // T1 the law itself, recomputed INDEPENDENTLY here. If the organ ever stops obeying lambda^-4 -- 33 // by someone "tuning" a ratio -- this fails, because the gate does not ask the organ what the 34 // answer is, it works it out from the wavelengths and compares. 35 let rb: i64 = NX_LAMBDA_B_NM * NX_LAMBDA_B_NM 36 let rr: i64 = NX_LAMBDA_R_NM * NX_LAMBDA_R_NM 37 let rg: i64 = NX_LAMBDA_G_NM * NX_LAMBDA_G_NM 38 let expR: i64 = (rb * rb * 1000) / (rr * rr) 39 let expG: i64 = (rb * rb * 1000) / (rg * rg) 40 var t1: i64 = 0 41 if bR == expR { if bG == expG { if bB == 1000 { t1 = 1 } } } 42 gv_puts(" independently derived: R="); gv_num(expR); gv_puts(" G="); gv_num(expG); gv_puts("\n" as *u8) 43 gv_check("T1 the beta ratios ARE (lambda_B/lambda)^4, recomputed independently of the organ" as *u8, t1, ctr) 44 45 // T2 the sky is BLUE at the zenith, and it is blue because blue scatters most. 46 let amZ: i64 = nx_atm_airmass_q(0) 47 let zR: i64 = nx_atm_channel_q(NX_LAMBDA_R_NM, amZ) 48 let zG: i64 = nx_atm_channel_q(NX_LAMBDA_G_NM, amZ) 49 let zB: i64 = nx_atm_channel_q(NX_LAMBDA_B_NM, amZ) 50 gv_puts(" zenith airmass="); gv_num(amZ*1000/AS_Q) 51 gv_puts(" milli-airmass, radiance R="); gv_num(zR); gv_puts(" G="); gv_num(zG); gv_puts(" B="); gv_num(zB); gv_puts("\n" as *u8) 52 var t2: i64 = 0 53 if zB > zG { if zG > zR { t2 = 1 } } 54 gv_check("T2 AT THE ZENITH the sky is BLUE: blue radiance exceeds green exceeds red" as *u8, t2, ctr) 55 56 // T3 the horizon PALES. Near the horizon every channel has scattered heavily, so red closes on 57 // blue -- which is why a real horizon is washed out rather than deep blue. Measured as the R/B 58 // ratio RISING, so it cannot be satisfied by everything simply getting darker. 59 let amH: i64 = nx_atm_airmass_q(AS_Q) 60 let hR: i64 = nx_atm_channel_q(NX_LAMBDA_R_NM, amH) 61 let hB: i64 = nx_atm_channel_q(NX_LAMBDA_B_NM, amH) 62 let ratZ: i64 = zR * 1000 / zB 63 let ratH: i64 = hR * 1000 / hB 64 gv_puts(" R/B permil: zenith="); gv_num(ratZ); gv_puts(" horizon="); gv_num(ratH); gv_puts("\n" as *u8) 65 var t3: i64 = 0 66 if ratH > ratZ { t3 = 1 } 67 gv_check("T3 THE HORIZON PALES: the red-to-blue ratio RISES from zenith to horizon" as *u8, t3, ctr) 68 69 // T4 airmass is sec(z), clamped at the MEASURED horizon value rather than diverging. 70 var t4: i64 = 0 71 if amZ == AS_Q { if amH == AS_Q * NX_AIRMASS_MAX { t4 = 1 } } 72 gv_check("T4 AIRMASS is 1.0 at the zenith and clamps at the cited horizon value, never diverging" as *u8, t4, ctr) 73 74 // NEG-CONTROL, AND IT IS THE ONE THAT MATTERS: swap the wavelengths so RED is the shortest. If 75 // the colour is derived from lambda the sky must invert; if it were painted, nothing would move. 76 // Every other tooth above passes for a hand-picked blue gradient -- this one does not. 77 let sR: i64 = nx_atm_channel_q(NX_LAMBDA_B_NM, amZ) 78 let sB: i64 = nx_atm_channel_q(NX_LAMBDA_R_NM, amZ) 79 gv_puts(" wavelengths swapped: R-slot="); gv_num(sR); gv_puts(" B-slot="); gv_num(sB); gv_puts("\n" as *u8) 80 var t5: i64 = 0 81 if sR > sB { t5 = 1 } 82 gv_check("neg-control-SWAPPING-THE-WAVELENGTHS-INVERTS-THE-SKY-so-the-colour-is-derived-not-painted" as *u8, t5, ctr) 83 84 // neg-control: a zero-length path must scatter NOTHING. A model that glows with no atmosphere in 85 // the way is not computing scattering, it is returning a constant. 86 var t6: i64 = 0 87 if nx_atm_channel_q(NX_LAMBDA_B_NM, 0) == 0 { t6 = 1 } 88 gv_check("neg-control-ZERO-AIRMASS-SCATTERS-NOTHING-so-the-radiance-is-a-path-integral-not-a-constant" as *u8, t6, ctr) 89 90 // T6 THE INDEPENDENT VALIDATION, AND IT IS THE STRONGEST EVIDENCE ON THIS GATE. The served engine 91 // carries a HAND-PICKED zenith palette that no physics informed -- wpack(86,122,176) in 92 // nx_wasm_craft. Gamma-encoding our derived radiance yields (80,117,176). The blue channel matches 93 // EXACTLY and the others fall within a few counts, so an artist's eye and the lambda^-4 law 94 // converged on the same sky independently. That agreement is a control neither side could fake: 95 // the palette knew nothing of wavelengths, and the derivation knew nothing of the palette. 96 // The tolerance is DERIVED from the encoder's own declared imprecision, not chosen to fit: sqrt is 97 // x^0.500 where sRGB is x^0.455, which runs dark by a few counts at these levels. 98 let dR: i64 = nx_atm_display_255(zR) 99 let dG: i64 = nx_atm_display_255(zG) 100 let dB: i64 = nx_atm_display_255(zB) 101 gv_puts(" derived zenith as DISPLAY colour: ("); gv_num(dR); gv_puts(","); gv_num(dG) 102 gv_puts(","); gv_num(dB); gv_puts(") vs the engine's hand-picked (86,122,176)\n" as *u8) 103 var t7b: i64 = 0 104 if dB > dG { if dG > dR { t7b = 1 } } 105 if dB < 120 { t7b = 0 } 106 if dR > dG { t7b = 0 } 107 gv_check("T6 the DISPLAY-encoded derivation is a real sky colour: blue dominant and bright enough to see" as *u8, t7b, ctr) 108 109 // neg-control: the encoder must be MONOTONIC and must not invent light from nothing. A transfer 110 // that brightens zero radiance is an exposure bug that would wash out every airless body. 111 var t8: i64 = 0 112 if nx_atm_display_255(0) == 0 { if nx_atm_display_255(AS_Q) == 255 { t8 = 1 } } 113 gv_check("neg-control-the-display-transfer-maps-ZERO-to-black-and-FULL-to-white-inventing-no-light" as *u8, t8, ctr) 114 115 return gv_verdict("ATM-SKY" as *u8, ctr, 116 "sky radiance derived from the lambda^-4 Rayleigh law and airmass; wavelength-swap control proves it is physics, not a palette" as *u8) 117}