• Create Account

## Voxel-based lighting

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1ProtectedMode  Members

1339
Like
0Likes
Like

Posted 21 August 2014 - 05:21 AM

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

### #2Ashaman73  Members

13649
Like
0Likes
Like

Posted 21 August 2014 - 06:33 AM

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.

Ashaman

### #3ProtectedMode  Members

1339
Like
0Likes
Like

Posted 21 August 2014 - 06:57 AM

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.

### #4 slalrbalr   Banned

2006
Like
0Likes
Like

Posted 21 August 2014 - 07:18 AM

since Minecraft somehow gets it working properly.

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

### #5ProtectedMode  Members

1339
Like
0Likes
Like

Posted 21 August 2014 - 07:25 AM

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?

### #6kauna  Members

2918
Like
0Likes
Like

Posted 21 August 2014 - 07:51 AM

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!

### #7ProtectedMode  Members

1339
Like
0Likes
Like

Posted 21 August 2014 - 07:57 AM

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

### #8Giallanon  Members

1819
Like
0Likes
Like

Posted 21 August 2014 - 08:47 AM

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

### #9SeanMiddleditch  Members

16717
Like
0Likes
Like

Posted 21 August 2014 - 09:57 AM

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.

Game Developer, C++ Geek, Dragon Slayer - http://seanmiddleditch.com

C++ SG14 "Games & Low Latency" - Co-chair - public forums

Wargaming Seattle - Lead Server Engineer - We're hiring!

### #10 slalrbalr   Banned

2006
Like
0Likes
Like

Posted 22 August 2014 - 12:52 AM

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)

Edited by tonemgub, 22 August 2014 - 12:58 AM.

### #11kalle_h  Members

2402
Like
0Likes
Like

Posted 22 August 2014 - 02:20 AM

I would just calculate direct contribution first and then scatter/blur that a bit. Should look better and be faster.

### #12ProtectedMode  Members

1339
Like
0Likes
Like

Posted 22 August 2014 - 02:56 AM

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

This is the technique I'm using now with a breadth-first search and it's working a hundred times faster than before. I was using a byte for the lighting value, which is too much space anyway... Thank you all for your suggestions and answers.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.