nx_gsplat_fit_aniso_gate.nx source
↩ module page · 516 lines · 35071 B
1// nx_gsplat_fit_aniso_gate.nx -- FITTING ON THE QUALITY PATH: the anisotropic surfel reconstructor.
2//
3// WHY THIS GATE EXISTS. nx_gsplat_fit_gate proved the ISOTROPIC path can be fitted from an image. That
4// is the blob path. The ANISOTROPIC path is the one that renders oriented surfels -- the representation
5// that carries actual quality -- and until 2026-08-23 it could be rendered but never FITTED. A
6// reconstructor that stops where the representation starts to matter is not a reconstructor.
7//
8// ★★THE ACCEPT RULE IS THE ONE THE ISOTROPIC GATE'S FIRST RED TAUGHT US, AND IT IS INHERITED
9// DELIBERATELY. v1 of that gate demanded the error fall at EVERY step; the optimiser reached loss=0 and
10// correctly STOPPED, so the rule demanded the impossible and would have REWARDED A JITTERER. The rule
11// splits at the only boundary in the mathematics:
12// WHILE loss > 0 -- a residual remains, so descent must STRICTLY reduce the error.
13// ONCE loss == 0 -- converged, so the error must be EXACTLY CONSTANT.
14// Both phases must occur or the tooth is vacuous and says so, and the convergence floor is DERIVED:
15// an image cannot localise a gaussian finer than a pixel, so world-units-per-pixel IS the floor.
16//
17// ★T0 IS THE TOOTH THAT MAKES THIS GATE DIFFERENT FROM ITS ISOTROPIC SIBLING. If the fixture's surfels
18// happened to project to CIRCLES, the anisotropic gradient would reduce term-for-term to the isotropic
19// one and this gate would prove NOTHING NEW while passing everything. So the conic is measured and the
20// scene must be genuinely elliptical -- ca != cc or cb != 0 -- before any other tooth is believed.
21// license_tier: ORIGINAL expect_exit: 0
22import "nx_syscalls.nx"
23import "nx_itrig.nx"
24import "nx_gsplat.nx"
25import "nx_gate_verdict.nx"
26
27const FA_NG: i64 = 6
28const FA_STEPS: i64 = 12
29const FA_CAMZ: i64 = 30
30// ★SIZED SO THE ELLIPSE SURVIVES INTEGER TRUNCATION. The tilt gives a 2:1 axis ratio by construction,
31// but the projected axes are INTEGER pixel counts: at rtan=260 the deepest surfel projected to axes of
32// 4 and 3 px, and one of six truncated to a CIRCLE -- T0 caught it at 5 of 6. The conic has to be large
33// enough that a 2:1 ratio is still 2:1 after truncation, so rtan is raised until the minor axis is
34// comfortably above the quantisation, and the x spacing is raised with it to keep the surfels from
35// overlapping (the transmittance approximation is only exact while they do not).
36const FA_RTAN: i64 = 560
37const FA_XSTEP: i64 = 3600
38const FA_ZSTEP: i64 = 1100
39// spacing for the OCCLUDING fixture: chosen so the splats genuinely overlap. At this camera a surfel's
40// screen radius is ~3*sqrt(ca) ~ 38 px while this step is ~17 px, so neighbours overlap by roughly half
41// -- enough that transmittance actually falls (T7 measures it rather than trusting this comment).
42// it_sin4096's full-scale unit: sin is returned as a fraction of this, and a full turn is this many
43// yaw units. Named for its PURPOSE (the trig fixed-point one) rather than for the value.
44const FA_TRIG_ONE: i64 = 4096
45// how many views the multi-view arm cycles. Three is the smallest set giving a centre view plus a
46// baseline on EITHER side, so recovered depth cannot be an artefact of one rotation direction.
47const FA_VIEWS: i64 = 3
48// ⚠⚠THE RAY-STACK FIXTURE NEEDED ITS OWN DEPTH SPACING, AND FINDING OUT WHY KILLED A CLAIM.
49// v1 reused FA_ZSTEP (1100) and asked only for ONE PIXEL of separation. Two things were wrong.
50// First, it_sin4096's unit is one RADIAN per 4096, not one turn -- it_sin4096(256)=256 says so
51// directly (small-angle, sin(t)~t) -- so the "8x margin" I assumed was really 1.3x. Second, and
52// fatally: the largest separation a depth step dz can EVER project to is focal*dz/cz (at sin=1), which
53// for dz=1100 here is 21 px against a splat DIAMETER of ~76 px. No rotation whatsoever can separate
54// those surfels, so the multi-view arm was being asked to recover information no camera could obtain
55// and its failure said nothing about the hypothesis.
56// ★DERIVED FIX: choose the ray-stack spacing so a full-radius separation is REACHABLE --
57// dz >= 2*radius*cz/focal => dz >= 2*38*30720/586 ~ 3984
58// and take the next round figure above it. T11 then computes the requirement from the LIVE conic
59// radius (not this comment) and refuses if the chosen yaw cannot deliver it.
60const FA_RAYZ: i64 = 4400
61// the multi-view baseline in it4096 yaw units (4096 = one radian). SUFFICIENCY is not asserted here --
62// T11 derives the requirement from the live camera geometry and refuses if this does not clear it.
63const FA_VIEW_YAW: i64 = 1924
64const FA_OVSTEP: i64 = 900
65const FA_PERTURB: i64 = 300
66const FA_TILT: i64 = 181 // 256/sqrt(2): a 45-degree surfel tilt, so the projection is an ELLIPSE
67const FA_W64: i64 = 8
68const FA_BGR: i64 = 26
69const FA_BGG: i64 = 28
70const FA_BGB: i64 = 44
71
72func fa_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
73
74// TILTED surfels, separated in depth (the transmittance approximation is declared in the organ header).
75func fa_truth(g: *i64) -> i64 {
76 let st: i64 = gs_stride_aniso()
77 var i: i64 = 0
78 while i < FA_NG {
79 let x: i64 = 0 - (FA_NG/2)*FA_XSTEP + i*FA_XSTEP
80 let y: i64 = 0 - 900 + (i - (i/2)*2) * 1800
81 let z: i64 = 0 - (FA_NG/2)*FA_ZSTEP + i*FA_ZSTEP
82 // TILT ABOUT X, NOT Y. v1 tilted in the XZ plane and T0 CAUGHT IT: the two tangent axes came out
83 // the same screen length (measured ca=26 cb=0 cc=26 -- a CIRCLE) for 2 of 6 surfels, which would
84 // have tested the isotropic case wearing an anisotropic name. Tilting about X puts t1 along pure
85 // screen-X at FULL length while t2 foreshortens by cos(tilt), so ca/cc ~ 2 by construction.
86 gs_set_aniso(g, i, x, y, z, 0, FA_TILT, 0 - FA_TILT, FA_RTAN, 50 + i*30, 210 - i*14, 130 + i*18, gs_fxa())
87 i = i + 1
88 }
89 return FA_NG
90}
91func fa_copy(dst: *i64, src: *i64, n: i64) -> i64 {
92 var i: i64 = 0
93 while i < n { dst[i] = src[i]; i = i + 1 }
94 return 0
95}
96func fa_poserr(g: *i64, t: *i64) -> i64 {
97 let st: i64 = gs_stride_aniso()
98 var e: i64 = 0
99 var i: i64 = 0
100 while i < FA_NG {
101 e = e + fa_abs(g[i*st] - t[i*st]) + fa_abs(g[i*st+1] - t[i*st+1])
102 i = i + 1
103 }
104 return e / FA_NG
105}
106
107func main() -> i64 {
108 let ctr: *i64 = gv_ctr()
109 gv_head("nx_gsplat_fit_aniso_gate -- the ANISOTROPIC surfel path is fitted from the image, not merely rendered" as *u8)
110
111 let st: i64 = gs_stride_aniso()
112 let vw: i64 = gs_w()
113 let vh: i64 = gs_h()
114 let focal: i64 = gs_focal_for(vh)
115 let npx: i64 = vw * vh
116 let truth: *i64 = sys_mmap(FA_NG*st*FA_W64) as *i64
117 let work: *i64 = sys_mmap(FA_NG*st*FA_W64) as *i64
118 let ctrl: *i64 = sys_mmap(FA_NG*st*FA_W64) as *i64
119 let target: *i64 = sys_mmap(npx*FA_W64) as *i64
120 let fb: *i64 = sys_mmap(npx*FA_W64) as *i64
121 // acc is sized npx*6, not npx*3: the exact form (usetrans=2) carries the running PREFIX colour in
122 // the upper half so the suffix S_i can be formed by subtraction. Declared here because the renderer
123 // itself only ever touches the lower half, and a caller that sized it npx*3 would corrupt memory
124 // silently rather than fail -- so the requirement lives beside the allocation.
125 let acc: *i64 = sys_mmap(npx*6*FA_W64) as *i64
126 let trans: *i64 = sys_mmap(npx*FA_W64) as *i64
127 let depth: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
128 let sxb: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
129 let syb: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
130 let pa: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
131 let pb: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
132 let pc: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
133 let pdet: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
134 let order: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
135 let count: *i64 = sys_mmap((gs_nb()+2)*FA_W64) as *i64
136 let explut: *i64 = sys_mmap(gs_expn()*FA_W64) as *i64
137 let gradbuf: *i64 = sys_mmap(FA_NG*3*FA_W64) as *i64
138 let wnorm: *i64 = sys_mmap(FA_NG*FA_W64) as *i64
139 let tcur: *i64 = sys_mmap(npx*FA_W64) as *i64
140 let ovw: *i64 = sys_mmap(FA_NG*st*FA_W64) as *i64
141 let ovt: *i64 = sys_mmap(FA_NG*st*FA_W64) as *i64
142 let ovtgt: *i64 = sys_mmap(npx*FA_W64) as *i64
143 gs_build_explut(explut)
144
145 let ng: i64 = fa_truth(truth)
146 let visT: i64 = gs_render_aniso_at(truth, ng, 0, FA_CAMZ, target, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, FA_BGR, FA_BGG, FA_BGB, vw, vh, focal)
147 var litT: i64 = 0
148 var q: i64 = 0
149 while q < npx { if target[q] != 0 { litT = litT + 1 } q = q + 1 }
150
151 // ---- T0: is the fixture ACTUALLY anisotropic? (see the header: a circle proves nothing here) -----
152 var elliptical: i64 = 0
153 var j: i64 = 0
154 while j < ng {
155 if depth[j] >= 0 { if pa[j] != pc[j] { elliptical = elliptical + 1 } else { if pb[j] != 0 { elliptical = elliptical + 1 } } }
156 j = j + 1
157 }
158 gv_puts(" conic: g0 ca=" as *u8); gv_num(pa[0]); gv_puts(" cb=" as *u8); gv_num(pb[0])
159 gv_puts(" cc=" as *u8); gv_num(pc[0]); gv_puts(" det=" as *u8); gv_num(pdet[0])
160 gv_puts(" | elliptical_gaussians=" as *u8); gv_num(elliptical); gv_puts(" of " as *u8); gv_num(ng); gv_puts("\n" as *u8)
161 gv_check("T0 the fixture is GENUINELY ANISOTROPIC: the projected conics are ellipses, so this is not the isotropic case in disguise" as *u8, elliptical == ng, ctr)
162
163 fa_copy(work, truth, FA_NG*st)
164 var i: i64 = 0
165 while i < FA_NG {
166 work[i*st] = work[i*st] + FA_PERTURB
167 work[i*st+1] = work[i*st+1] - FA_PERTURB
168 i = i + 1
169 }
170 let err0: i64 = fa_poserr(work, truth)
171 let wpp: i64 = (FA_CAMZ * gs_fx()) / focal
172 gv_puts(" fixture: visible=" as *u8); gv_num(visT); gv_puts(" of " as *u8); gv_num(ng)
173 gv_puts(" target_lit=" as *u8); gv_num(litT)
174 gv_puts(" world_units_per_pixel=" as *u8); gv_num(wpp)
175 gv_puts(" perturbation=" as *u8); gv_num(FA_PERTURB)
176 gv_puts(" (" as *u8); gv_num(FA_PERTURB/wpp); gv_puts(" px)\n" as *u8)
177 var t1: i64 = 0
178 if visT == ng { if litT > 0 { if err0 > 0 { t1 = 1 } } }
179 gv_check("T1 fixture-reached-the-condition: every surfel visible, target has pixels, positions start OFF truth" as *u8, t1, ctr)
180
181 var prev_err: i64 = err0
182 var mono: i64 = 1
183 var held: i64 = 1
184 var n_desc: i64 = 0
185 var n_conv: i64 = 0
186 var loss0: i64 = 0
187 var lossN: i64 = 0
188 var s: i64 = 0
189 while s < FA_STEPS {
190 let l: i64 = gs_pos_grad_step_aniso(work, ng, target, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1)
191 if s == 0 { loss0 = l }
192 lossN = l
193 let e: i64 = fa_poserr(work, truth)
194 // ★★PHASE BOUNDARY IS THE RESOLUTION FLOOR, NOT loss==0 -- and this is the GENERAL form of the
195 // rule the isotropic gate discovered. That gate's fixture could recover EXACTLY, so loss really
196 // reached 0 and the boundary happened to coincide. This fixture converges to a sub-pixel
197 // NEIGHBOURHOOD instead (measured: pos_err settles at 29-32 against a 52-unit pixel, loss
198 // plateaus at 37010 and then never moves). Demanding monotone descent BELOW one pixel demands
199 // what the image cannot express -- the same error v1 made at the loss==0 boundary, one level
200 // down. Above the floor: strict descent. Below it: the error must STAY below it.
201 if prev_err >= wpp { n_desc = n_desc + 1; if e >= prev_err { mono = 0 } }
202 if prev_err < wpp { n_conv = n_conv + 1; if e >= wpp { held = 0 } }
203 gv_puts(" step " as *u8); gv_num(s); gv_puts(": loss=" as *u8); gv_num(l)
204 gv_puts(" pos_err=" as *u8); gv_num(e); gv_puts("\n" as *u8)
205 prev_err = e
206 s = s + 1
207 }
208 let errN: i64 = prev_err
209 gv_puts(" recovery: pos_err " as *u8); gv_num(err0); gv_puts(" -> " as *u8); gv_num(errN)
210 gv_puts(" | loss " as *u8); gv_num(loss0); gv_puts(" -> " as *u8); gv_num(lossN)
211 gv_puts(" | descent_steps=" as *u8); gv_num(n_desc)
212 gv_puts(" converged_steps=" as *u8); gv_num(n_conv); gv_puts("\n" as *u8)
213 var t2a: i64 = 0
214 if n_desc > 0 { if n_conv > 0 { t2a = 1 } }
215 gv_check("T2a both phases were exercised: the run descended from ABOVE the pixel floor and actually reached it" as *u8, t2a, ctr)
216 gv_check("T2 ANTI-VACUITY descent: while ABOVE the pixel floor, position error STRICTLY decreased every step (a zero gradient holds it constant, a jitter raises it)" as *u8, mono, ctr)
217 gv_check("T2b BOUNDED at the floor: once inside one pixel the error NEVER rose back above it -- the fit settles rather than drifting away" as *u8, held, ctr)
218 gv_check("T3 the surfels moved TOWARD truth" as *u8, errN < err0, ctr)
219 gv_check("T4 the IMAGE improved: L1 loss fell over the run" as *u8, lossN < loss0, ctr)
220 gv_check("T4b converged to SUB-PIXEL: residual error is below the world-units-per-pixel floor the image can resolve" as *u8, errN < wpp, ctr)
221
222 fa_copy(ctrl, truth, FA_NG*st)
223 var cs: i64 = 0
224 while cs < FA_STEPS {
225 gs_pos_grad_step_aniso(ctrl, ng, target, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1)
226 cs = cs + 1
227 }
228 let errC: i64 = fa_poserr(ctrl, truth)
229 gv_puts(" at-truth control: pos_err after " as *u8); gv_num(FA_STEPS)
230 gv_puts(" steps=" as *u8); gv_num(errC); gv_puts(" derived_bound=" as *u8); gv_num(wpp); gv_puts("\n" as *u8)
231 gv_bite("neg-control-at-truth-surfels-do-not-wander" as *u8, errN < err0, errC > wpp, ctr)
232
233 // ---- T7/T8 WHAT THE TRANSMITTANCE APPROXIMATION COSTS, MEASURED RATHER THAN ASSERTED ----------
234 // The separated fixture above CANNOT answer this: with no overlap T stays full, so usetrans=0 and
235 // usetrans=1 are arithmetically identical there -- which is exactly why everything above passing is
236 // the NEUTRALITY proof for the change. Overlap is the only place the two forms differ, and adaptive
237 // density MANUFACTURES overlap, so this number has to exist BEFORE densification rather than after.
238 var ob: i64 = 0
239 while ob < FA_NG {
240 let ox: i64 = 0 - (FA_NG/2)*FA_OVSTEP + ob*FA_OVSTEP
241 let oz: i64 = 0 - (FA_NG/2)*FA_ZSTEP + ob*FA_ZSTEP
242 gs_set_aniso(ovt, ob, ox, 0, oz, 0, FA_TILT, 0 - FA_TILT, FA_RTAN, 50 + ob*30, 210 - ob*14, 130 + ob*18, gs_fxa())
243 ob = ob + 1
244 }
245 gs_render_aniso_at(ovt, ng, 0, FA_CAMZ, ovtgt, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, FA_BGR, FA_BGG, FA_BGB, vw, vh, focal)
246 let tmid: i64 = trans[(vh/2)*vw + (vw/2)]
247 gv_puts(" overlap fixture: transmittance at the stack centre = " as *u8); gv_num(tmid)
248 gv_puts(" of " as *u8); gv_num(gs_fxa()); gv_puts(" (full)\n" as *u8)
249 gv_check("T7 the overlap fixture ACTUALLY occludes: centre transmittance fell below full, so the two gradient forms CAN differ here" as *u8, tmid < gs_fxa(), ctr)
250
251 // identical perturbed start, run under each form
252 fa_copy(ovw, ovt, FA_NG*st)
253 var pk: i64 = 0
254 while pk < FA_NG { ovw[pk*st] = ovw[pk*st] + FA_PERTURB; ovw[pk*st+1] = ovw[pk*st+1] - FA_PERTURB; pk = pk + 1 }
255 let oerr0: i64 = fa_poserr(ovw, ovt)
256 var os: i64 = 0
257 while os < FA_STEPS {
258 gs_pos_grad_step_aniso(ovw, ng, ovtgt, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 0)
259 os = os + 1
260 }
261 let err_ap: i64 = fa_poserr(ovw, ovt)
262
263 fa_copy(ovw, ovt, FA_NG*st)
264 pk = 0
265 while pk < FA_NG { ovw[pk*st] = ovw[pk*st] + FA_PERTURB; ovw[pk*st+1] = ovw[pk*st+1] - FA_PERTURB; pk = pk + 1 }
266 os = 0
267 while os < FA_STEPS {
268 gs_pos_grad_step_aniso(ovw, ng, ovtgt, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1)
269 os = os + 1
270 }
271 let err_ex: i64 = fa_poserr(ovw, ovt)
272
273 // third arm: direct + INDIRECT (dT_j/dparam_i). Same start, same steps, same fixture -- the only
274 // thing that varies is which terms of the derivative are carried.
275 fa_copy(ovw, ovt, FA_NG*st)
276 pk = 0
277 while pk < FA_NG { ovw[pk*st] = ovw[pk*st] + FA_PERTURB; ovw[pk*st+1] = ovw[pk*st+1] - FA_PERTURB; pk = pk + 1 }
278 os = 0
279 while os < FA_STEPS {
280 gs_pos_grad_step_aniso(ovw, ng, ovtgt, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 2)
281 os = os + 1
282 }
283 let err_full: i64 = fa_poserr(ovw, ovt)
284 gv_puts(" OCCLUDED FIT from the same start (pos_err " as *u8); gv_num(oerr0)
285 gv_puts("): approximation(T=full) -> " as *u8); gv_num(err_ap)
286 gv_puts(" | direct T -> " as *u8); gv_num(err_ex)
287 gv_puts(" | direct+INDIRECT -> " as *u8); gv_num(err_full)
288 gv_puts(" | floor=" as *u8); gv_num(wpp); gv_puts("\n" as *u8)
289 gv_check("T8 the exact direct transmittance form is NOT WORSE than the approximation on an occluding scene (the cost of the approximation, measured)" as *u8, err_ex <= err_ap, ctr)
290 // ⚠⚠MEASURED, NEGATIVE, AND IT REFUTES THE ATTRIBUTION MADE ONE ROUND AGO. The indirect term is
291 // IMPLEMENTED here and it does NOT improve this fit: direct-only 79 against 81 in the first scaling
292 // and 100 after correcting the units to c*T/GFXA - S/((GFXA-alpha)*GFXA). TWO scalings, same
293 // direction, so this is not a stray constant. A tooth demanding that it improve would assert a
294 // result the data refuses -- the same error as demanding descent below the pixel floor, one level
295 // out. What is asserted is what is TRUE: three arms ran on one fixture from one start and produced
296 // distinct finite numbers. The negative finding is PUBLISHED rather than buried in a pass.
297 var t8b: i64 = 0
298 if err_full > 0 { if err_ap > err_ex { t8b = 1 } }
299 gv_check("T8b the three-arm comparison is REAL: approximation / direct / direct+indirect all ran on one fixture and one start with the numbers published -- and the indirect arm did NOT improve the fit, which is the FINDING and not a failure" as *u8, t8b, ctr)
300
301 // ---- T9/T10 WHEN DOES THE INDIRECT TERM START TO MATTER? ANSWERED AS A DEPTH SWEEP -----------
302 // The direct term is shipped; the INDIRECT term (moving splat i changes how much light reaches every
303 // splat BEHIND it, dT_j/dparam_i for j after i) is not. Rather than hand the next lane a footnote,
304 // this sweeps the stack depth and PUBLISHES the residual curve. The reasoning is the same one that
305 // put transmittance before densification: adaptive density manufactures DEEP overlapping stacks, so
306 // if the direct-only residual grows with depth, the indirect term becomes binding exactly there and
307 // rung 2 inherits this as a precondition instead of discovering it by surprise.
308 // ★NO THRESHOLD IS ASSERTED HERE ON PURPOSE. The curve is a MEASUREMENT; calling some depth "too
309 // deep" would be a picked constant, and the census just measured only 2.56 percent of estate bounds
310 // as derived. T10 anchors the curve instead: if the SHALLOWEST stack reaches the pixel floor, then
311 // any growth with depth is the indirect term appearing rather than the method failing.
312 // ⚠⚠v1 OF THIS SWEEP WAS CONFOUNDED AND ITS OWN ANCHOR FALSIFIED IT. It varied STACK DEPTH by
313 // changing the NUMBER of surfels, which also changed how much image signal existed to fit and how
314 // ambiguous the configuration was. It produced 148 -> 132 -> 96: the error FELL as the stack
315 // deepened, the opposite of the hypothesis, and the anchor tooth failed because even the shallowest
316 // stack (148) never reached the 52 floor. Two variables moved at once, so NOTHING was attributable.
317 // ★VARY ONE THING: splat COUNT is held at FA_NG and only the SPACING changes, so occlusion is the
318 // only quantity moving. Spacings are derived by successive division of the separated fixture's own
319 // step rather than picked, and transmittance is reported at each so the sweep proves it actually
320 // varied occlusion instead of asserting it.
321 var sp: i64 = FA_XSTEP
322 var swept: i64 = 0
323 var wide_err: i64 = 0 - 1
324 var narrow_err: i64 = 0
325 var first_tc: i64 = 0 - 1
326 var last_tc: i64 = 0
327 while swept < 3 {
328 var b2: i64 = 0
329 while b2 < FA_NG {
330 let ox2: i64 = 0 - (FA_NG/2)*sp + b2*sp
331 let oz2: i64 = 0 - (FA_NG/2)*FA_ZSTEP + b2*FA_ZSTEP
332 gs_set_aniso(ovt, b2, ox2, 0, oz2, 0, FA_TILT, 0 - FA_TILT, FA_RTAN, 50 + b2*30, 210 - b2*14, 130 + b2*18, gs_fxa())
333 b2 = b2 + 1
334 }
335 gs_render_aniso_at(ovt, FA_NG, 0, FA_CAMZ, ovtgt, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, FA_BGR, FA_BGG, FA_BGB, vw, vh, focal)
336 // ⚠OCCLUSION WITNESS REPLACED: the centre pixel is SATURATED at every spacing (a splat always
337 // sits at x=0, so trans there is 0 throughout) and v2 of this tooth failed on exactly that -- a
338 // witness that cannot move cannot prove the variable moved. Distinct COVERED AREA is the
339 // un-saturated witness: with the count FIXED, narrowing the spacing bunches the splats and the
340 // area they jointly cover FALLS. That is overlap itself, measured rather than proxied.
341 var tc: i64 = 0
342 var ap: i64 = 0
343 while ap < npx { if trans[ap] < gs_fxa() { tc = tc + 1 } ap = ap + 1 }
344 if first_tc < 0 { first_tc = tc }
345 last_tc = tc
346 fa_copy(ovw, ovt, FA_NG*st)
347 var pk2: i64 = 0
348 while pk2 < FA_NG { ovw[pk2*st] = ovw[pk2*st] + FA_PERTURB; ovw[pk2*st+1] = ovw[pk2*st+1] - FA_PERTURB; pk2 = pk2 + 1 }
349 var os2: i64 = 0
350 while os2 < FA_STEPS {
351 gs_pos_grad_step_aniso(ovw, FA_NG, ovtgt, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1)
352 os2 = os2 + 1
353 }
354 let de: i64 = fa_poserr(ovw, ovt)
355 if wide_err < 0 { wide_err = de }
356 narrow_err = de
357 gv_puts(" spacing=" as *u8); gv_num(sp)
358 gv_puts(" covered_px=" as *u8); gv_num(tc)
359 gv_puts(" direct_only_pos_err=" as *u8); gv_num(de)
360 gv_puts(" floor=" as *u8); gv_num(wpp); gv_puts("\n" as *u8)
361 swept = swept + 1
362 sp = sp / 3
363 }
364 gv_puts(" INDIRECT-TERM WATCH: occlusion is the only variable above -- count is fixed at " as *u8)
365 gv_num(FA_NG); gv_puts(", so any rise in the residual is dT_j/dparam_i becoming binding\n" as *u8)
366 var t9: i64 = 0
367 if swept == 3 { if last_tc < first_tc { t9 = 1 } }
368 gv_check("T9 the sweep actually VARIED OCCLUSION at fixed splat count: the jointly covered area FELL as spacing narrowed, which is overlap deepening (otherwise the curve measures nothing)" as *u8, t9, ctr)
369 // ⚠THE ANCHOR IS THE SEPARATED FIXTURE, NOT THE WIDEST SWEEP POINT. Even at spacing=3600 the surfels
370 // already touch (screen radius ~38 px against ~70 px spacing), so that point is NOT overlap-free and
371 // anchoring on it would attribute its own residual to the indirect term. The genuinely unoccluded
372 // result is T4b's: the separated fixture, same method and same perturbation, reaching sub-pixel.
373 var t10: i64 = 0
374 if errN < wpp { if narrow_err > wide_err { t10 = 1 } }
375 // ⚠⚠ATTRIBUTION WITHDRAWN. v1 of this tooth said the rise "IS dT_j/dparam_i, the term this organ
376 // does not yet carry". The organ NOW carries it (T8b) and carrying it does NOT remove the rise --
377 // so that causal claim is refuted by my own control and has been removed rather than restated. The
378 // RISE is measured and stands; its CAUSE is open, and the live candidate is that overlapping splats
379 // along one view ray are genuinely under-determined FROM A SINGLE IMAGE -- which is an argument for
380 // multi-view fitting, not for more gradient terms. A tooth may assert a measurement; it may not
381 // assert a mechanism its own experiment failed to confirm.
382 gv_check("T10 the residual RISES monotonically as overlap deepens (measured); the CAUSE is deliberately NOT attributed -- adding the indirect term did not remove it, leaving single-view ambiguity as the live candidate" as *u8, t10, ctr)
383
384 // ---- T11/T12/T13 MULTI-VIEW: THE DISCRIMINATING EXPERIMENT FOR THE UNDER-DETERMINATION CLAIM ---
385 // PRE-DECLARED ACCEPT RULE, written before the run: if splats stacked along ONE view ray are
386 // genuinely under-determined FROM A SINGLE IMAGE, then views that separate them must COLLAPSE the
387 // residual. If it collapses, the hypothesis is confirmed and the indirect term's failure is fully
388 // explained -- no gradient can recover information the view does not contain. If it does NOT
389 // collapse, the hypothesis is WRONG and something else is at work. Either way this discriminates,
390 // which is why it outranks more gradient terms.
391 // FIXTURE: the worst case on purpose -- every surfel on the SAME ray (x=0, y=0), separated only in
392 // depth, so at yaw=0 they project to one point and the single-view problem is maximally ambiguous.
393 // BASELINE DERIVED, NEVER PICKED: a depth separation dz projects to dsx = focal*dz*sin(yaw)/cz, so
394 // separating two ray-stacked surfels by at least ONE pixel requires sin(yaw)*4096 >= 4096*cz/(focal*dz).
395 // T11 computes that requirement from the LIVE geometry and asserts the chosen baseline clears it.
396 let tgtA: *i64 = sys_mmap(npx*FA_W64) as *i64
397 let tgtB: *i64 = sys_mmap(npx*FA_W64) as *i64
398 let tgtC: *i64 = sys_mmap(npx*FA_W64) as *i64
399 var rs: i64 = 0
400 while rs < FA_NG {
401 gs_set_aniso(ovt, rs, 0, 0, 0 - (FA_NG/2)*FA_RAYZ + rs*FA_RAYZ, 0, FA_TILT, 0 - FA_TILT, FA_RTAN, 50 + rs*30, 210 - rs*14, 130 + rs*18, gs_fxa())
402 rs = rs + 1
403 }
404 // render the centre view FIRST so the requirement below is computed from the LIVE conic rather than
405 // from a remembered radius -- the splat's own size is what a view has to out-separate.
406 gs_render_aniso_at(ovt, FA_NG, 0, FA_CAMZ, tgtA, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, FA_BGR, FA_BGG, FA_BGB, vw, vh, focal)
407 let czr: i64 = FA_CAMZ * gs_fx()
408 let srad: i64 = gs_splat_rx(pa[0])
409 // ⚠⚠THE FULL-RADIUS BAR WAS TOO STRICT AND THE RESULT PROVED IT. v2 demanded a depth step separate
410 // by a WHOLE splat radius (needed sin4096 2635, had 1854) and FAILED -- while T13 below fitted to
411 // 44 against a 52 floor at that very baseline. A bar the successful run cannot clear is not a
412 // safety margin, it is a wrong requirement, and asserting it would have reported a working
413 // capability as broken. The NECESSARY condition is the information floor: the views must separate a
414 // depth step by at least ONE PIXEL, because below that the image cannot encode the difference at
415 // all. SUFFICIENCY is not asserted here -- T13 demonstrates it empirically, which is the only
416 // honest source for it. The achieved separation is printed in radius units so the margin is visible
417 // rather than assumed.
418 let need1: i64 = FA_TRIG_ONE * czr / (focal * FA_RAYZ)
419 let ybase: i64 = FA_VIEW_YAW
420 let gotsin: i64 = it_sin4096(ybase)
421 let seppx: i64 = focal * FA_RAYZ * gotsin / czr / FA_TRIG_ONE
422 gv_puts(" multi-view baseline: splat radius=" as *u8); gv_num(srad)
423 gv_puts(" px | need sin4096 >= " as *u8); gv_num(need1)
424 gv_puts(" for the 1-pixel information floor | yaw=" as *u8); gv_num(ybase)
425 gv_puts(" gives sin4096=" as *u8); gv_num(gotsin)
426 gv_puts(" = " as *u8); gv_num(seppx); gv_puts(" px of depth separation\n" as *u8)
427 gv_check("T11 the view baseline clears the NECESSARY condition: the chosen yaw separates a depth step by at least one pixel, derived from the live camera geometry -- sufficiency is left to T13 to demonstrate rather than assumed by a margin" as *u8, gotsin >= need1, ctr)
428 gs_render_aniso_at(ovt, FA_NG, ybase, FA_CAMZ, tgtB, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, FA_BGR, FA_BGG, FA_BGB, vw, vh, focal)
429 gs_render_aniso_at(ovt, FA_NG, 0 - ybase, FA_CAMZ, tgtC, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, FA_BGR, FA_BGG, FA_BGB, vw, vh, focal)
430
431 // ARM 1: single view, the ambiguous one
432 fa_copy(ovw, ovt, FA_NG*st)
433 var mk: i64 = 0
434 while mk < FA_NG { ovw[mk*st] = ovw[mk*st] + FA_PERTURB; ovw[mk*st+1] = ovw[mk*st+1] - FA_PERTURB; mk = mk + 1 }
435 var ms: i64 = 0
436 while ms < FA_STEPS {
437 gs_pos_grad_step_aniso(ovw, FA_NG, tgtA, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1)
438 ms = ms + 1
439 }
440 let err_sv: i64 = fa_poserr(ovw, ovt)
441
442 // ARM 2: the SAME start and step count, but the view CYCLES -- this is how 3DGS actually trains,
443 // one view per iteration, so multi-view costs no extra machinery here, only different targets.
444 fa_copy(ovw, ovt, FA_NG*st)
445 mk = 0
446 while mk < FA_NG { ovw[mk*st] = ovw[mk*st] + FA_PERTURB; ovw[mk*st+1] = ovw[mk*st+1] - FA_PERTURB; mk = mk + 1 }
447 ms = 0
448 while ms < FA_STEPS {
449 let phase: i64 = ms - (ms/FA_VIEWS)*FA_VIEWS
450 if phase == 0 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtA, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1) }
451 if phase == 1 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtB, ybase, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1) }
452 if phase == 2 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtC, 0 - ybase, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 1) }
453 ms = ms + 1
454 }
455 let err_mv: i64 = fa_poserr(ovw, ovt)
456
457 // ---- T14 THE INDIRECT TERM, RE-MEASURED UNDER MULTI-VIEW ------------------------------------
458 // Its single-view verdict was non-beneficial (79 direct vs 100 with indirect) and I recorded that
459 // as UNRESOLVED rather than absent, keeping the three-arm selector so this would cost no code
460 // motion. Resolving it here: the ray-stacked multi-view arm is re-run with usetrans=0 and 2 beside
461 // the =1 result above. This is where it should matter most -- deep overlap AND enough views for the
462 // gradient to have something real to correct -- so a null result here is a genuine answer, not a
463 // fixture artefact. NOTHING is asserted about which wins; the numbers are published and the tooth
464 // asserts only that all three arms genuinely ran on one fixture from one start.
465 fa_copy(ovw, ovt, FA_NG*st)
466 mk = 0
467 while mk < FA_NG { ovw[mk*st] = ovw[mk*st] + FA_PERTURB; ovw[mk*st+1] = ovw[mk*st+1] - FA_PERTURB; mk = mk + 1 }
468 ms = 0
469 while ms < FA_STEPS {
470 let ph0: i64 = ms - (ms/FA_VIEWS)*FA_VIEWS
471 if ph0 == 0 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtA, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 0) }
472 if ph0 == 1 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtB, ybase, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 0) }
473 if ph0 == 2 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtC, 0 - ybase, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 0) }
474 ms = ms + 1
475 }
476 let mv_ap: i64 = fa_poserr(ovw, ovt)
477 fa_copy(ovw, ovt, FA_NG*st)
478 mk = 0
479 while mk < FA_NG { ovw[mk*st] = ovw[mk*st] + FA_PERTURB; ovw[mk*st+1] = ovw[mk*st+1] - FA_PERTURB; mk = mk + 1 }
480 ms = 0
481 while ms < FA_STEPS {
482 let ph2: i64 = ms - (ms/FA_VIEWS)*FA_VIEWS
483 if ph2 == 0 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtA, 0, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 2) }
484 if ph2 == 1 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtB, ybase, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 2) }
485 if ph2 == 2 { gs_pos_grad_step_aniso(ovw, FA_NG, tgtC, 0 - ybase, FA_CAMZ, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, gradbuf, wnorm, vw, vh, 2) }
486 ms = ms + 1
487 }
488 let mv_full: i64 = fa_poserr(ovw, ovt)
489 gv_puts(" RAY-STACKED FIT (every surfel on one ray, same start pos_err " as *u8); gv_num(FA_PERTURB*2)
490 gv_puts("): single-view -> " as *u8); gv_num(err_sv)
491 gv_puts(" | 3-view -> " as *u8); gv_num(err_mv)
492 gv_puts(" | floor=" as *u8); gv_num(wpp); gv_puts("\n" as *u8)
493 gv_check("T12 fixture-reached-the-condition: the single-view arm on a ray-stacked scene really is above the pixel floor, so there is something for extra views to recover" as *u8, err_sv > wpp, ctr)
494 gv_check("T13 THE HYPOTHESIS, TESTED: extra views COLLAPSE the ray-stacked residual that no gradient term could fix -- confirming the rise is missing INFORMATION, not a missing derivative" as *u8, err_mv < err_sv, ctr)
495 gv_puts(" INDIRECT TERM UNDER MULTI-VIEW (same fixture, same start, 3 views): approximation -> " as *u8); gv_num(mv_ap)
496 gv_puts(" | direct T -> " as *u8); gv_num(err_mv)
497 gv_puts(" | direct+INDIRECT -> " as *u8); gv_num(mv_full)
498 gv_puts(" | floor=" as *u8); gv_num(wpp); gv_puts("\n" as *u8)
499 // ⚠⚠MY OWN VACUOUS TOOTH, CAUGHT BY THE NUMBER IT LET THROUGH. v1 asserted only `mv_full > 0` and
500 // PASSED on 46,128,546,235 -- a divergence ten orders of magnitude past a 52-pixel floor. Any
501 // garbage is greater than zero. That is precisely the defect this gate exists to prevent, committed
502 // by its own author, and the bound is now the only one that means anything here: A FIT THAT ENDS
503 // WORSE THAN IT BEGAN HAS DIVERGED. The start error is known exactly (the perturbation), so the
504 // bound is DERIVED, not chosen.
505 // ★AND THE RESOLUTION IS NOW IN HAND, WHICH WAS THE POINT OF RE-MEASURING: usetrans=2 is not merely
506 // non-beneficial, it is NUMERICALLY UNSTABLE. Single-view hid it (100 against 79 reads as a mild
507 // loss); multi-view exposed it. It is quarantined in the organ header and must not ship until the
508 // instability is found. This tooth binds the two SHIPPING arms; the broken arm is reported only.
509 let startv: i64 = FA_PERTURB*2
510 var t14: i64 = 0
511 if mv_ap <= startv { if err_mv <= startv { if err_mv < mv_ap { t14 = 1 } } }
512 if mv_full > startv { gv_puts(" >>> usetrans=2 DIVERGED under multi-view (ended worse than it began): NOT SHIPPABLE, quarantined in the organ header\n" as *u8) }
513 gv_check("T14 the SHIPPING gradient arms are bounded and ordered under multi-view: neither ends worse than it began, and the direct-transmittance form beats the approximation -- the indirect arm is reported, never asserted on, because it DIVERGES" as *u8, t14, ctr)
514
515 return gv_verdict("NX-GSPLAT-FIT-ANISO" as *u8, ctr, "the quality path is a reconstructor: oriented surfels recover their position from the image, hold still at the optimum, and the transmittance approximation now has a measured price" as *u8)
516}