nx_voxel_world.nx
buildroot/runtime/nx_voxel_world.nx
about
nx_voxel_world.nx -- PARAMETERIZED sovereign 3D-world renderer: a game-SPEC (DATA) -> a rendered world.
Style is a spec field, NOT a hardcode -- the engine is not locked to one look: SP_STYLE 0=realism (textured,
smooth light), 1=toon (banded light + silhouette outline = anime/cel), 2=flat (untextured facets = artsy
low-poly). Geometry here is voxel terrain, but the rasterizer (fill_ztex) draws arbitrary textured triangles,
so other geometry (meshes/characters) plugs into the same path. Composes nx_f32_hw. license_tier: ORIGINAL
dependencies 2 imports · 7 importers
imports: nx_syscalls.nxnx_f32_hw.nx
imported by: nx_anim_gate.nxnx_entity_gate.nxnx_fpsworld_gate.nxnx_game_loop_gate.nxnx_voxel_spec_gate.nxnx_world_png_gate.nxnx_world_style_gate.nx
structs
| none |
consts
| 8 | const SP_MAGIC_65536: i64 = 65536 |
| 10 | const W: i64 = 320 |
| 11 | const H: i64 = 240 |
| 12 | const HW: i64 = 160 |
| 13 | const HH: i64 = 120 |
| 14 | const TN: i64 = 4 |
| 15 | const ZFAR: i64 = 1073741824 |
| 16 | const SP_SEED: i64 = 0 |
| 17 | const SP_N: i64 = 1 |
| 18 | const SP_WATER: i64 = 2 |
| 19 | const SP_MAXH: i64 = 3 |
| 20 | const SP_LAT: i64 = 4 |
| 21 | const SP_PSIN: i64 = 5 |
| 22 | const SP_PCOS: i64 = 6 |
| 23 | const SP_YSIN: i64 = 7 |
| 24 | const SP_YCOS: i64 = 8 |
| 25 | const SP_PUSH: i64 = 9 |
| 26 | const SP_FOCAL: i64 = 10 |
| 27 | const SP_STYLE: i64 = 11 |
| 28 | const SP_CAMX: i64 = 12 // first-person camera position (f32 bit-patterns) |
| 29 | const SP_CAMY: i64 = 13 |
| 30 | const SP_CAMZ: i64 = 14 |
| 31 | const SP_FPS: i64 = 15 // 1 = first-person (subtract cam pos, no push); 0 = orbit (default) |
| 32 | const STYLE_REAL: i64 = 0 |
| 33 | const STYLE_TOON: i64 = 1 |
| 34 | const STYLE_FLAT: i64 = 2 |
functions
| 36 | func world_pixels() -> i64 { return W * H } |
| 37 | func world_fb_bytes() -> i64 { return W * H * 8 } |
| 38 | func world_sky() -> i64 { return 142 + 186 * 256 + 228 * SP_MAGIC_65536 } |
| 40 | func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b } |
| 41 | func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b } |
| 42 | func iabs(a: i64) -> i64 { if a < 0 { return 0 - a } return a } called by 1: outline_pass |
| 43 | func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) } |
| 44 | func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) } |
| 45 | func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v } |
| 46 | func same_sign3(a: i64, b: i64, c: i64) -> i64 called by 1: fill_ztex |
| 51 | func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) } |
| 53 | func lat(ix: i64, iz: i64, seed: i64) -> i64 called by 1: terrain_h |
| 58 | func terrain_h(sp: *i64, gx: i64, gz: i64) -> i64 |
| 78 | func hN(sp: *i64, gx: i64, gz: i64) -> i64 |
| 85 | func top_color(sp: *i64, h: i64) -> i64 called by 1: draw_col |
| 91 | func side_color(sp: *i64, h: i64) -> i64 called by 1: draw_col |
| 97 | func texel_col(style: i64, baseR: i64, baseG: i64, baseB: i64, u: i64, v: i64, bright: i64) -> i64 |
| 106 | func toon_band(b: i64) -> i64 called by 1: draw_face |
| 110 | func fill_ztex(fb: *i64, zb: *i64, t: *i64, br: i64, bg: i64, bb: i64, bright: i64, style: i64) -> i64 |
| 143 | func project(sp: *i64, R: *i64, iwx: i64, iwy: i64, iwz: i64, out: *i64) -> i64 |
| 168 | func shade_local(lnx: i64, lny: i64, lnz: i64) -> i64 |
| 173 | func draw_face(fb: *i64, zb: *i64, sx: *i64, sy: *i64, sd: *i64, sok: *i64, |
| 195 | func draw_col(sp: *i64, fb: *i64, zb: *i64, R: *i64, gx: i64, gz: i64) -> i64 |
| 222 | func draw_obox(sp: *i64, fb: *i64, zb: *i64, R: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, col: i64, style: i64) -> i64 |
| 245 | func has_tree(sp: *i64, gx: i64, gz: i64) -> i64 |
| 254 | func draw_tree(sp: *i64, fb: *i64, zb: *i64, R: *i64, gx: i64, gz: i64, style: i64) -> i64 |
| 261 | func outline_pass(fb: *i64, zb: *i64) -> i64 |
| 286 | func put_u32le(b: *u8, o: i64, v: i64) -> i64 called by 1: write_bmp |
| 293 | func write_bmp(fb: *i64, path: *u8) -> i64 |
| 329 | func build_cam(sp: *i64, R: *i64) -> i64 |
| 338 | func world_project(sp: *i64, R: *i64, iwx: i64, iwy: i64, iwz: i64, out: *i64) -> i64 { return project(sp, R, iwx, iwy, iwz, out) } calls 1: project |
| 339 | func world_height(sp: *i64, gx: i64, gz: i64) -> i64 { return terrain_h(sp, gx, gz) } |
| 340 | func world_obox(sp: *i64, fb: *i64, zb: *i64, R: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, col: i64, style: i64) -> i64 |
| 343 | func render_world(sp: *i64, fb: *i64, zb: *i64) -> i64 |