code wiki / _hdl_build / nx_person_face_gate.nx

nx_person_face_gate.nx source

↩ module page · 134 lines · 6308 B

1// nx_person_face_gate.nx -- the emitted person gets the REAL HEAD: sdf_person = A-posed body + grafted 2// face/hair/eyes via PER-PART BLEND (O_KB2 -- limbs fuse at k130 while facial features hold k8 in the SAME 3// field). Proves: renders whole; the head carries EYES (blue-leaning material px, impossible from skin) and 4// HAIR (dark warm-brown px) at BODY scale; close-up frames the face; deterministic; critic stays honest. 5// license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_sdfrender.nx" 8import "nx_critic_axes.nx" 9import "nx_png.nx" 10 11func hw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12func pn(v: i64) -> i64 { 13 let b: *u8 = sys_mmap(32) as *u8 14 var x: i64 = v 15 var neg: i64 = 0 16 if x < 0 { neg = 1; x = 0 - x } 17 var i: i64 = 31 18 if x == 0 { b[i] = 48 as u8; i = i - 1 } 19 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 } 20 if neg == 1 { b[i] = 45 as u8; i = i - 1 } 21 sys_write(1, (b as i64 + i + 1) as *u8, 31 - i) 22 return 0 23} 24func eye_px(fb: *i64, w: i64, h: i64) -> i64 { 25 var n: i64 = 0 26 var i: i64 = 0 27 while i < w * h { 28 let c: i64 = fb[i] 29 let r: i64 = c & 255 30 let bl: i64 = (c >> 16) & 255 31 if bl > r + 20 { let l: i64 = ca_lum(c); if l > 40 { if l < 220 { n = n + 1 } } } 32 i = i + 1 33 } 34 return n 35} 36func hair_px(fb: *i64, w: i64, h: i64) -> i64 { 37 var n: i64 = 0 38 var i: i64 = 0 39 while i < w * h { 40 let c: i64 = fb[i] 41 let r: i64 = c & 255 42 let g: i64 = (c >> 8) & 255 43 let bl: i64 = (c >> 16) & 255 44 if r > g + 8 { if g > bl + 6 { let l: i64 = ca_lum(c); if l > 25 { if l < 105 { n = n + 1 } } } } 45 i = i + 1 46 } 47 return n 48} 49func fb_sum(fb: *i64, w: i64, h: i64) -> i64 { 50 var s: i64 = 0 51 var i: i64 = 0 52 while i < w * h { s = s + (fb[i] & 16777215); i = i + 1 } 53 return s 54} 55 56// heads-tall from the ACTUAL geometry: total silhouette height / skull vertical diameter (canon = 7-8 for an 57// adult; a stylized-attractive figure ~6.5-7). Returns heads*10 so we stay in integers. 58func heads10_of(base: i64) -> i64 { 59 let p: *i64 = (base + O_PARTS) as *i64 60 let npp: *i64 = (base + O_NPART) as *i64 61 var np: i64 = npp[0] 62 var top: i64 = 0 - 999999 63 var bot: i64 = 999999 64 var i: i64 = 0 65 while i < np { 66 let cy: i64 = p[i * 6 + 1] 67 let ry: i64 = p[i * 6 + 4] 68 if cy + ry > top { top = cy + ry } 69 if cy - ry < bot { bot = cy - ry } 70 i = i + 1 71 } 72 let head_diam: i64 = p[4] * 2 // part 0 = skull; ry is its vertical half-axis (chin->crown) 73 if head_diam <= 0 { return 0 } 74 return (top - bot) * 10 / head_diam 75} 76 77func main() -> i64 { 78 var fails: i64 = 0 79 let W: i64 = ww() 80 let H: i64 = hh() 81 hw("=== nx_person_face_gate -- the person gets the REAL head (per-part blend graft) ===\n" as *u8) 82 let base: i64 = sys_mmap(sdf_bytes()) as i64 83 let scr: i64 = sys_mmap(sdf_bytes()) as i64 84 let fb: *i64 = (base + fb_off()) as *i64 85 86 // --- full figure --- 87 sdf_person(base, scr) 88 sdf_render(base, 300, 5, 236, 180, 156) 89 let fg: i64 = ca_fgcount(fb, W, H) 90 let hfull: i64 = hair_px(fb, W, H) 91 write_png(fb, W, H, "knowledge/nx_person_full.png" as *u8) 92 hw(" full figure: fg=" as *u8); pn(fg); hw(" hair-px=" as *u8); pn(hfull); hw("\n" as *u8) 93 if fg > 25000 { hw("T1 PASS the person renders whole (body + grafted head)\n" as *u8) } 94 else { hw("T1 FAIL fg low\n" as *u8); fails = fails + 1 } 95 if hfull > 800 { hw("T2 PASS HAIR present at body scale (dark warm-brown px)\n" as *u8) } 96 else { hw("T2 FAIL hair-px=" as *u8); pn(hfull); hw("\n" as *u8); fails = fails + 1 } 97 98 // T2b PROPORTIONS: heads-tall from the actual geometry (base still holds the full figure here) 99 let h10: i64 = heads10_of(base) 100 hw(" proportions: heads-tall=" as *u8); pn(h10 / 10); hw("." as *u8); pn(h10 % 10); hw(" (adult canon 7-8; stylized-attractive ~6.5-7)\n" as *u8) 101 if h10 >= 60 { if h10 <= 82 { hw("T2b PASS adult proportions (was ~5.2 = childish big-head; now geometry-measured in range)\n" as *u8) } else { hw("T2b FAIL heads=" as *u8); pn(h10 / 10); hw(" too tall\n" as *u8); fails = fails + 1 } } 102 else { hw("T2b FAIL heads=" as *u8); pn(h10 / 10); hw(" head still too big\n" as *u8); fails = fails + 1 } 103 104 // --- head close-up (shift the model down so the fixed-height camera frames the head) --- 105 sdf_person(base, scr) 106 sdf_shift_y(base, 0 - 1360) 107 sdf_render(base, 200, 2, 236, 180, 156) 108 let epx: i64 = eye_px(fb, W, H) 109 let hpx: i64 = hair_px(fb, W, H) 110 let score: i64 = ca_score(fb, W, H) 111 write_png(fb, W, H, "knowledge/nx_person_head.png" as *u8) 112 hw(" head close-up: eye-px=" as *u8); pn(epx); hw(" hair-px=" as *u8); pn(hpx); hw(" critic=" as *u8); pn(score); hw("/1000 " as *u8); hw(ca_verdict(score)); hw("\n" as *u8) 113 if epx > 80 { hw("T3 PASS the person's EYES read (iris/pupil material px at body scale)\n" as *u8) } 114 else { hw("T3 FAIL eye-px=" as *u8); pn(epx); hw("\n" as *u8); fails = fails + 1 } 115 if hpx > 3000 { hw("T4 PASS the person's HAIR reads in close-up\n" as *u8) } 116 else { hw("T4 FAIL hair-px=" as *u8); pn(hpx); hw("\n" as *u8); fails = fails + 1 } 117 118 // --- determinism (same build+shift+render -> byte-identical frame) --- 119 let s1: i64 = fb_sum(fb, W, H) 120 sdf_person(base, scr) 121 sdf_shift_y(base, 0 - 1360) 122 sdf_render(base, 200, 2, 236, 180, 156) 123 let s2: i64 = fb_sum(fb, W, H) 124 if s1 == s2 { hw("T5 PASS deterministic (frame checksum identical on rebuild)\n" as *u8) } 125 else { hw("T5 FAIL determinism\n" as *u8); fails = fails + 1 } 126 127 // --- honesty ceiling --- 128 if score < 400 { hw("T6 PASS honest: still CLAY-tier (" as *u8); pn(score); hw("/1000) -- a stylized character, not photoreal; the ladder continues\n" as *u8) } 129 else { hw("T6 NOTE score " as *u8); pn(score); hw(" >= 400 -- eyeball it, do not over-trust\n" as *u8) } 130 131 if fails == 0 { hw("GATE GREEN: the person has the REAL head -- body-fuse and face-crisp coexist in ONE field via per-part blend. Eyeball nx_person_full.png + nx_person_head.png.\n" as *u8) } 132 else { hw("GATE RED fails=" as *u8); pn(fails); hw("\n" as *u8) } 133 return fails 134}