I made this flood fill/breadth-first search style voxel lighting system using geometry nodes. However, due to the wonky set-up I have in the repeat zone, it lags quite a lot when the light is moved. I have used the new bake node to reduce lag, but I would much prefer a solution to the node setup itself, since the bake node doesn't really help when making adjustments to the searching itself (which comes before the bake node)
Blend file is included at the bottom.
Here's the initial set-up.
- Use a 32 x 32 point cloud to represent the voxels in a chunk, and store the inputted mesh as point attributes in that 32 x 32 point cloud (also store the light as another attribute)
- The occupied voxels node group is as follows
- And then the voxels to points node group:
Here's the repeat zone set-up. The idea is as follows:
- use a geometry proximity node to find the points in the point cloud that are 1m from the light
- subtract the occupied voxels (so the propagation doesn't go through them)
- subtract all the previous iterations (so you're only left with all points x meters away from the light in manhattan/taxicab distance)
- each iteration, a new point cloud is created from the current loop to feed into the next loop
- this is a hacky solution since the geometry proximity node uses euclidean distance. using a distance value of 1m and resetting the sample position to be points from the previous iteration creates a taxicab-like algorithm but it means a lot of unnecessary calculation is being done
- each iteration, the light level is stored starting from 15 (for the center) and decreasing by 1 each iteration
- then I transfer the light level onto the original mesh and store that as an attribute per face
In shader nodes I use the attributes and some math to sample the appropriate color from a lightmap texture (Y values are sunlight, X is time of day), but multiplying the attribute directly also works.
Example iterations (the light level 1-15 is previewed here):
Iteration 1
Iteration 2
Iteration 6
Iteration 4, with 1m cubes instanced on each point and the "current distance" point cloud being previewed
Repeat Zone
) then successively the results of the first two iterations ? For those of us not familiar with Minecraft-style... $\endgroup$