Jump to content

Possible Lighting Improvements and/or Optimizations Using Voxels


Recommended Posts

The Problem

As you may know, currently the lighting is very inefficient. That is, adding more lights adds significant performance hit. Also, visually the lighting is limited as it doesn't have indirect lighting calculation (that is, there is no GI, adding a lamp to ceiling that faces downwards means that ceiling will remain nearly black).


The Solution

Voxel-based lighting calculations could be added to game. Idea is something similar to Minecraft (but a bit improved). Note that this should apply for any light sources that isn't sun, moon or player hand-held light.



Every block should have following data variables assigned to them: light_brightness(float), light_color(vector3) and (optionally, explained at bottom) direction_affinity(int[2]). For any block that can cast light (lamps, electronic panels, billboards, forges etc.) there should be similar parameters stored that are constant (unless you decide to make a light with analogue brightness control).


The Mathz

A concept of light updates should be introduced. Whenever a block changes any physical condition (it gets broken, placed, or toggled on/off (if a light emitter)) it causes a light update for all blocks in a certain area around it (e.g. 15x15x15 block area). Now at this point the block propogates a shockwave of light parameter changes around it.


Let's simplify light updates to a 2D 5x5 area (although at least 11x11x11 is reccomended to smooth things out, give lights a good range and prevent artifacts). Let's say this is how the blocks are layed out in current area (B stands for brightness, C - for color):

Xs5XcSV.pngI may have taken some mistakes there, sorry


Now let's say the middle block in this image turned on with brightness 4 and color (1, 0.5, 0) causing light update in this area that now propagades till it stabilizes. Each voxel checks for all surrounding voxels, sums their brightnesses and divides by 4, also mixes their colors. This is what we get:

xL11b5H.pngI didn't finish the propagation outside, but did enoguh to give an idea. 3x3 would have been easier to understand example, I figure


In general, the propagation starts in the conter block, and continues out to blocks that touch it till it covers the area. The color is taken from all surrounding blocks and weighted by their brightnesses. Brightness is added up from all surrounding blocks and divided by surrounding block count (which in 3D world is always 6).



Every face of block in certain direction would be illuminated by the light data from the voxel in that direction. As the face detection is ther for painting, doing this would be easy. A bit harder for rounded surfaces as interpolation is required.



Not easy to implement (lots of work). No specular highlights from the light sources (unless some reflection probe/SSR method is used to get them to reflect). No shadows.


Regarding shadows and spot-light type lights...

The direction affinity could help with this.

Basically, it's first integer value would hold the direction (e.g. 0 = south, 1 = north, 2 = east... ... 6 = south/west, 7 = north/west, etc.) and it's second integer value would hold weight where 0 = no affinity, spread in all directions equally, 1 = 1/5th of light goes here, no light goes in opposite direction etc. (you can figure out the weights yourself). This would help (by assigning direction affinity when light is emitted from light source) to generate shadow-like effects.


Of course, this is just a broad look at the idea (had my time constraints of annoying family members asking to do other stuff). But this should be enough to give you an idea of how to implement something like this. It would generate nice global illumination-like effect as well as allow to implement optimized lights for weaker computers.

Link to comment
Share on other sites

You may want to hold off and see how it's changed in a17, because it will be completely different from how it is now.


A17 is updating engine and lamps will most likely perform better, but still - having many lamps with all shadows and stuff will be very heavy on performance. A faster option wouldn't be bad.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...