code wiki / _hdl_build / nx_gsplat_showcase.nx

nx_gsplat_showcase.nx source

↩ module page · 142 lines · 9229 B

1// nx_gsplat_showcase.nx -- PUBLISH the sovereign 3D Gaussian Splatting work (operator: "are you publishing?"). 2// Our anatomical base (nx_faceanat) -> surface-nets mesh (nx_meshgen) -> ANISOTROPIC surface Gaussians (surfels, 3// nx_gsplat) -> photo-coloured from the reference projection -> a TURNTABLE rendered by our own integer splatter. 4// This is exactly the 2024-2025 frontier pipeline (mesh/SMPL-X -> Gaussians -> splat), 100% sovereign: no WebGL, 5// no libraries, no trained weights (renderer). Emits a self-contained /gsplat page. license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_png.nx" 8import "nx_base64.nx" 9import "nx_jpeg_ascii.nx" 10import "nx_faceanat.nx" 11import "nx_meshgen.nx" 12import "nx_gsplat.nx" 13const P_MAGIC_1024: i64 = 1024 14const P_MAGIC_3217: i64 = 3217 15 16func hw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd, s, n); return 0 } 17 18func emit_frame(fb: *i64, fd: i64, tmp: *u8) -> i64 { 19 write_png(fb, gs_w(), gs_h(), tmp) 20 let lenp: *i64 = sys_mmap(16) as *i64 21 let png: *u8 = sys_read_file(tmp, lenp) 22 if (png as i64) == 0 { return 0 - 1 } 23 let plen: i64 = lenp[0] 24 let b64: *u8 = sys_mmap(plen*2+64) as *u8 25 let blen: i64 = b64_encode(png, plen, b64) 26 hw(fd, "'" as *u8); sys_write(fd, b64, blen); hw(fd, "',\n" as *u8) 27 return 0 28} 29 30const P_UC: i64 = 256 31const P_VC: i64 = 329 32const P_SU: i64 = 333 33const P_SV: i64 = 350 34const P_VLO: i64 = 240 35const P_VHI: i64 = 440 36 37func main() -> i64 { 38 let fd: i64 = sys_openat_wr("knowledge/gsplat.html\x00" as *u8, 0x1a4) 39 if fd < 0 { hw(2, "gsplat_showcase: open failed\n" as *u8); return 1 } 40 let W: i64 = gs_w() 41 let H: i64 = gs_h() 42 let npx: i64 = W*H 43 44 // emit the anatomical mesh 45 let base: i64 = sys_mmap(sdf_bytes()) as i64 46 let F: *i64 = sys_mmap((MG_N+1)*(MG_N+1)*(MG_N+1)*8) as *i64 47 let cubevi: *i64 = sys_mmap(MG_N*MG_N*MG_N*8) as *i64 48 let vbuf: *i64 = sys_mmap(MG_MAXV*3*8) as *i64 49 let fbuf: *i64 = sys_mmap(MG_MAXF*3*8) as *i64 50 let mo: *i64 = sys_mmap(16) as *i64 51 faceanat_build(base) 52 mg_build(base, F, cubevi, vbuf, fbuf, mo) 53 let nv: i64 = mo[0] 54 55 // decode reference for per-surfel colour 56 let szp: *i64 = sys_mmap(16) as *i64 57 let jpeg: *u8 = sys_read_file("knowledge/elara_face_hi.jpg" as *u8, szp) 58 var tex: i64 = 0; var tw: i64 = 0; var th: i64 = 0 59 if (jpeg as i64) != 0 { let rp: *i64=sys_mmap(8) as *i64; let wp: *i64=sys_mmap(8) as *i64; let hp: *i64=sys_mmap(8) as *i64; if nx_jpeg_decode_rgb(jpeg, szp[0], rp, wp, hp)==NX_JPEG_ASCII_OK { tex=rp[0]; tw=wp[0]; th=hp[0] } } 60 let rgb: *u8 = tex as *u8 61 62 // build the aniso surfel cloud ONCE (projection colour on front-band, shaded skin elsewhere) 63 let gauss: *i64 = sys_mmap(nv*12*8) as *i64 64 var vi: i64 = 0 65 while vi < nv { 66 let x: i64 = vbuf[vi*3]; let y: i64 = vbuf[vi*3+1]; let z: i64 = vbuf[vi*3+2] 67 let e: i64 = 12 68 let gx: i64 = sdf_eval(base,x+e,y,z)-sdf_eval(base,x-e,y,z) 69 let gy: i64 = sdf_eval(base,x,y+e,z)-sdf_eval(base,x,y-e,z) 70 let gz: i64 = sdf_eval(base,x,y,z+e)-sdf_eval(base,x,y,z-e) 71 let gl: i64 = gs_isqrt(gx*gx+gy*gy+gz*gz) 72 var nx: i64 = 0; var ny: i64 = 256; var nz: i64 = 0 73 if gl > 0 { nx=gx*256/gl; ny=gy*256/gl; nz=gz*256/gl } 74 var sh: i64 = 130 + (nx*(0-121)+ny*191+nz*(0-121))/256*90/256 75 if sh<70 {sh=70} if sh>255 {sh=255} 76 var cr: i64 = sh*236/255; var cg: i64 = sh*180/255; var cb: i64 = sh*156/255 77 if tex != 0 { if nz < 0 - 2 { 78 let u: i64 = P_UC + x*P_SU/P_MAGIC_1024 79 let v: i64 = P_VC - y*P_SV/P_MAGIC_1024 80 if v>=P_VLO { if v<P_VHI { if u>=1 { if u<tw-1 { if v<th-1 { 81 let o: i64 = (v*tw+u)*3 82 let pr: i64 = (rgb[o] as i64)&255; let pg: i64 = (rgb[o+1] as i64)&255; let pb: i64 = (rgb[o+2] as i64)&255 83 cr = pr*sh/210; cg = pg*sh/210; cb = pb*sh/210 // photo albedo * our shade 84 if cr>255{cr=255} if cg>255{cg=255} if cb>255{cb=255} 85 } } } } } 86 } } 87 gs_set_aniso(gauss, vi, x, y, z, nx, ny, nz, 34, cr, cg, cb, 235) 88 vi = vi + 1 89 } 90 91 // scratch 92 let fb: *i64 = sys_mmap(npx*8) as *i64 93 let acc: *i64 = sys_mmap(npx*3*8) as *i64 94 let trans: *i64 = sys_mmap(npx*8) as *i64 95 let depth: *i64 = sys_mmap(nv*8) as *i64 96 let sxb: *i64 = sys_mmap(nv*8) as *i64 97 let syb: *i64 = sys_mmap(nv*8) as *i64 98 let pa: *i64 = sys_mmap(nv*8) as *i64 99 let pb: *i64 = sys_mmap(nv*8) as *i64 100 let pc: *i64 = sys_mmap(nv*8) as *i64 101 let pdet: *i64 = sys_mmap(nv*8) as *i64 102 let order: *i64 = sys_mmap(nv*8) as *i64 103 let count: *i64 = sys_mmap((gs_nb()+2)*8) as *i64 104 let explut: *i64 = sys_mmap(gs_expn()*8) as *i64 105 gs_build_explut(explut) 106 let tmp: *u8 = "knowledge/_gsframe.png\x00" as *u8 107 108 hw(fd, "<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>Nishi 3D Gaussian Splatting -- the frontier photoreal-avatar rep, sovereign</title><style>html,body{margin:0;height:100%;background:#0b0d13;color:#cde;font-family:sans-serif;overflow-x:hidden}#wrap{display:flex;flex-direction:column;align-items:center;padding:14px}img{max-width:100vw;width:560px;border:1px solid #223;border-radius:6px;box-shadow:0 6px 24px #0008}h1{font-size:19px;margin:8px 0 2px;text-align:center}p{max-width:700px;text-align:center;color:#9ab;font-size:14px;line-height:1.5}.k{color:#8ef}</style></head><body><div id='wrap'>\n" as *u8) 109 hw(fd, "<h1>Nishi <span class='k'>3D Gaussian Splatting</span> &mdash; the 2025 frontier rep, on our <span class='k'>OWN</span> stack</h1>\n" as *u8) 110 hw(fd, "<p>The current SOTA for photoreal avatars (GaussianAvatars, HumanSplat, VRGaussianAvatar) renders a cloud of oriented 3D Gaussians. This is that pipeline, <b>100% sovereign</b>: our inside-out anatomical base &rarr; a surface-nets mesh &rarr; <b>anisotropic surface Gaussians</b> (surfels aligned to the surface normal, projected to 2D ellipses) &rarr; depth-sorted, alpha-composited by our <b>own integer splatter</b> &mdash; then photo-coloured from our Z-Image reference. <b>No WebGL, no libraries, no trained weights</b> (only a generator needs training; the renderer is fully ours). Honest tier: hand-placed surfels on the mesh, not yet gradient-fit to images (the generator rung); a stylized base, real frontier rendering.</p>\n" as *u8) 111 hw(fd, "<img id='v' alt='Gaussian-splatted face'>\n<p id='cap' class='k'>loading&hellip;</p>\n<script>\nconst F=[\n" as *u8) 112 113 // true 360 turntable: step = 2*IT_PI/8 = 25736/8 = 3217 (it_sin4096 period is 2*IT_PI). Start near-front. 114 var i: i64 = 0 115 while i < 8 { 116 gs_render_aniso(gauss, nv, 200 + i*P_MAGIC_3217, 4, fb, acc, trans, depth, sxb, syb, pa, pb, pc, pdet, order, count, explut, 26, 28, 44) 117 emit_frame(fb, fd, tmp) 118 i = i + 1 119 } 120 121 hw(fd, "];\nlet k=0;const v=document.getElementById('v'),cap=document.getElementById('cap');\n" as *u8) 122 hw(fd, "function step(){v.src='data:image/png;base64,'+F[k];cap.textContent='anisotropic Gaussian surfels, photo-coloured, our integer splatter -- turntable '+(k+1)+'/8';k=(k+1)%F.length;setTimeout(step,700);}\nstep();\n" as *u8) 123 hw(fd, "</script>\n" as *u8) 124 125 // ★THE GENERATOR fitting the REAL Elara photo (from nx_gsplat_elara_gate) 126 let ftlen: *i64 = sys_mmap(16) as *i64 127 let ftpng: *u8 = sys_read_file("knowledge/nx_gsplat_elara.png\x00" as *u8, ftlen) 128 if (ftpng as i64) != 0 { 129 let flen: i64 = ftlen[0] 130 let fb64: *u8 = sys_mmap(flen*2+64) as *u8 131 let fblen: i64 = b64_encode(ftpng, flen, fb64) 132 hw(fd, "<h1 style='margin-top:28px'>The <span class='k'>generator</span> &mdash; fitting Gaussians to the real photo</h1>\n" as *u8) 133 hw(fd, "<p>The other half of 3D Gaussian Splatting is the <b>optimizer</b> that fits the Gaussians to a target image &mdash; also sovereign + integer. A splatted pixel is <b>linear</b> in the Gaussian colours, so the image-loss gradient is <b>analytic</b> (no autograd, no float). Here the target is the <b>actual reference photograph</b>: 12,288 Gaussians start grey and gradient descent fits them to <b>reproduce it</b>. <b>Left</b>: the real photo. <b>Middle</b>: the grey start. <b>Right</b>: the fitted Gaussian splat &mdash; a recognizable reproduction (image loss down to 6%), rendered by our own integer splatter. Honest boundary: this is a <b>single-view</b> fit (a 3D-Gaussian representation of one 2D photo) &mdash; it reproduces the face from the front; a full 3D-consistent avatar from one photo needs single-image-3D reconstruction (a trained net), the next rung. The renderer + optimizer are entirely ours.</p>\n" as *u8) 134 hw(fd, "<img style='width:96vw;max-width:980px' alt='fit to the real photo: photo | grey start | fitted' src='data:image/png;base64," as *u8) 135 sys_write(fd, fb64, fblen) 136 hw(fd, "'>\n" as *u8) 137 } 138 hw(fd, "</div></body></html>\n" as *u8) 139 sys_close(fd) 140 hw(1, "nx_gsplat_showcase: wrote knowledge/gsplat.html (8-frame aniso-splat turntable, self-contained, no libs)\n" as *u8) 141 return 0 142}