code wiki / (root) / nx_pets_voxel3d.nx

nx_pets_voxel3d.nx

buildroot/runtime/nx_pets_voxel3d.nx

89099 B1683 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tooltopic pets
docsdependenciesstructsconstsfunctions

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

nx_camera_q14.nx nx_raster_triangle.nx nx_perlin.nx nx_syscalls.nx nx_pets_voxel3d.nx

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

main nx_raster_alloc_fb sys_mmap nx_raster_alloc_zb sys_mmap ↻ nx_raster_clear vp_pack nx_raster_zbuffer_clear sys_mmap ↻ nx_raster_triangle _clamp _min3 _max3 _same_sign_3 nx_raster_pixel vp_puts vp_putfd sys_write nx_camera_perspective nx_camera_cos_q14_deg nx_camera_sin_q14_deg _normalise_deg _sin_table_alloc sys_mmap ↻ nx_camera_sin_q14_deg ↻ nx_camera_identity_4x4 vp_project sys_mmap ↻ nx_camera_mat4_vec4 nx_perlin_alloc sys_mmap ↻ _perlin_lcg_step nx_perlin_2d _perlin_hash_2d _perlin_dot_2d _perlin_grad_2d_x _perlin_grad_2d_y _perlin_ease _perlin_lerp vp_h

structs

none

consts

26const NX_MAGIC_65536: i64 = 65536
27const NX_MAGIC_16777216: i64 = 16777216
28const NX_MAGIC_4096: i64 = 4096
29const NX_MAGIC_1024: i64 = 1024
30const NX_MAGIC_2048: i64 = 2048
31const NX_MAGIC_2147483647: i64 = 2147483647
32const NX_MAGIC_1103515: i64 = 1103515
33const NX_MAGIC_12345: i64 = 12345
34const NX_MAGIC_5000: i64 = 5000
35const NX_MAGIC_100000: i64 = 100000
36const NX_MAGIC_10000: i64 = 10000
37const NX_MAGIC_8000: i64 = 8000
38const NX_MAGIC_320000: i64 = 320000
39const NX_MAGIC_2835: i64 = 2835
40const NX_MAGIC_1337: i64 = 1337
41const NX_MAGIC_7777: i64 = 7777
42const NX_MAGIC_909090: i64 = 909090
43const NX_MAGIC_424242: i64 = 424242
44const NX_MAGIC_515151: i64 = 515151
45const NX_MAGIC_31337: i64 = 31337
46const NX_MAGIC_4000: i64 = 4000
47const NX_MAGIC_110000: i64 = 110000
48const NX_MAGIC_16384: i64 = 16384
50const NX_W: nx_int = 320
51const NX_H: nx_int = 240
52const NX_W2: nx_int = 160
53const NX_H2: nx_int = 120
54const NX_VQ: nx_int = 16384

functions

56func vp_pack(r: nx_int, g: nx_int, b: nx_int, a: nx_int) -> nx_int
called by 2: vp_quad_aomain
61func vp_project(mvp: *i64, wx: nx_int, wy: nx_int, wz: nx_int, scr: *i64) -> nx_int
78func vp_tri(fb: *i64, zb: *i64, a: *i64, b: *i64, c: *i64, col: nx_int) -> nx_int
called by 1: vp_quad calls 2: sys_mmapnx_raster_triangle
91func 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
102func vp_h(ps: *PerlinState, x: nx_int, z: nx_int) -> nx_int
called by 2: vp_gen_chunkmain calls 1: nx_perlin_2d
111func vp_biome(bps: *PerlinState, h: nx_int, x: nx_int, z: nx_int) -> nx_int
called by 1: main calls 1: nx_perlin_2d
122func hget(hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int
130func vp_ao(occ: nx_int) -> nx_int
called by 2: vp_columnmain
137func vp_occ(hgrid: *i64, gn: nx_int, h: nx_int,
called by 2: vp_columnmain calls 1: hget
147func vp_aabb_floor(hgrid: *i64, gn: nx_int, x0: nx_int, z0: nx_int, x1: nx_int, z1: nx_int) -> nx_int
called by 2: vp_collide_ymain calls 1: hget
161func 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
called by 1: main calls 1: vp_aabb_floor
168func vp_gen_chunk(ps: *PerlinState, cx: nx_int, cz: nx_int, out: *i64) -> nx_int
called by 1: main calls 1: vp_h
178func vp_place(hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int
called by 1: main calls 1: hget
183func vp_break(hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int
called by 1: main calls 1: hget
190func vp_greedy_row(hrow: *i64, brow: *i64, n: nx_int) -> nx_int
called by 1: main
203func vp_struct_at(sps: *PerlinState, hgrid: *i64, gn: nx_int, x: nx_int, z: nx_int) -> nx_int
called by 1: main calls 2: hgetnx_perlin_2d
214func vp_erode_pass(hg: *i64, gn: nx_int, talus: nx_int, delta: *i64) -> nx_int
called by 1: main
235func vp_ore(ops: *PerlinState, x: nx_int, z: nx_int, y: nx_int) -> nx_int
called by 1: main calls 1: nx_perlin_2d
243func vp_cave(cps: *PerlinState, x: nx_int, z: nx_int, y: nx_int) -> nx_int
called by 1: main calls 1: nx_perlin_2d
254func vp_bit(t: nx_int) -> nx_int
260func vp_popcount4(m: nx_int) -> nx_int
called by 1: vp_wfc_solve
270func vp_wfc_allow(a: nx_int, b: nx_int) -> nx_int
called by 2: vp_wfc_prunemain
279func vp_wfc_prune(mask: *i64, src: nx_int, dst: nx_int) -> nx_int
called by 1: vp_wfc_solve calls 2: vp_bitvp_wfc_allow
301func vp_wfc_solve(seed: nx_int, cells: *i64, mask: *i64, gn: nx_int) -> nx_int
called by 1: main calls 3: vp_popcount4vp_bitvp_wfc_prune
374func 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 }
376func vp_mc_field(c: nx_int, r2: nx_int, x: nx_int, y: nx_int, z: nx_int) -> nx_int
383func 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 }
384func 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 }
385func 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 }
387func 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
388func 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
390func vp_mc_case(c: nx_int, r2: nx_int, bx: nx_int, by: nx_int, bz: nx_int) -> nx_int
400func vp_mc_active_edges(c: nx_int, r2: nx_int, bx: nx_int, by: nx_int, bz: nx_int) -> nx_int
416func vp_mc_interp_q10(fa: nx_int, fb: nx_int) -> nx_int
called by 1: main
425func 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
439func vp_oct_homog(c: nx_int, r2: nx_int, x0: nx_int, y0: nx_int, z0: nx_int, s: nx_int) -> nx_int
called by 1: vp_octree_count calls 1: vp_mc_field
460func vp_octree_count(c: nx_int, r2: nx_int, W: nx_int, maxDepth: nx_int, stack: *i64) -> nx_int
called by 1: main calls 2: vp_pow2vp_oct_homog
506func vp_vd_count(occ: *i64, GN: nx_int) -> nx_int
called by 1: main
513func 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
537func vp_vd_visit(occ: *i64, reached: *i64, stack: *i64, sp: nx_int, nid: nx_int) -> nx_int
called by 1: vp_vd_floating
543func vp_vd_floating(occ: *i64, reached: *i64, GN: nx_int, stack: *i64) -> nx_int
called by 1: main calls 1: vp_vd_visit
589func 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 }
called by 2: vp_nanite_errvp_nanite_lo calls 1: vp_pow2
590func vp_nanite_err(i: nx_int, NLEAF: nx_int) -> nx_int { return NLEAF / vp_pow2(vp_nanite_depth(i)) }
591func vp_nanite_lo(i: nx_int, NLEAF: nx_int) -> nx_int
598func vp_nanite_cut(NLEAF: nx_int, NNODE: nx_int, K: nx_int, TAU: nx_int, dist: nx_int, stack: *i64, cover: *i64) -> nx_int
called by 1: main calls 2: vp_nanite_errvp_nanite_lo
634func 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
635func vp_tex_sample(atlas: *i64, atlasW: nx_int, TS: nx_int, tile: nx_int, u: nx_int, v: nx_int) -> nx_int
called by 1: main calls 1: vp_tex_clampi
656func vp_water_step(terr: *i64, water: *i64, gn: nx_int, dw: *i64) -> nx_int
called by 1: main
682func vp_ssao(fb: *i64, zb: *i64, w: nx_int, h: nx_int) -> nx_int
called by 1: main
719func vp_atmos(fb: *i64, zb: *i64, w: nx_int, h: nx_int) -> nx_int
called by 1: main
748func vp_gi(fb: *i64, src: *i64, w: nx_int, h: nx_int) -> nx_int
called by 1: main
785func vp_sun_face(face: nx_int, sx: nx_int, sy: nx_int, sz: nx_int) -> nx_int
called by 2: vp_columnmain
800func vp_spec(roughness: nx_int, ndoth: nx_int) -> nx_int
called by 2: vp_columnmain
810func vp_tri3(fb: *i64, zb: *i64, a: *i64, b: *i64, c: *i64, ca: nx_int, cb: nx_int, cc: nx_int) -> nx_int
822func vp_quad_ao(fb: *i64, zb: *i64, p: *i64, a: nx_int, b: nx_int, c: nx_int, d: nx_int,
called by 1: vp_column calls 2: vp_tri3vp_pack
834func 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
877func vp_build_mvp(mvp: *i64, camx: nx_int, camy: nx_int, camz: nx_int,
896func vp_putfd(fd: nx_int, s: *u8) -> nx_int
called by 2: vp_putsmain calls 1: sys_write
902func vp_puts(s: *u8) -> nx_int { return vp_putfd(1, s) }
called by 1: main calls 1: vp_putfd
905func 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
906func vp_w32(b: *u8, o: nx_int, v: nx_int) -> nx_int
called by 1: vp_write_bmp
910func vp_write_bmp(fb: *i64, path: *u8) -> nx_int
942func vp_frame_path(buf: *u8, f: nx_int) -> nx_int
called by 1: main
955func main() -> nx_int