Hi all,
I’m having a lot of trouble with voxel lighting. By this, I mean a flood-fill voxel lighting type system in a blocky voxel type game (think Minecraft).
I don’t need help on a code level, but more on a conceptual level. While this isn’t directly about Unity, I figured I’d ask here anyway as I know there are several people with experience around here.
Here’s my understanding:
For sunlight, iterate downward until the surface of the terrain is found. Do this for each x, z column. And once done, use a flood-fill propagation algorithm to scatter the light outwards and around obstacles. This propagation occurs by adding nodes to a list of all locations where there are sources of light (so place a node on each x, z column at the surface). Then flood fill out from these nodes.
Simple enough. But how in the world do I handle neighbor chunks?
If I want to load a chunk and draw a mesh for it, I need to know the lighting that enters this chunk from its neighbors. Well, I can run the propagation algorithm on the neighbor chunks and it will propagate into this chunk that I’m generating now. But it will also propagate into other chunks that haven’t even been generated yet. And if it does, it won’t know which blocks exist to block the light…
So how can I generate light on a chunk by chunk basis without requiring every chunk in the whole world loaded before I start doing the lighting?
Thanks for your help.
(As a note: I had the lighting working before in a finite world where I could indeed have all chunks loaded at once. But now that I’m wanting much larger worlds, I need a new approach…)