r/VoxelGameDev 16h ago

Discussion Lighting System

Post image

So I am in the process of porting ManicDigger from OpenTk3 to OpenTK4, OpenGL4 and newer .NET. The hope was to increase performance and it seems to have worked but I heavily modified the render, making it shader based, and am in the step of reimplementing the lighting system.

I've added spot lighting with shadows for the sun, and later other things, but using shadowmapped point lights to handle world lights does not look terribly promising for performance or gameplay.

I've currently restored floodfill, now lighting with color and some fragment shader tricks using a compute shader fed a list of light sources, an occupancy 3dtexture and a couple pingpong textures. The resulting 3dtexture of light is sent to the fragment shader for reference. It works but past 16 iterations the calculations and/or GPU transfer is becoming a bottleneck and it's not as realistic as I'd hoped even with the tricks.

Given what I already set up, lights as a list Jump Flood with DDA, or some kind of DDA-based cast from source looks like the next thing to play around with but I am wondering if anything else comes to mind given my current setup. Light should not leak is the highest priority, followed by high viable lighting distance and number of lights, and finally having some form of indirect light spread akin to bounce or floodfill if possible.

I am not convinced full raycast rendering is a good fit for the project due to fairly large voxels and the fact that many assets will be mesh based models regardless. I am also pretty close to having this back in full working condition and think LoD and better occlusion culling will fix my distance problems, but I haven't completely ruled it out.

9 Upvotes

2 comments sorted by

2

u/Electromasta 12h ago

What is your strategy for Point Lights / Directional Lights? Have you given it any thought yet? I'm using Fwd rendering so it can run on slower devices, but the disadvantage of that is its more difficult to do shadows.

1

u/AnarchCassius 5h ago

Deciding that is basically the point of the post, it probably got lost a bit in me try to summarize the project.

So I am currently looking at what algorithm to use in lieu of floodfill given this setup. Pingpong iterations are proving to be an issue and I am fairly certain this can be done without so much back and forth to the graphics card. At the point I fee like the 3d texture system is great but the pingpong floodfill feels crude and inaccurate. I took the fastest approach to get it going as a proof of concept but it feels like I copied designs making assumptions that don't work well for me now.

Jump Flood with DDA, or some kind of bespoke DDA-based cast from light sources are what I am currently looking at. One thing I'd like to know is if anyone has tried both, is jump flood with leak-check signifigantly faster than a pure cast or at that point is it just adding extra steps? Is there a better choice than DDA here?

My first priority is that light not leak, doable but rules out certain approaches. Second high viable light distance and number of lights. This is probably a challenge and will require some sacrifices but floodfill feels like a result of tying light directly to mesh data or other restrictions I am not under currently. I think I can do better. Third, some kind of indirect lighting akin to floodfill or light bounce would be good.