Voxel-based lighting

Started by
10 comments, last by ProtectedMode 9 years, 8 months ago

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...?

Advertisement

Some thoughts:

1. Use insertion sort and avoid duplicates when inserting the voxel into the list.

2. Google for LPV (ligth propagation volumes), a technique used by crytek to simulate realtime GI. They utilize the GPU, which would be a good idea for your scenario too.

3. With one light, you mean a directional,infinit light (aka sun) ? In this case consider standard shadow mapping approaches.

Some thoughts:

1. Use insertion sort and avoid duplicates when inserting the voxel into the list.

2. Google for LPV (ligth propagation volumes), a technique used by crytek to simulate realtime GI. They utilize the GPU, which would be a good idea for your scenario too.

3. With one light, you mean a directional,infinit light (aka sun) ? In this case consider standard shadow mapping approaches.

1. I still expect this approach to be too slow when considering there will be thousands of blocks on that list and it needs to be done very often.

2. Calculating lighting on changes and baking the light level into the vertices should probably still be faster, and fast enough since Minecraft somehow gets it working properly.

3. With one light I mean a single light block that emits light.


since Minecraft somehow gets it working properly.

Minecraft's lighting is not that great. Simple shadow mapping would give better results.


since Minecraft somehow gets it working properly.

Minecraft's lighting is not that great. Simple shadow mapping would give better results.

The smooth lighting is good enough for my taste. How would you handle hundreds of lights with shadow mapping?


How would you handle hundreds of lights with shadow mapping?

I'd use light maps only for the closest lights - hundreds of shadow casting lights may require too much computing resources and memory.

Cheers!


How would you handle hundreds of lights with shadow mapping?

I'd use light maps only for the closest lights - hundreds of shadow casting lights may require too much computing resources and memory.

Cheers!

That's why I think a voxel-based lighting model would be better. The light information could easily be baked into the voxels, which is much more efficient after the initial calculation is done. But that initial calculation is the problem...

Couldn't you add a single bit for each voxel that tells you of the voxel is already in light list or not?

1. I still expect this approach to be too slow when considering there will be thousands of blocks on that list and it needs to be done very often.


Try and measure. A measly few thousand primitives (integer ids/indices) aren't likely to give you any trouble.

Sean Middleditch – Game Systems Engineer – Join my team!

Why don't you use an octree or a grid for the changed blocks? That would make it faster for you to find the voxels in range of a light for example (since they are 3D rather 1D), and they also don't allow duplicates (this is handled during insertion).

Since you are using voxels, you probably already have a grid or octree? An octree would be better, though (a grid will just waste memory). With an octree, you could just add a "changed" flag to the chunks of the existing octree (the flag should propagate to the parent chunks, all the way up to the root), and then if you want to find out if a voxel is changed or not, just traverse the octree geometrically all the way down to your voxel, while checking if the "changed" flag is set on the traversed chunks. If any of the traversed chunks aren't "changed" you can just return immediately - otherwise, you get to your voxel's chunk, and just check if it is "changed".

(Corrected to allow for fast removal of "changed" flag - i.e., not having to traverse a whole branch just to tell if a chunk's "changed" flag should be reset; now only the leafs should have the flag)

This topic is closed to new replies.

Advertisement