code wiki / _hdl_build / nx_persongen_gate.nx
nx_persongen_gate.nx source
↩ module page · 112 lines · 5446 B
1// nx_persongen_gate.nx -- ★prove the GENERATIVE PERSON FACTORY: seeds grow NOVEL people from the bones up, with
2// NO photo reference. DAZ-like parametric identity generation, sovereign.
3// T1 each seed generates a valid face that renders (non-background head present)
4// T2 ★NOVELTY: different seeds -> measurably DIFFERENT people (pairwise render L1 large -- distinct identities)
5// T3 ★DETERMINISM: the same seed -> the exact same person (a reproducible identity, bit-identical)
6// T4 gallery PNG knowledge/nx_persongen.png (6 distinct generated people, zero photos used)
7// license_tier: ORIGINAL expect_exit: 0
8import "nx_syscalls.nx"
9import "nx_png.nx"
10import "nx_persongen.nx"
11
12func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func 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 }
14func lum(px: i64) -> i64 { return (px&255)+((px>>8)&255)+((px>>16)&255) }
15func l1(a: *i64, b: *i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { var d: i64=(a[i]&255)-(b[i]&255); if d<0{d=0-d} var e: i64=((a[i]>>8)&255)-((b[i]>>8)&255); if e<0{e=0-e} var f: i64=((a[i]>>16)&255)-((b[i]>>16)&255); if f<0{f=0-f} s=s+d+e+f; i=i+1 } return s }
16
17const W: i64 = 512
18const H: i64 = 384
19const YAW: i64 = 200
20
21func main() -> i64 {
22 hw("=== nx_persongen_gate -- generative person factory: novel people from the bones up, NO photo ===\n" as *u8)
23 var fails: i64 = 0
24 let npx: i64 = W*H
25 let base: i64 = sys_mmap(sdf_bytes()) as i64
26 let fbp: *i64 = (base + fb_off()) as *i64
27
28 // 6 seeds -> 6 people; keep each render for novelty/gallery
29 let NP: i64 = 6
30 let seeds: *i64 = sys_mmap(NP*8) as *i64
31 seeds[0]=7; seeds[1]=42; seeds[2]=99; seeds[3]=256; seeds[4]=777; seeds[5]=2026
32 let tiles: *i64 = sys_mmap(NP*npx*8) as *i64
33 let skin: *i64 = sys_mmap(8*8) as *i64
34 let idv: *i64 = sys_mmap(8*8) as *i64
35
36 var validcount: i64 = 0
37 var p: i64 = 0
38 while p < NP {
39 persongen_build(base, seeds[p], skin, idv)
40 sdf_render(base, YAW, 4, skin[0], skin[1], skin[2])
41 // copy render into tile p
42 var k: i64 = 0
43 while k < npx { tiles[p*npx+k] = fbp[k]; k=k+1 }
44 // count head pixels
45 var head: i64 = 0
46 k = 0
47 while k < npx { if lum(fbp[k]) > 130 { head = head + 1 } k=k+1 }
48 hw(" person seed="); pn(seeds[p]); hw(" morphs[w,l,j,e,lip,n,ch]=[");
49 var q: i64 = 0
50 while q < 7 { pn(idv[q]); if q<6 { hw("," as *u8) } q=q+1 }
51 hw("] skin=("); pn(skin[0]); hw(","); pn(skin[1]); hw(","); pn(skin[2]); hw(") head_px="); pn(head); hw("\n" as *u8)
52 if head > 6000 { validcount = validcount + 1 }
53 p = p + 1
54 }
55 var t1: i64 = 0
56 if validcount == NP { t1 = 1 }
57 if t1 == 1 { hw("T1 PASS all 6 seeds generate a valid rendered face\n" as *u8) }
58 else { fails=fails+1; hw("T1 FAIL only "); pn(validcount); hw("/6 valid\n" as *u8) }
59
60 // T2 novelty: min pairwise L1 across all pairs must be large (distinct identities)
61 var minpair: i64 = 2000000000
62 var i2: i64 = 0
63 while i2 < NP {
64 var j2: i64 = i2 + 1
65 while j2 < NP {
66 let d: i64 = l1((tiles as i64 + i2*npx*8) as *i64, (tiles as i64 + j2*npx*8) as *i64, npx)
67 if d < minpair { minpair = d }
68 j2 = j2 + 1
69 }
70 i2 = i2 + 1
71 }
72 hw(" min pairwise render L1 across all 15 pairs: "); pn(minpair); hw("\n" as *u8)
73 var t2: i64 = 0
74 if minpair > 300000 { t2 = 1 } // every pair clearly distinct
75 if t2 == 1 { hw("T2 PASS NOVELTY: all 6 people are measurably different (distinct generated identities)\n" as *u8) }
76 else { fails=fails+1; hw("T2 FAIL two people too similar\n" as *u8) }
77
78 // T3 determinism: regenerate seed[2] -> must be bit-identical to its tile
79 persongen_build(base, seeds[2], skin, idv)
80 sdf_render(base, YAW, 4, skin[0], skin[1], skin[2])
81 var ddiff: i64 = 0
82 var k3: i64 = 0
83 while k3 < npx { if fbp[k3] != tiles[2*npx+k3] { ddiff = ddiff + 1 } k3=k3+1 }
84 var t3: i64 = 0
85 if ddiff == 0 { t3 = 1 }
86 if t3 == 1 { hw("T3 PASS DETERMINISM: the same seed reproduces the exact same person (bit-identical)\n" as *u8) }
87 else { fails=fails+1; hw("T3 FAIL seed not reproducible, ddiff="); pn(ddiff); hw("\n" as *u8) }
88
89 // T4 gallery 3x2
90 let GW: i64 = W*3
91 let GH: i64 = H*2
92 let gal: *i64 = sys_mmap(GW*GH*8) as *i64
93 p = 0
94 while p < NP {
95 let col: i64 = p % 3
96 let row: i64 = p / 3
97 var y: i64 = 0
98 while y < H {
99 var x: i64 = 0
100 while x < W { gal[(row*H+y)*GW + col*W + x] = tiles[p*npx + y*W + x]; x=x+1 }
101 y = y + 1
102 }
103 p = p + 1
104 }
105 write_png(gal, GW, GH, "knowledge/nx_persongen.png" as *u8)
106 hw("T4 gallery -> knowledge/nx_persongen.png (6 generated people, zero photos)\n" as *u8)
107
108 if fails == 0 { hw("PERSONGEN-GATE 4/4 GREEN -- a sovereign GENERATIVE PERSON FACTORY: seeds grow NOVEL, distinct, reproducible people from the bones up, NO photo reference (DAZ-like parametric identity, ours)\n" as *u8); sys_exit(0); return 0 }
109 hw("PERSONGEN-GATE RED fails="); pn(fails); hw("\n" as *u8)
110 sys_exit(1)
111 return 1
112}