code wiki / _hdl_build / nx_char_layers_gate.nx
nx_char_layers_gate.nx source
↩ module page · 76 lines · 4511 B
1// nx_char_layers_gate.nx -- the LAYER STACK proven: a nude base + [tunic + belt + hat] composes into one clothed
2// character, all layers rendering, on the photoreal shader. Proves (T1) the stack adds each layer's parts, (T2)
3// multiple layer materials render (crimson cloth from tunic+hat, steel from the belt), (T3) the stack reads as a
4// covering outfit (delivered tier = clothed). Emits knowledge/synth_layered.png. expect_exit:0 ORIGINAL
5import "nx_syscalls.nx"
6import "nx_sdfrender.nx"
7import "nx_assetvariant.nx"
8import "nx_body_figure.nx"
9import "nx_char_layers.nx"
10import "nx_png.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 }
14
15const LGW: i64 = 144
16const LGH: i64 = 132
17const LGFOCAL: i64 = 150
18
19func lg_render(base: i64, fb: *i64) -> i64 {
20 let cy4: i64 = it_cos4096(470); let sy4: i64 = it_sin4096(470)
21 let R: i64 = 5 * 1024
22 let rox: i64 = 0 - sy4 * R / 4096; let roz: i64 = 0 - cy4 * R / 4096
23 var y: i64 = 0
24 while y < LGH {
25 let misscol: i64 = (24 + y*30/LGH) + (26 + y*28/LGH)*256 + (40 + y*26/LGH)*65536
26 var x: i64 = 0
27 while x < LGW {
28 let ndcx: i64 = (2*x+1-LGW)*1024/(2*LGFOCAL); let ndcy: i64 = (LGH-(2*y+1))*1024/(2*LGFOCAL)
29 let rl: i64 = sdf_isqrt(ndcx*ndcx + ndcy*ndcy + 1024*1024)
30 let vdx: i64 = ndcx*1024/rl; let rdy: i64 = ndcy*1024/rl; let vdz: i64 = 1024*1024/rl
31 let rdx: i64 = (cy4*vdx + sy4*vdz)/4096; let rdz: i64 = (0-sy4*vdx + cy4*vdz)/4096
32 fb[y*LGW+x] = sdf_shade_ray(base, rox, 0, roz, rdx, rdy, rdz, 200, 176, 152, misscol)
33 x = x + 1
34 }
35 y = y + 1
36 }
37 return 0
38}
39func count_crimson(fb: *i64, n: i64) -> i64 { var c: i64=0; var i: i64=0; while i<n { let col: i64=fb[i]; let r: i64=col&255; let g: i64=(col>>8)&255; let b: i64=(col>>16)&255; if r>g+55 { if r>b+45 { c=c+1 } } i=i+1 } return c }
40func count_steel(fb: *i64, n: i64) -> i64 { var c: i64=0; var i: i64=0; while i<n { let col: i64=fb[i]; let r: i64=col&255; let g: i64=(col>>8)&255; let b: i64=(col>>16)&255; if r>95 { if g>95 { if b>95 { var d: i64=r-b; if d<0{d=0-d} if d<22 { c=c+1 } } } } i=i+1 } return c }
41
42func main() -> i64 {
43 hw("=== nx_char_layers_gate -- nude base + [tunic + belt + hat] composed into one character ===\n" as *u8)
44 let base: i64 = sys_mmap(sdf_bytes()) as i64
45 let fb: *i64 = sys_mmap(LGW * LGH * 8) as *i64
46 var fails: i64 = 0
47
48 // the ordered layer stack: tunic (outfit) -> belt -> hat (accessories)
49 let stack: *i64 = sys_mmap(6 * 2 * 8) as *i64
50 stack[0]=LT_OUTFIT; stack[1]=OF_TUNIC
51 stack[2]=LT_ACCESSORY; stack[3]=ACC_BELT
52 stack[4]=LT_ACCESSORY; stack[5]=ACC_HAT
53 let nl: i64 = 3
54
55 av_build(base, 0, 0, 0, 0, 100)
56 figure_apply(base, FIG_FEM)
57 let np0: *i64 = (base + O_NPART) as *i64
58 let nbase: i64 = np0[0]
59 let nfin: i64 = char_layers_apply(base, nbase, stack, nl)
60 hw(" base parts="); pn(nbase); hw(" -> after "); pn(nl); hw(" layers="); pn(nfin); hw(" (tunic 4 + belt 1 + hat 1)\n" as *u8)
61 if nfin == nbase + 6 { hw("T1 PASS the stack applied every layer's geometry\n" as *u8) } else { fails=fails+1; hw("T1 FAIL expected +6 parts\n" as *u8) }
62
63 lg_render(base, fb)
64 write_png(fb, LGW, LGH, "knowledge/synth_layered.png" as *u8)
65 let cr: i64 = count_crimson(fb, LGW*LGH)
66 let st: i64 = count_steel(fb, LGW*LGH)
67 hw(" rendered knowledge/synth_layered.png: crimson(tunic+hat)="); pn(cr); hw(" steel(belt)="); pn(st); hw("\n" as *u8)
68 if cr > 200 { if st > 40 { hw("T2 PASS multiple layer materials render together (cloth + metal)\n" as *u8) } else { fails=fails+1; hw("T2 FAIL belt not visible\n" as *u8) } }
69 else { fails=fails+1; hw("T2 FAIL cloth not visible\n" as *u8) }
70
71 if stack_has_outfit(stack, nl) == 1 { hw("T3 PASS stack reads as covering (delivered tier = clothed)\n" as *u8) } else { fails=fails+1; hw("T3 FAIL outfit not detected\n" as *u8) }
72
73 if fails == 0 { hw("CHAR-LAYERS-GATE 3/3 GREEN -- ordered layer stack (base + outfit + accessories) composes; extensible to makeup/other\n" as *u8); sys_exit(0); return 0 }
74 hw("CHAR-LAYERS-GATE RED fails="); pn(fails); hw("\n" as *u8)
75 sys_exit(1); return 1
76}