# How to remove voxel lights with Minecraft-style algorithm?

I am making a voxel game. I have researched lighting techniques, and the minecraft-style algorithm appears the most efficient. When blocks are placed, they are marked for update. The engine performs a recursive algorithm on them that forms a diamond-shaped pattern like this:

01210
12321
01210
00100


My question is how you would remove lights using such an algorithm. Suppose your light setup looks like this: (The 2s would be the light sources)

01100
12210
01100


And you wanted to remove one of the light sources. From what I have seen, it would produce a result like this:

01000
10000
01000


A diamond-shaped pattern around the light source would be removed. How can I remove a light source without causing this effect?

## 1 Answer

You can't. That's one of the downsides to MC's lighting model.

What you can do is update the just the cell by setting them to max of the neighbours minus the decay like if there wasn't a light there and mark each of the neighbours as needing an update.

01100
12110
01100


And then you go over each of the marked cells and update them in the same way, (marking the neighbours of changed cells as you go):

01000
12100
01000


If a light is in a updating cell then the new light value is either the calculated value or the emitted light whichever is greater.

Then when no more cells have been updated then the update is finished.

Each iteration can be done in a separate game tick to avoid freezing the game. You don't even need to do a full iteration.

The number of iterations can become quite large if the lighting level is very granular. Removing a strength 255 light will result in 128 iterations to remove all of the light. This is related to the count-to-infinity in network routing.

To solve this you can instead reset all light values in the affected radius to 0 (except existing lights to their light value) and mark the edge of the area (and neighbours of existing lights) for lighting updates.

• As someone getting into voxel technologies myself, what kind of system would allow this aside from the Minecraft model? – Mkalafut Oct 6 '15 at 19:45
• @Mkalafut you can add some info per voxel about where the light is coming from and how much it affect the voxel and use that to speed up the update. Or just don't store lighting info in each voxel but then pay the cost of having to recalculate it every time you need it. – ratchet freak Oct 6 '15 at 19:56
• Hm, It doesn't look like this will do what I want. However, it does contain useful information, from which I have derived a working algorithm. Once I get the opportunity to, I will make some diagrams to explain how it works. Thank you for your answer! – Code Cube Oct 7 '15 at 18:30
• @CodeCube yeah I since though of a better solution see my edit. – ratchet freak Oct 7 '15 at 18:39