nx_pets_voxel3d.nx
buildroot/runtime/nx_pets_voxel3d.nx
about
nx_pets_voxel3d.nx -- RUNG 2 of the Pixelmon-exceed ladder: TRUE 3D voxel terrain by composing
the team's CERTIFIED 3D math + z-buffered rasterizer. Replaces the rung-1 2.5D raycaster columns
with real perspective-projected, depth-occluded, directionally-lit cubes (Minecraft-class).
Composes (parts-composition doctrine -- I author ONLY the mesh/scene glue, not the math/raster):
nx_camera_q14 -- certified Q14 camera: perspective + yaw/pitch + mat4 mul + mat4*vec4.
nx_raster_triangle -- certified z-buffered Pineda rasterizer; u32 RGBA framebuffer that is
EXPLICITLY browser-ready (JS reads Uint32Array -> putImageData). The
alpha channel is an ambient/light multiplier -> per-face directional light.
(nx_voxel_mesh is still ABSENT per MINECRAFTCLONE_BITS_UP_GAPS Gap 8, so the cube-face meshing
here is the composition glue = tutor tooling, per the game-spec authorship law.)
Pipeline (the real hardware-up render path): world cube corner (Q14) -> MVP = P*V (certified
mat4) -> clip (certified mat4*vec4) -> perspective divide -> integer screen x,y + depth w ->
certified z-buffered triangle raster -> u32 framebuffer -> 24bpp BMP (last-mile image; the same
framebuffer feeds the browser canvas in the delivery rung).
BAKED gate (camera-independent correctness, no false green): z-occlusion (near tri hides far) +
projection (in-front projects centered, behind-camera is rejected, off-axis projects off-centre) +
scene-non-empty. Browser delivery of this exact framebuffer = the NAMED next rung.
license_tier: ORIGINAL
dependencies 4 imports · 0 importers
imports: nx_camera_q14.nxnx_raster_triangle.nxnx_perlin.nxnx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 26 | const NX_MAGIC_65536: i64 = 65536 |
| 27 | const NX_MAGIC_16777216: i64 = 16777216 |
| 28 | const NX_MAGIC_4096: i64 = 4096 |
| 29 | const NX_MAGIC_1024: i64 = 1024 |
| 30 | const NX_MAGIC_2048: i64 = 2048 |
| 31 | const NX_MAGIC_2147483647: i64 = 2147483647 |
| 32 | const NX_MAGIC_1103515: i64 = 1103515 |
| 33 | const NX_MAGIC_12345: i64 = 12345 |
| 34 | const NX_MAGIC_5000: i64 = 5000 |
| 35 | const NX_MAGIC_100000: i64 = 100000 |
| 36 | const NX_MAGIC_10000: i64 = 10000 |
| 37 | const NX_MAGIC_8000: i64 = 8000 |
| 38 | const NX_MAGIC_320000: i64 = 320000 |
| 39 | const NX_MAGIC_2835: i64 = 2835 |
| 40 | const NX_MAGIC_1337: i64 = 1337 |
| 41 | const NX_MAGIC_7777: i64 = 7777 |
| 42 | const NX_MAGIC_909090: i64 = 909090 |
| 43 | const NX_MAGIC_424242: i64 = 424242 |
| 44 | const NX_MAGIC_515151: i64 = 515151 |
| 45 | const NX_MAGIC_31337: i64 = 31337 |
| 46 | const NX_MAGIC_4000: i64 = 4000 |
| 47 | const NX_MAGIC_110000: i64 = 110000 |
| 48 | const NX_MAGIC_16384: i64 = 16384 |
| 50 | const NX_W: nx_int = 320 |
| 51 | const NX_H: nx_int = 240 |
| 52 | const NX_W2: nx_int = 160 |
| 53 | const NX_H2: nx_int = 120 |
| 54 | const NX_VQ: nx_int = 16384 |
functions
| 56 | func vp_pack(r: nx_int, g: nx_int, b: nx_int, a: nx_int) -> nx_int |
| 61 | func vp_project(mvp: *i64, wx: nx_int, wy: nx_int, wz: nx_int, scr: *i64) -> nx_int |
| 78 | func vp_tri(fb: *i64, zb: *i64, a: *i64, b: *i64, c: *i64, col: nx_int) -> nx_int |
| 91 | func vp_quad(fb: *i64, zb: *i64, p: *i64, a: nx_int, b: nx_int, c: nx_int, d: nx_int, col: nx_int) -> nx_int calls 1: vp_tri |
| 102 | func vp_h(ps: *PerlinState, x: nx_int, z: nx_int) -> nx_int |
| 111 | func vp_biome(bps: *PerlinState, h: nx_int, x: nx_int, z: nx_int) -> nx_int |
| 122 | func hget(hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int |
| 130 | func vp_ao(occ: nx_int) -> nx_int |
| 137 | func vp_occ(hgrid: *i64, gn: nx_int, h: nx_int, |
| 147 | func vp_aabb_floor(hgrid: *i64, gn: nx_int, x0: nx_int, z0: nx_int, x1: nx_int, z1: nx_int) -> nx_int |
| 161 | func vp_collide_y(hgrid: *i64, gn: nx_int, x0: nx_int, z0: nx_int, x1: nx_int, z1: nx_int, y: nx_int) -> nx_int |
| 168 | func vp_gen_chunk(ps: *PerlinState, cx: nx_int, cz: nx_int, out: *i64) -> nx_int |
| 178 | func vp_place(hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int |
| 183 | func vp_break(hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int |
| 190 | func vp_greedy_row(hrow: *i64, brow: *i64, n: nx_int) -> nx_int called by 1: main |
| 203 | func vp_struct_at(sps: *PerlinState, hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int |
| 214 | func vp_erode_pass(hg: *i64, gn: nx_int, talus: nx_int, delta: *i64) -> nx_int called by 1: main |
| 235 | func vp_ore(ops: *PerlinState, x: nx_int, z: nx_int, y: nx_int) -> nx_int |
| 243 | func vp_cave(cps: *PerlinState, x: nx_int, z: nx_int, y: nx_int) -> nx_int |
| 254 | func vp_bit(t: nx_int) -> nx_int |
| 260 | func vp_popcount4(m: nx_int) -> nx_int called by 1: vp_wfc_solve |
| 270 | func vp_wfc_allow(a: nx_int, b: nx_int) -> nx_int |
| 279 | func vp_wfc_prune(mask: *i64, src: nx_int, dst: nx_int) -> nx_int |
| 301 | func vp_wfc_solve(seed: nx_int, cells: *i64, mask: *i64, gn: nx_int) -> nx_int |
| 374 | func vp_pow2(i: nx_int) -> nx_int { var v: nx_int = 1; var k: nx_int = 0; while k < i { v = v * 2; k = k + 1 } return v } |
| 376 | func vp_mc_field(c: nx_int, r2: nx_int, x: nx_int, y: nx_int, z: nx_int) -> nx_int |
| 383 | func vp_mc_cx(i: nx_int) -> nx_int { if i == 1 { return 1 } if i == 2 { return 1 } if i == 5 { return 1 } if i == 6 { return 1 } return 0 } |
| 384 | func vp_mc_cy(i: nx_int) -> nx_int { if i == 2 { return 1 } if i == 3 { return 1 } if i == 6 { return 1 } if i == 7 { return 1 } return 0 } |
| 385 | func vp_mc_cz(i: nx_int) -> nx_int { if i == 4 { return 1 } if i == 5 { return 1 } if i == 6 { return 1 } if i == 7 { return 1 } return 0 } |
| 387 | func vp_mc_ea(e: nx_int) -> nx_int { if e == 0 { return 0 } if e == 1 { return 1 } if e == 2 { return 2 } if e == 3 { return 3 } if e == 4 { return 4 } if e == 5 { return 5 } if e == 6 { return 6 } if e == 7 { return 7 } if e == 8 { return 0 } if e == 9 { return 1 } if e == 10 { return 2 } return 3 } called by 1: vp_mc_active_edges |
| 388 | func vp_mc_eb(e: nx_int) -> nx_int { if e == 0 { return 1 } if e == 1 { return 2 } if e == 2 { return 3 } if e == 3 { return 0 } if e == 4 { return 5 } if e == 5 { return 6 } if e == 6 { return 7 } if e == 7 { return 4 } if e == 8 { return 4 } if e == 9 { return 5 } if e == 10 { return 6 } return 7 } called by 1: vp_mc_active_edges |
| 390 | func vp_mc_case(c: nx_int, r2: nx_int, bx: nx_int, by: nx_int, bz: nx_int) -> nx_int |
| 400 | func vp_mc_active_edges(c: nx_int, r2: nx_int, bx: nx_int, by: nx_int, bz: nx_int) -> nx_int |
| 416 | func vp_mc_interp_q10(fa: nx_int, fb: nx_int) -> nx_int called by 1: main |
| 425 | func vp_reflect(dx: nx_int, dy: nx_int, dz: nx_int, nax: nx_int, nay: nx_int, naz: nx_int, out: *i64) -> nx_int called by 1: main |
| 439 | func vp_oct_homog(c: nx_int, r2: nx_int, x0: nx_int, y0: nx_int, z0: nx_int, s: nx_int) -> nx_int |
| 460 | func vp_octree_count(c: nx_int, r2: nx_int, W: nx_int, maxDepth: nx_int, stack: *i64) -> nx_int |
| 506 | func vp_vd_count(occ: *i64, GN: nx_int) -> nx_int called by 1: main |
| 513 | func vp_vd_blast(occ: *i64, GN: nx_int, bx: nx_int, by: nx_int, bz: nx_int, r2: nx_int) -> nx_int called by 1: main |
| 537 | func vp_vd_visit(occ: *i64, reached: *i64, stack: *i64, sp: nx_int, nid: nx_int) -> nx_int called by 1: vp_vd_floating |
| 543 | func vp_vd_floating(occ: *i64, reached: *i64, GN: nx_int, stack: *i64) -> nx_int |
| 589 | func vp_nanite_depth(i: nx_int) -> nx_int { var d: nx_int = 0; while vp_pow2(d + 1) <= i + 1 { d = d + 1 } return d } |
| 590 | func vp_nanite_err(i: nx_int, NLEAF: nx_int) -> nx_int { return NLEAF / vp_pow2(vp_nanite_depth(i)) } |
| 591 | func vp_nanite_lo(i: nx_int, NLEAF: nx_int) -> nx_int |
| 598 | func vp_nanite_cut(NLEAF: nx_int, NNODE: nx_int, K: nx_int, TAU: nx_int, dist: nx_int, stack: *i64, cover: *i64) -> nx_int |
| 634 | func vp_tex_clampi(a: nx_int, hi: nx_int) -> nx_int { if a < 0 { return 0 } if a > hi { return hi } return a } called by 1: vp_tex_sample |
| 635 | func vp_tex_sample(atlas: *i64, atlasW: nx_int, TS: nx_int, tile: nx_int, u: nx_int, v: nx_int) -> nx_int |
| 656 | func vp_water_step(terr: *i64, water: *i64, gn: nx_int, dw: *i64) -> nx_int called by 1: main |
| 682 | func vp_ssao(fb: *i64, zb: *i64, w: nx_int, h: nx_int) -> nx_int called by 1: main |
| 719 | func vp_atmos(fb: *i64, zb: *i64, w: nx_int, h: nx_int) -> nx_int called by 1: main |
| 748 | func vp_gi(fb: *i64, src: *i64, w: nx_int, h: nx_int) -> nx_int called by 1: main |
| 785 | func vp_sun_face(face: nx_int, sx: nx_int, sy: nx_int, sz: nx_int) -> nx_int |
| 800 | func vp_spec(roughness: nx_int, ndoth: nx_int) -> nx_int |
| 810 | func vp_tri3(fb: *i64, zb: *i64, a: *i64, b: *i64, c: *i64, ca: nx_int, cb: nx_int, cc: nx_int) -> nx_int |
| 822 | func vp_quad_ao(fb: *i64, zb: *i64, p: *i64, a: nx_int, b: nx_int, c: nx_int, d: nx_int, |
| 834 | func vp_column(fb: *i64, zb: *i64, mvp: *i64, hgrid: *i64, biomegrid: *i64, gn: nx_int, x: nx_int, z: nx_int, sx: nx_int, sy: nx_int, sz: nx_int) -> nx_int |
| 877 | func vp_build_mvp(mvp: *i64, camx: nx_int, camy: nx_int, camz: nx_int, |
| 896 | func vp_putfd(fd: nx_int, s: *u8) -> nx_int |
| 902 | func vp_puts(s: *u8) -> nx_int { return vp_putfd(1, s) } |
| 905 | func vp_w16(b: *u8, o: nx_int, v: nx_int) -> nx_int { b[o] = (v & 255) as u8; b[o+1] = ((v>>8)&255) as u8; return o+2 } called by 1: vp_write_bmp |
| 906 | func vp_w32(b: *u8, o: nx_int, v: nx_int) -> nx_int called by 1: vp_write_bmp |
| 910 | func vp_write_bmp(fb: *i64, path: *u8) -> nx_int |
| 942 | func vp_frame_path(buf: *u8, f: nx_int) -> nx_int called by 1: main |
| 955 | func main() -> nx_int |