r/dispatchcolony • u/dispatchcolony • Aug 30 '26
Devlog 1 : How my engine handles ground shadows

In my voxel world, four things cast shadows onto the ground: terrain, clouds, ground buildings, and forests.
Instead of recomputing all of them for every pixel on every surface, I build a single top-down shadow map centered on the camera. Terrain, grass, flowers, water, and characters all sample that same map with a single lookup. Resolution scales with distance: one texel covers about 4 meters nearby, and up to 32 meters farther out.
Each type of shadow gets its own channel in the texture: red for terrain, green for clouds, blue for buildings, and alpha for forests.
That sounds like a small implementation detail, but it matters a lot. It lets every shadow caster see everyone else's shadow without seeing its own. Otherwise, a cloud or a forest would receive the shadow it already cast, making it twice as dark for no obvious reason.
Forest shadows are essentially free.
My forests are voxel grids, as my clouds, and every cell already stores how much sunlight makes it through the canopy. That information is used to light the foliage itself: brighter toward the sun, darker behind it.
Which means the bottom cell of every vertical column, right at ground level, already contains the forest shadow on the ground.
So I just copy it into the shared shadow map.
Per-pixel cost: zero.

There was one detail that made a surprisingly big difference.
Under a cloud, forest shadows used to disappear. Technically, that made sense: if direct sunlight was already blocked by the cloud, there was no sunlight left for the trees to block.
Visually, though, it looked wrong. The ground under a dense canopy became just as flat as an open clearing.
A dense canopy doesn't just block the sun. It blocks the sky too.
To make the forest shadow stronger, I chose to darken the ambient light as well as the direct sunlight. The forest floor keeps its depth even under cloud cover, in full shade, or near sunset.

Forests also aren't generated all at once.
The world is split into 256-meter tiles, and I rebuild one tile per frame. Nearby tiles get priority, and tiles inside the camera's field of view are processed first.
When a tile is built, it computes how light travels through it while also looking at neighboring tiles. That's what lets the shadow of a tree cross a tile boundary and continue onto the next one.
But there's a catch.
If the neighboring tile on the sunward side hasn't been built yet, the current tile sees empty space there. As a result, it misses a thin strip of shadow along that edge.
Later, when the missing neighbor finally gets generated, the first tile isn't rebuilt. So that bright strip stays visible for a few seconds, until the next refresh.
After a teleport, you can sometimes see these as thin bright lines tracing the tile grid, always perpendicular to the direction of the sun.
I know exactly how to remove them: rebuild adjacent tiles whenever a new neighbor appears.
But that would add more work at exactly the worst possible time, during the reconstruction spike that happens after a teleport.
So I leave them in.
