code wiki / _hdl_build / nx_face_style_gate.nx

nx_face_style_gate.nx source

↩ module page · 211 lines · 9916 B

1// nx_face_style_gate.nx -- HAIRSTYLES + the makeup follow-ons (eyeshadow lid-parts, blush cheek-apples) on the 2// detailed face (the crash-session callouts, landed 2026-07-07). 3// T1 hairstyle VOLUME ordering at a 3/4 view: bald < pixie < bob < long (dark-warm hair px, with margins) 4// T2 explicit HS_BOB == the sdf_face default, BYTE-IDENTICAL (negative control: the id system adds nothing) 5// T3 PONYTAIL visibly differs from bob (the tail renders) 6// T4 EYESHADOW: on-vs-off visibly differs AND the plum-pixel DELTA is positive (delta vs the off-render, so the 7// blue iris cannot fake it) 8// T5 BLUSH cheek-apples: on-vs-off differs, majority of the change in the lower face (the apples, not the 9// under-eye shadow zone that killed the v0 recolor) 10// T6 PERSON graft carries the hairstyle (sdf_person2 long vs bob differ) 11// T7 determinism + PNG knowledge/face_style.png (threaded full-res: long hair + glam makeup) 12// expect_exit:0 license_tier: ORIGINAL 13import "nx_syscalls.nx" 14import "nx_sdfrender_mt.nx" 15import "nx_makeup.nx" 16import "nx_png.nx" 17 18func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19func 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 } 20 21const CW: i64 = 144 22const CH: i64 = 132 23const CFOCAL: i64 = 150 24 25func c_render2(base: i64, fb: *i64, yaw: i64, camz: i64) -> i64 { 26 let cy4: i64 = it_cos4096(yaw) 27 let sy4: i64 = it_sin4096(yaw) 28 let R: i64 = camz * 1024 29 let rox: i64 = 0 - sy4 * R / 4096 30 let roz: i64 = 0 - cy4 * R / 4096 31 var y: i64 = 0 32 while y < CH { 33 let misscol: i64 = (24 + y*30/CH) + (26 + y*28/CH)*256 + (40 + y*26/CH)*65536 34 var x: i64 = 0 35 while x < CW { 36 let ndcx: i64 = (2*x+1-CW)*1024/(2*CFOCAL) 37 let ndcy: i64 = (CH-(2*y+1))*1024/(2*CFOCAL) 38 let rl: i64 = sdf_isqrt(ndcx*ndcx + ndcy*ndcy + 1024*1024) 39 let vdx: i64 = ndcx*1024/rl 40 let rdy: i64 = ndcy*1024/rl 41 let vdz: i64 = 1024*1024/rl 42 let rdx: i64 = (cy4*vdx + sy4*vdz)/4096 43 let rdz: i64 = (0-sy4*vdx + cy4*vdz)/4096 44 fb[y*CW+x] = sdf_shade_ray(base, rox, 0, roz, rdx, rdy, rdz, 236, 180, 156, misscol) 45 x = x + 1 46 } 47 y = y + 1 48 } 49 return 0 50} 51func 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 } 52// dark-warm px = hair-ish (dark, red>=blue, not green-shifted). Shadowed skin also matches, but it is ~constant 53// across hairstyle variants, so ORDERING comparisons stay valid. 54func count_hair(fb: *i64, n: i64) -> i64 { 55 var c: i64 = 0 56 var i: i64 = 0 57 while i < n { 58 let col: i64 = fb[i] 59 let r: i64 = col & 255 60 let g: i64 = (col >> 8) & 255 61 let b: i64 = (col >> 16) & 255 62 if r + g + b < 430 { if r > b { if r + 8 >= g { if r > 30 { c = c + 1 } } } } 63 i = i + 1 64 } 65 return c 66} 67// plum px = eyeshadow signature (blue over green, blue over red-ish, bright enough, red high enough to exclude 68// the blue-gray iris). Used as an ON-minus-OFF DELTA so any residual misclassification cancels. 69func count_plum(fb: *i64, n: i64) -> i64 { 70 var c: i64 = 0 71 var i: i64 = 0 72 while i < n { 73 let col: i64 = fb[i] 74 let r: i64 = col & 255 75 let g: i64 = (col >> 8) & 255 76 let b: i64 = (col >> 16) & 255 77 if b > g + 22 { if b > r { if r >= 78 { if b >= 100 { c = c + 1 } } } } 78 i = i + 1 79 } 80 return c 81} 82// diff restricted to rows [y0,y1) 83func fbdiff_rows(a: *i64, b: *i64, y0: i64, y1: i64) -> i64 { 84 var d: i64 = 0 85 var y: i64 = y0 86 while y < y1 { 87 var x: i64 = 0 88 while x < CW { if a[y*CW+x] != b[y*CW+x] { d=d+1 } x=x+1 } 89 y = y + 1 90 } 91 return d 92} 93 94func main() -> i64 { 95 hw("=== nx_face_style_gate -- hairstyles + eyeshadow lid-parts + blush cheek-apples ===\n" as *u8) 96 var fails: i64 = 0 97 let npx: i64 = CW * CH 98 let base: i64 = sys_mmap(sdf_bytes()) as i64 99 let fA: *i64 = sys_mmap(npx*8) as *i64 100 let fB: *i64 = sys_mmap(npx*8) as *i64 101 let fC: *i64 = sys_mmap(npx*8) as *i64 102 let fD: *i64 = sys_mmap(npx*8) as *i64 103 104 // T1 hairstyle volume ordering (3/4 view yaw 900, camz 4) 105 sdf_face(base) 106 c_render2(base, fA, 900, 4) 107 let h_bob: i64 = count_hair(fA, npx) 108 sdf_face(base) 109 sdf_face_hairstyle(base, HS_LONG) 110 c_render2(base, fB, 900, 4) 111 let h_long: i64 = count_hair(fB, npx) 112 sdf_face(base) 113 sdf_face_hairstyle(base, HS_PIXIE) 114 c_render2(base, fC, 900, 4) 115 let h_pixie: i64 = count_hair(fC, npx) 116 sdf_face(base) 117 sdf_face_hairstyle(base, HS_BALD) 118 c_render2(base, fD, 900, 4) 119 let h_bald: i64 = count_hair(fD, npx) 120 let dlong: i64 = fbdiff(fA, fB, npx) 121 let dpixie: i64 = fbdiff(fA, fC, npx) 122 hw(" hair px: bald=" as *u8); pn(h_bald); hw(" pixie=" as *u8); pn(h_pixie); hw(" bob=" as *u8); pn(h_bob) 123 hw(" pixie-diff=" as *u8); pn(dpixie); hw(" long-diff=" as *u8); pn(dlong); hw("\n" as *u8) 124 // REMOVAL is count-robust (bald strips ~30% of the dark-warm px). RESTYLES are pixel-DIFF-based: the 125 // dark-warm CLASSIFIER count is not a volume meter at few-percent deltas (curtains moved it 1381->1319; 126 // the A-R2 cap drop inverted pixie-vs-bob by 18px) -- diffs measure "visibly restyles" honestly. 127 var t1: i64 = 0 128 if h_bald + 200 < h_bob { if dpixie > 150 { if dlong > 400 { t1 = 1 } } } 129 if t1 == 1 { hw("T1 PASS hairstyles: BALD strips volume; PIXIE + LONG visibly restyle\n" as *u8) } 130 else { fails=fails+1; hw("T1 FAIL ordering\n" as *u8) } 131 132 // T2 explicit bob == default (negative control) 133 sdf_face(base) 134 sdf_face_hairstyle(base, HS_BOB) 135 c_render2(base, fB, 900, 4) 136 let dbob: i64 = fbdiff(fA, fB, npx) 137 if dbob == 0 { hw("T2 PASS explicit HS_BOB is BYTE-IDENTICAL to the sdf_face default\n" as *u8) } 138 else { fails=fails+1; hw("T2 FAIL bob differs px=" as *u8); pn(dbob); hw("\n" as *u8) } 139 140 // T3 ponytail differs from bob at a 60-degree view (yaw 4289 ~ 1.05 rad): the tail hangs BEHIND the head 141 // (near-frontal correctly hides it -- run 1 proved that with diff=0 at yaw 900); at 60deg its lobe clears 142 // the skull silhouette by ~340 units and must read plainly. 143 sdf_face(base) 144 c_render2(base, fC, 4289, 4) 145 sdf_face(base) 146 sdf_face_hairstyle(base, HS_PONY) 147 c_render2(base, fB, 4289, 4) 148 let dpony: i64 = fbdiff(fC, fB, npx) 149 hw(" pony vs bob diff px at 60deg=" as *u8); pn(dpony); hw("\n" as *u8) 150 if dpony > 100 { hw("T3 PASS ponytail renders (tail + tucked nape visible from the side)\n" as *u8) } 151 else { fails=fails+1; hw("T3 FAIL pony invisible\n" as *u8) } 152 153 // T4 eyeshadow (frontal yaw 200): on-vs-off diff + plum DELTA 154 sdf_face(base) 155 c_render2(base, fA, 200, 4) 156 let plum_off: i64 = count_plum(fA, npx) 157 sdf_face(base) 158 makeup_apply2(base, 27, 0, 0, 1) 159 c_render2(base, fB, 200, 4) 160 let plum_on: i64 = count_plum(fB, npx) 161 let dshadow: i64 = fbdiff(fA, fB, npx) 162 hw(" eyeshadow: diff px=" as *u8); pn(dshadow); hw(" plum off=" as *u8); pn(plum_off); hw(" on=" as *u8); pn(plum_on); hw("\n" as *u8) 163 var t4: i64 = 0 164 if dshadow > 60 { if plum_on > plum_off + 20 { t4 = 1 } } 165 if t4 == 1 { hw("T4 PASS eyeshadow lid-parts render plum on the lids\n" as *u8) } 166 else { fails=fails+1; hw("T4 FAIL eyeshadow\n" as *u8) } 167 168 // T5 blush cheek-apples: on-vs-off differs, majority of change in the LOWER face rows 169 sdf_face(base) 170 makeup_apply2(base, 27, 0, 1, 0) 171 c_render2(base, fC, 200, 4) 172 let dblush: i64 = fbdiff(fA, fC, npx) 173 let dlow: i64 = fbdiff_rows(fA, fC, CH/2, CH) 174 hw(" blush: diff px=" as *u8); pn(dblush); hw(" lower-half diff=" as *u8); pn(dlow); hw("\n" as *u8) 175 var t5: i64 = 0 176 if dblush > 60 { if dlow * 10 > dblush * 6 { t5 = 1 } } 177 if t5 == 1 { hw("T5 PASS blush apples render low + frontal (a flush, not an under-eye patch)\n" as *u8) } 178 else { fails=fails+1; hw("T5 FAIL blush\n" as *u8) } 179 180 // T6 the person graft carries a hairstyle (long vs default on the grafted head; 45-degree view so the 181 // back-fall is not hidden behind the head) 182 let scr: i64 = sys_mmap(sdf_bytes()) as i64 183 sdf_person(base, scr) 184 c_render2(base, fA, 3200, 5) 185 sdf_person2(base, scr, HS_LONG) 186 c_render2(base, fB, 3200, 5) 187 let dperson: i64 = fbdiff(fA, fB, npx) 188 hw(" person long-vs-bob diff px at 45deg=" as *u8); pn(dperson); hw("\n" as *u8) 189 if dperson > 40 { hw("T6 PASS sdf_person2 grafts the styled head (appended hair parts ride the copy)\n" as *u8) } 190 else { fails=fails+1; hw("T6 FAIL person hairstyle\n" as *u8) } 191 192 // T7 determinism + full-res threaded PNG (long + glam) 193 sdf_face(base) 194 var nfs: i64 = sdf_face_hairstyle(base, HS_LONG) 195 nfs = makeup_style2(base, nfs, MKUP_GLAM) 196 c_render2(base, fC, 300, 4) 197 sdf_face(base) 198 nfs = sdf_face_hairstyle(base, HS_LONG) 199 nfs = makeup_style2(base, nfs, MKUP_GLAM) 200 c_render2(base, fD, 300, 4) 201 let ddet: i64 = fbdiff(fC, fD, npx) 202 sdfmt_render(base, 300, 4, 236, 180, 156, 0) 203 write_png((base + fb_off()) as *i64, ww(), hh(), "knowledge/face_style.png" as *u8) 204 if ddet == 0 { hw("T7 PASS determinism + PNG knowledge/face_style.png (long hair + glam makeup)\n" as *u8) } 205 else { fails=fails+1; hw("T7 FAIL nondeterministic diff=" as *u8); pn(ddet); hw("\n" as *u8) } 206 207 if fails == 0 { hw("FACE-STYLE-GATE 7/7 GREEN -- 5 hairstyles + lid eyeshadow + apple blush, on the face AND the grafted person\n" as *u8); sys_exit(0); return 0 } 208 hw("FACE-STYLE-GATE RED fails=" as *u8); pn(fails); hw("\n" as *u8) 209 sys_exit(1) 210 return 1 211}