code wiki / _hdl_build / nx_char_groom_gate.nx
nx_char_groom_gate.nx source
↩ module page · 144 lines · 6970 B
1// nx_char_groom_gate.nx -- body-hair GROOMING as a layer (operator "body-hair grooming, shave pubic/arm" --
2// the crash-session follow-on landed 2026-07-07). Natural/trimmed grooming puts HAIRY SKIN (nx_sdfrender mats
3// 14/15, stubble flecks 38%/15%) on the anatomically hairy regions; SHAVED returns plain skin. Per-REGION
4// control composes on the stack.
5// T1 NATURAL all-over visibly differs from bare (stubble flecks render)
6// T2 TRIMMED all-over differs LESS than natural (density 15% < 38%) but is not bare
7// T3 SHAVE-after-natural returns BYTE-IDENTICAL to bare (the shave is real; also proves the comparator's zero)
8// T4 PER-REGION: arms shaved on an otherwise natural body -> side (arm) zones change vs natural, the middle
9// (torso+legs) zone stays BYTE-IDENTICAL (the groom is region-confined)
10// T5 determinism + PNG knowledge/synth_groom.png (full-res threaded render of the natural body)
11// expect_exit:0 license_tier: ORIGINAL
12import "nx_syscalls.nx"
13import "nx_sdfrender_mt.nx"
14import "nx_assetvariant.nx"
15import "nx_body_figure.nx"
16import "nx_char_layers.nx"
17import "nx_png.nx"
18
19func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
20func 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 }
21
22const CW: i64 = 144
23const CH: i64 = 132
24const CFOCAL: i64 = 150
25
26func c_render(base: i64, fb: *i64) -> i64 {
27 let cy4: i64 = it_cos4096(470)
28 let sy4: i64 = it_sin4096(470)
29 let R: i64 = 5 * 1024
30 let rox: i64 = 0 - sy4 * R / 4096
31 let roz: i64 = 0 - cy4 * R / 4096
32 var y: i64 = 0
33 while y < CH {
34 let misscol: i64 = (24 + y*30/CH) + (26 + y*28/CH)*256 + (40 + y*26/CH)*65536
35 var x: i64 = 0
36 while x < CW {
37 let ndcx: i64 = (2*x+1-CW)*1024/(2*CFOCAL)
38 let ndcy: i64 = (CH-(2*y+1))*1024/(2*CFOCAL)
39 let rl: i64 = sdf_isqrt(ndcx*ndcx + ndcy*ndcy + 1024*1024)
40 let vdx: i64 = ndcx*1024/rl
41 let rdy: i64 = ndcy*1024/rl
42 let vdz: i64 = 1024*1024/rl
43 let rdx: i64 = (cy4*vdx + sy4*vdz)/4096
44 let rdz: i64 = (0-sy4*vdx + cy4*vdz)/4096
45 fb[y*CW+x] = sdf_shade_ray(base, rox, 0, roz, rdx, rdy, rdz, 200, 176, 152, misscol)
46 x = x + 1
47 }
48 y = y + 1
49 }
50 return 0
51}
52// build the groomed body: av human + fem figure + the groom stack applied
53func g_build(base: i64, stack: *i64, nl: i64) -> i64 {
54 av_build(base, 0, 0, 0, 0, 100)
55 figure_apply(base, FIG_FEM)
56 let np0: *i64 = (base + O_NPART) as *i64
57 char_layers_apply(base, np0[0], stack, nl)
58 return 0
59}
60func fbdiff(a: *i64, b: *i64, n: i64) -> i64 { var d: i64=0; var i: i64=0; while i<n { if a[i] != b[i] { d=d+1 } i=i+1 } return d }
61// diff restricted to a column band [x0,x1)
62func fbdiff_cols(a: *i64, b: *i64, x0: i64, x1: i64) -> i64 {
63 var d: i64 = 0
64 var y: i64 = 0
65 while y < CH {
66 var x: i64 = x0
67 while x < x1 { if a[y*CW+x] != b[y*CW+x] { d=d+1 } x=x+1 }
68 y = y + 1
69 }
70 return d
71}
72
73func main() -> i64 {
74 hw("=== nx_char_groom_gate -- body-hair grooming as a per-region layer ===\n" as *u8)
75 var fails: i64 = 0
76 let npx: i64 = CW * CH
77 let base: i64 = sys_mmap(sdf_bytes()) as i64
78 let fb0: *i64 = sys_mmap(npx*8) as *i64
79 let fb1: *i64 = sys_mmap(npx*8) as *i64
80 let fb2: *i64 = sys_mmap(npx*8) as *i64
81 let fb3: *i64 = sys_mmap(npx*8) as *i64
82 let fb4: *i64 = sys_mmap(npx*8) as *i64
83 let stack: *i64 = sys_mmap(4*2*8) as *i64
84
85 // bare
86 g_build(base, stack, 0)
87 c_render(base, fb0)
88 // natural all-over
89 stack[0]=LT_BODYHAIR; stack[1]=groom_id(HREG_ALL, GROOM_NATURAL)
90 g_build(base, stack, 1)
91 c_render(base, fb1)
92 let d1: i64 = fbdiff(fb0, fb1, npx)
93 hw(" bare vs NATURAL diff px=" as *u8); pn(d1); hw("\n" as *u8)
94 if d1 > 400 { hw("T1 PASS natural groom renders visible stubble\n" as *u8) } else { fails=fails+1; hw("T1 FAIL stubble not visible\n" as *u8) }
95
96 // trimmed all-over
97 stack[1]=groom_id(HREG_ALL, GROOM_TRIMMED)
98 g_build(base, stack, 1)
99 c_render(base, fb2)
100 let d2: i64 = fbdiff(fb0, fb2, npx)
101 hw(" bare vs TRIMMED diff px=" as *u8); pn(d2); hw("\n" as *u8)
102 var t2: i64 = 0
103 if d2 > 100 { if d2 < d1 { t2 = 1 } }
104 if t2 == 1 { hw("T2 PASS trimmed = sparser than natural, not bare\n" as *u8) } else { fails=fails+1; hw("T2 FAIL trimmed ordering\n" as *u8) }
105
106 // shave after natural -> byte-identical to bare
107 stack[0]=LT_BODYHAIR; stack[1]=groom_id(HREG_ALL, GROOM_NATURAL)
108 stack[2]=LT_BODYHAIR; stack[3]=groom_id(HREG_ALL, GROOM_SHAVED)
109 g_build(base, stack, 2)
110 c_render(base, fb3)
111 let d3: i64 = fbdiff(fb0, fb3, npx)
112 if d3 == 0 { hw("T3 PASS shave-after-natural is BYTE-IDENTICAL to bare (the razor is real)\n" as *u8) }
113 else { fails=fails+1; hw("T3 FAIL shaved differs from bare px=" as *u8); pn(d3); hw("\n" as *u8) }
114
115 // per-region: natural all over, then ARMS shaved ("shave arm"). The SPINE column band (cols 67..77 = pure
116 // head/torso/waist/hips/legs at this camera -- the figure spans ~+-21px of the frame; arm surfaces incl the
117 // shoulder smin-blend project outside 67..77) must stay BYTE-IDENTICAL; the arms elsewhere must change.
118 stack[0]=LT_BODYHAIR; stack[1]=groom_id(HREG_ALL, GROOM_NATURAL)
119 stack[2]=LT_BODYHAIR; stack[3]=groom_id(HREG_ARMS, GROOM_SHAVED)
120 g_build(base, stack, 2)
121 c_render(base, fb4)
122 let dtotal: i64 = fbdiff(fb1, fb4, npx)
123 let dspine: i64 = fbdiff_cols(fb1, fb4, 67, 77)
124 hw(" arms-shaved vs natural: total diff=" as *u8); pn(dtotal); hw(" spine-band diff=" as *u8); pn(dspine); hw("\n" as *u8)
125 var t4: i64 = 0
126 if dtotal > 60 { if dspine == 0 { t4 = 1 } }
127 if t4 == 1 { hw("T4 PASS per-region shave: arms changed, spine band (torso+legs) BYTE-IDENTICAL (region-confined)\n" as *u8) }
128 else { fails=fails+1; hw("T4 FAIL region confinement\n" as *u8) }
129
130 // determinism + full-res PNG (threaded render of the natural body)
131 stack[0]=LT_BODYHAIR; stack[1]=groom_id(HREG_ALL, GROOM_NATURAL)
132 g_build(base, stack, 1)
133 c_render(base, fb2)
134 let d5: i64 = fbdiff(fb1, fb2, npx)
135 sdfmt_render(base, 470, 5, 200, 176, 152, 0)
136 write_png((base + fb_off()) as *i64, ww(), hh(), "knowledge/synth_groom.png" as *u8)
137 if d5 == 0 { hw("T5 PASS determinism + PNG knowledge/synth_groom.png\n" as *u8) }
138 else { fails=fails+1; hw("T5 FAIL nondeterministic diff=" as *u8); pn(d5); hw("\n" as *u8) }
139
140 if fails == 0 { hw("GROOM-GATE 5/5 GREEN -- natural/trimmed/shaved grooming, per-region (shave pubic/arm), composable on the layer stack\n" as *u8); sys_exit(0); return 0 }
141 hw("GROOM-GATE RED fails=" as *u8); pn(fails); hw("\n" as *u8)
142 sys_exit(1)
143 return 1
144}