Rust voxel sandbox (wgpu + wasm + axum multiplayer)
Find a file
Maximus Gorog 511798b6eb Phase 1 lighting: bake per-vertex sky visibility from voxel construction
The "side faces don't adjust to daytime ambiance" bug was caused by
conflating geometric sky visibility with radiometric sky intensity
into a single ambient_strength knob. This commit separates them.

sim/lighting.rs:
  - Refactor: extract walks_to_sky(world, origin, dir) -> bool as the
    shared DDA primitive. is_in_direct_sun now calls it.
  - New: sky_visibility(world, pos, normal) -> f32. Casts 8 cosine-
    weighted hemisphere rays through the voxel grid (Hammersley(2)
    distribution, deterministic). Returns fraction that escape to
    the world top. Pure function of (world, position, normal) — depends
    only on the surrounding voxel construction. Architecturally, this
    means a player-built sealed roof on the surface produces the same
    sky_vis as the same enclosure underground; no "is this the surface
    or underground?" hack anywhere.
  - 4 new tests including the construction-invariance test that pins
    "same enclosure geometry → same sky_vis regardless of world Y".

mesh.rs:
  - Vertex gains a sky_vis: f32 field at @location(5).
  - build_chunk_mesh computes sky_vis per quad corner via
    sky_visibility (one ray-walk per vertex; amortized at mesh build,
    free at runtime).
  - emit_oriented_box sets sky_vis = 1.0 for remote-player boxes
    (they float in open air).
  - 2 new tests: open-top has high sky_vis, slab-covered top has low.

shader.wgsl:
  - VsIn / VsOut grow @location(5) sky_vis: f32.
  - ambient_term rewritten as the principled split:
        sky_radiance(N) × sky_vis  +  bounce × (1 − sky_vis)
    where bounce is sun-tinted ground albedo scaled by day. No more
    `face_up = normal.y * 0.5 + 0.5` flat hemisphere assumption — the
    per-vertex geometric weight does the work.
  - ambient_strength bumped from mix(0.25, 0.85, day) to mix(0.35,
    1.00, day) since sky_vis now carries the geometric attenuation.

Result: side faces in the open get bright sky-colored ambient at noon;
side faces in pits dim correctly; player-built shelters darken by
construction without any time-of-day weirdness. Same model also sets
up the bounce-color bake (Phase 2) and the CSM shadow infrastructure
(Phase 3) — both extend the per-vertex visibility-attribute pattern
introduced here.

Tests: 61 passing (up from 53). Native + wasm release + server clean.
2026-05-24 00:00:04 -06:00
server pre-alpha 0.0.1 — initial multiplayer voxel sandbox 2026-05-22 23:33:47 -06:00
src Phase 1 lighting: bake per-vertex sky visibility from voxel construction 2026-05-24 00:00:04 -06:00
web Render + UI polish since pre-alpha-0.0.1 2026-05-23 18:44:56 -06:00
.dockerignore Add Docker + Caddy deploy for voxel.mxvs.art 2026-05-23 18:45:05 -06:00
.gitignore pre-alpha 0.0.1 — initial multiplayer voxel sandbox 2026-05-22 23:33:47 -06:00
ARCHITECTURE.md Add ARCHITECTURE.md mapping the functional-core/imperative-shell split 2026-05-23 23:33:02 -06:00
build-web.sh pre-alpha 0.0.1 — initial multiplayer voxel sandbox 2026-05-22 23:33:47 -06:00
Caddyfile Add Docker + Caddy deploy for voxel.mxvs.art 2026-05-23 18:45:05 -06:00
Cargo.lock pre-alpha 0.0.1 — initial multiplayer voxel sandbox 2026-05-22 23:33:47 -06:00
Cargo.toml pre-alpha 0.0.1 — initial multiplayer voxel sandbox 2026-05-22 23:33:47 -06:00
DEPLOY.md DEPLOY.md: add active-deployment runbook for voxel.mxvs.art 2026-05-23 22:52:43 -06:00
docker-compose.prod.yml Add Docker + Caddy deploy for voxel.mxvs.art 2026-05-23 18:45:05 -06:00
docker-compose.yml Add Docker + Caddy deploy for voxel.mxvs.art 2026-05-23 18:45:05 -06:00
Dockerfile Add Docker + Caddy deploy for voxel.mxvs.art 2026-05-23 18:45:05 -06:00
run.sh pre-alpha 0.0.1 — initial multiplayer voxel sandbox 2026-05-22 23:33:47 -06:00