code wiki / _hdl_build / nx_gsplat_gate.nx
nx_gsplat_gate.nx source
↩ module page · 131 lines · 7540 B
1// nx_gsplat_gate.nx -- prove the sovereign 3D Gaussian Splatting renderer (the frontier rep). Integer, no float,
2// no trained weights.
3// T1 SPLAT FALLOFF: one Gaussian renders a soft blob -- centre bright, fading radially to background (the Gaussian)
4// T2 ALPHA COMPOSITE: two overlapping semi-transparent Gaussians BLEND (the overlap colour is a mix of both)
5// T3 ★DEPTH SORT (the load-bearing correctness): a near opaque Gaussian OCCLUDES a far one; SWAP their depths ->
6// the result flips (near colour wins) -- proves front-to-back sorting + compositing is real
7// T4 a Gaussian POINT CLOUD (sphere) renders a coherent soft ball + determinism + PNG knowledge/nx_gsplat.png
8// license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_itrig.nx"
11import "nx_png.nx"
12import "nx_gsplat.nx"
13
14func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
15func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
16func lum(px: i64) -> i64 { return (px & 255) + ((px >> 8) & 255) + ((px >> 16) & 255) }
17
18func main() -> i64 {
19 hw("=== nx_gsplat_gate -- sovereign 3D Gaussian Splatting (integer, no float, no trained weights) ===\n" as *u8)
20 var fails: i64 = 0
21 let W: i64 = gs_w()
22 let H: i64 = gs_h()
23 let npx: i64 = W * H
24 let NGX: i64 = 2048
25 let gauss: *i64 = sys_mmap(NGX*8*8) as *i64
26 let fb: *i64 = sys_mmap(npx*8) as *i64
27 let acc: *i64 = sys_mmap(npx*3*8) as *i64
28 let trans: *i64 = sys_mmap(npx*8) as *i64
29 let depth: *i64 = sys_mmap(NGX*8) as *i64
30 let sxb: *i64 = sys_mmap(NGX*8) as *i64
31 let syb: *i64 = sys_mmap(NGX*8) as *i64
32 let sigb: *i64 = sys_mmap(NGX*8) as *i64
33 let order: *i64 = sys_mmap(NGX*8) as *i64
34 let count: *i64 = sys_mmap((gs_nb()+2)*8) as *i64
35 let explut: *i64 = sys_mmap(gs_expn()*8) as *i64
36 gs_build_explut(explut)
37 let cx: i64 = W/2
38 let cy: i64 = H/2
39
40 // T1 single white gaussian at origin
41 gs_set(gauss, 0, 0, 0, 0, 60, 240, 240, 240, 256)
42 gs_render(gauss, 1, 0, 4, fb, acc, trans, depth, sxb, syb, sigb, order, count, explut, 26, 28, 44)
43 let lc: i64 = lum(fb[cy*W+cx]) // centre
44 let ledge: i64 = lum(fb[(cy-9)*W+cx]) // ~1 sigma out (sig~8.6px at this depth)
45 let lbg: i64 = lum(fb[10*W+10]) // far background
46 hw(" falloff: centre lum="); pn(lc); hw(" edge="); pn(ledge); hw(" bg="); pn(lbg); hw("\n" as *u8)
47 var t1: i64 = 0
48 if lc > 600 { if ledge < lc { if ledge > lbg { t1 = 1 } } } // bright centre, fades, but still above bg near
49 if t1 == 1 { hw("T1 PASS Gaussian splat falloff (bright centre -> radial fade -> background)\n" as *u8) }
50 else { fails=fails+1; hw("T1 FAIL falloff\n" as *u8) }
51
52 // T2 two overlapping semi-transparent gaussians (red + green) -> blended overlap
53 gs_set(gauss, 0, 0-30, 0, 0, 70, 230, 20, 20, 150) // red, left, semi
54 gs_set(gauss, 1, 30, 0, 0, 70, 20, 230, 20, 150) // green, right, semi
55 gs_render(gauss, 2, 0, 4, fb, acc, trans, depth, sxb, syb, sigb, order, count, explut, 26, 28, 44)
56 let mid: i64 = fb[cy*W+cx] // overlap centre
57 let mr: i64 = mid & 255
58 let mg: i64 = (mid >> 8) & 255
59 hw(" overlap centre RGB r="); pn(mr); hw(" g="); pn(mg); hw("\n" as *u8)
60 var t2: i64 = 0
61 if mr > 40 { if mg > 40 { t2 = 1 } } // BOTH red and green present = a real blend
62 if t2 == 1 { hw("T2 PASS alpha compositing: overlapping splats blend (both colours in the overlap)\n" as *u8) }
63 else { fails=fails+1; hw("T2 FAIL no blend\n" as *u8) }
64
65 // T3 DEPTH SORT: near red (z-) opaque in FRONT of far blue (z+); both project to centre
66 gs_set(gauss, 0, 0, 0, 0-120, 55, 240, 30, 30, 245) // red, NEAR (smaller z at yaw0)
67 gs_set(gauss, 1, 0, 0, 120, 55, 30, 30, 240, 245) // blue, FAR
68 gs_render(gauss, 2, 0, 4, fb, acc, trans, depth, sxb, syb, sigb, order, count, explut, 26, 28, 44)
69 let a: i64 = fb[cy*W+cx]
70 let a_r: i64 = a & 255
71 let a_b: i64 = (a >> 16) & 255
72 // SWAP depths: red far, blue near
73 gs_set(gauss, 0, 0, 0, 120, 55, 240, 30, 30, 245) // red now FAR
74 gs_set(gauss, 1, 0, 0, 0-120, 55, 30, 30, 240, 245) // blue now NEAR
75 gs_render(gauss, 2, 0, 4, fb, acc, trans, depth, sxb, syb, sigb, order, count, explut, 26, 28, 44)
76 let c: i64 = fb[cy*W+cx]
77 let c_r: i64 = c & 255
78 let c_b: i64 = (c >> 16) & 255
79 hw(" depth sort: red-near -> centre r="); pn(a_r); hw(" b="); pn(a_b); hw(" | blue-near -> r="); pn(c_r); hw(" b="); pn(c_b); hw("\n" as *u8)
80 var t3: i64 = 0
81 if a_r > a_b { if c_b > c_r { t3 = 1 } } // near colour wins in each case; the flip proves sort
82 if t3 == 1 { hw("T3 PASS depth sort + occlusion: the NEAR splat wins, and swapping depths FLIPS the result\n" as *u8) }
83 else { fails=fails+1; hw("T3 FAIL depth ordering\n" as *u8) }
84
85 // T4 a sphere of gaussians -> a soft ball
86 var n: i64 = 0
87 var iu: i64 = 0
88 while iu < 24 { // 24 rings x 32 = 768 gaussians on a sphere r=300
89 let theta: i64 = iu * 6434 / 24 // 0..pi (it4096: pi~12868)
90 let st: i64 = it_sin4096(theta)
91 let ct: i64 = it_cos4096(theta)
92 var iv: i64 = 0
93 while iv < 32 {
94 let phi: i64 = iv * 12868 * 2 / 32 // 0..2pi
95 let sp: i64 = it_sin4096(phi)
96 let cp: i64 = it_cos4096(phi)
97 let x: i64 = 300 * st / 4096 * cp / 4096
98 let y: i64 = 300 * ct / 4096
99 let z: i64 = 300 * st / 4096 * sp / 4096
100 // simple lambert-ish shade from a light at (+x,+y,-z)
101 var shade: i64 = 120 + (x + y - z) / 6
102 if shade < 60 { shade = 60 }
103 if shade > 250 { shade = 250 }
104 gs_set(gauss, n, x, y, z, 26, shade, shade*180/255, shade*150/255, 210)
105 n = n + 1
106 iv = iv + 1
107 }
108 iu = iu + 1
109 }
110 gs_render(gauss, n, 300, 4, fb, acc, trans, depth, sxb, syb, sigb, order, count, explut, 26, 28, 44)
111 var ball: i64 = 0
112 var pi: i64 = 0
113 while pi < npx { if lum(fb[pi]) > 110 { ball = ball + 1 } pi = pi + 1 } // non-background (bg lum=98)
114 hw(" sphere: "); pn(n); hw(" gaussians -> "); pn(ball); hw(" ball px (non-bg)\n" as *u8)
115 // determinism
116 let fb2: *i64 = sys_mmap(npx*8) as *i64
117 gs_render(gauss, n, 300, 4, fb2, acc, trans, depth, sxb, syb, sigb, order, count, explut, 26, 28, 44)
118 var diff: i64 = 0
119 pi = 0
120 while pi < npx { if fb[pi] != fb2[pi] { diff = diff + 1 } pi = pi + 1 }
121 write_png(fb, W, H, "knowledge/nx_gsplat.png" as *u8)
122 var t4: i64 = 0
123 if ball > 4000 { if diff == 0 { t4 = 1 } }
124 if t4 == 1 { hw("T4 PASS Gaussian point-cloud renders a coherent soft ball; deterministic + PNG knowledge/nx_gsplat.png\n" as *u8) }
125 else { fails=fails+1; hw("T4 FAIL ball="); pn(ball); hw(" diff="); pn(diff); hw("\n" as *u8) }
126
127 if fails == 0 { hw("GSPLAT-GATE 4/4 GREEN -- sovereign 3D Gaussian Splatting: splat falloff + alpha compositing + depth sort + point cloud, ALL INTEGER, no float, no trained weights (the frontier rep, ours)\n" as *u8); sys_exit(0); return 0 }
128 hw("GSPLAT-GATE RED fails="); pn(fails); hw("\n" as *u8)
129 sys_exit(1)
130 return 1
131}