We are currently working on adding lighting to a small game with a voxel-based world.
Our current method consists of a list of changed blocks, and an update function invocated on every item on the list until the list is empty. The update method can add new blocks to the list in case they need an update. This works.
The only tiny problem is that it takes around a few minutes to calculate lighting for a world with one single lamp... The performance problem originates from the fact that the list doesn't check for duplicated blocks. So blocks can be updated more times than needed and therefore exponentially create more updates. A possibility would be to check for duplicate blocks but this is obviously a bad idea.
The world is dynamic so lights should be able to be removed and added, preferebly without having to remove all lighting and recalculating everything. This is possible with the current algorithm, however it's obviously too slow.
For people interested, here is the simplified algorithm executed on every item of the list:
- Calculate own light level by getting the neighbour with the highest light level and substracting it with one.
- Next, all blocks around the current block are added if their light levels are lower than the light level of the current block.
Does anybody have any experience or ideas about voxel lighting, preferably fast enough for updates every now and then...?