Rust voxel sandbox (wgpu + wasm + axum multiplayer)
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.
|
||
|---|---|---|
| server | ||
| src | ||
| web | ||
| .dockerignore | ||
| .gitignore | ||
| ARCHITECTURE.md | ||
| build-web.sh | ||
| Caddyfile | ||
| Cargo.lock | ||
| Cargo.toml | ||
| DEPLOY.md | ||
| docker-compose.prod.yml | ||
| docker-compose.yml | ||
| Dockerfile | ||
| run.sh | ||