Hardware lighting
We've been discussing this frequently on IRC, and it's becoming an important subject in Minetest development. Most users are probably aware that since its existence, Minetest has been using an unique method of doing lighting. Light is simulated by setting face colors (vertex colors when smooth lighting is enabled) to brighter or darken the intensity of surfaces. The correct way of doing lighting in a 3D environment though is by using real light entities (hardware lights or dynamic lights) which radiate lighting in an uniform way.
There are many reasons why this is heavily wanted in Minetest too. First of all, I consider the current method a hack. Surface colors are not meant to be used for simulating light, and this is incorrect in regard to how 3D rendering is meant to work at this day in my opinion. Second, it brings many problems. The mapgen must calculate lighting for each node as it spawns... causing the world to take longer to load, its size on the drive to be bigger, and more information to be constantly networked to the user. Multiple instances of the same mesh are also colorized as one, causing a known bug where a player being in a dark area makes all players turn black. Thirdly, hardware lighting looks a whole lot better, since lighting is always directional to surfaces and ranges properly. Fourth, it unlocks new possibilities such as bump mapping, specular (glossy reflections), light animations (blinking lights) and more graphical effects which can be optional.
Enabling light entities from Irrlicht is very simple, but there's a reason why this hasn't been done already; No one knows how to keep lighting from shining in caves and indoor. A dynamic light goes as far as its range is set, and culling by surface would be tricky. We're still brainstorming for ways to fix the problem. Preferably without shaders, so people who don't enable them can have proper lighting as well. As far as I'm aware, there are two ways we can go about this:
- Use the current voxel light calculation to determine where sunlight should shine. So instead of using it to set surface color, we use it as a mask to influence where lighting shows. Problem is there's no easy way to filter lights per surfaces. It could be done with multiple render buffers but that would be costly on performance. If anyone finds a way to do this with Irrlicht lights (and hopefully no shaders) you could be a hero :)
[EDIT] - Colorize nodes which are out of a light's influence black, reversing the current implementation and above suggestion. A light entity can't brighten a black surface, so darkening the diffuse color can be used to stop lights from shining in caves. Supposing it would work however, you still need to separate lights from each other, so placing a torch in a cave won't cause the sun / moon to show over it. This would get half of the problem solved still.
- Another idea I thought of is using stencil shadows to keep light showing where it should. Dynamic shadows however can be extremely costly, which is why they're always a preference and not meant for anything but visual effects. If we'd rely on them to hide light in caves, we'd need them to be always enabled, which most hardware couldn't handle properly (especially without shaders).
If anyone wishes to contribute to making this happen, everyone would greatly appreciate it. I already looked at the lighting system and it's too large to understand. I easily managed to add a dynamic light once and it looked awesome, but we need someone to figure out the masking. This thread is dedicated to finding ideas and working on adding hardware lighting to Minetest.
There are many reasons why this is heavily wanted in Minetest too. First of all, I consider the current method a hack. Surface colors are not meant to be used for simulating light, and this is incorrect in regard to how 3D rendering is meant to work at this day in my opinion. Second, it brings many problems. The mapgen must calculate lighting for each node as it spawns... causing the world to take longer to load, its size on the drive to be bigger, and more information to be constantly networked to the user. Multiple instances of the same mesh are also colorized as one, causing a known bug where a player being in a dark area makes all players turn black. Thirdly, hardware lighting looks a whole lot better, since lighting is always directional to surfaces and ranges properly. Fourth, it unlocks new possibilities such as bump mapping, specular (glossy reflections), light animations (blinking lights) and more graphical effects which can be optional.
Enabling light entities from Irrlicht is very simple, but there's a reason why this hasn't been done already; No one knows how to keep lighting from shining in caves and indoor. A dynamic light goes as far as its range is set, and culling by surface would be tricky. We're still brainstorming for ways to fix the problem. Preferably without shaders, so people who don't enable them can have proper lighting as well. As far as I'm aware, there are two ways we can go about this:
- Use the current voxel light calculation to determine where sunlight should shine. So instead of using it to set surface color, we use it as a mask to influence where lighting shows. Problem is there's no easy way to filter lights per surfaces. It could be done with multiple render buffers but that would be costly on performance. If anyone finds a way to do this with Irrlicht lights (and hopefully no shaders) you could be a hero :)
[EDIT] - Colorize nodes which are out of a light's influence black, reversing the current implementation and above suggestion. A light entity can't brighten a black surface, so darkening the diffuse color can be used to stop lights from shining in caves. Supposing it would work however, you still need to separate lights from each other, so placing a torch in a cave won't cause the sun / moon to show over it. This would get half of the problem solved still.
- Another idea I thought of is using stencil shadows to keep light showing where it should. Dynamic shadows however can be extremely costly, which is why they're always a preference and not meant for anything but visual effects. If we'd rely on them to hide light in caves, we'd need them to be always enabled, which most hardware couldn't handle properly (especially without shaders).
If anyone wishes to contribute to making this happen, everyone would greatly appreciate it. I already looked at the lighting system and it's too large to understand. I easily managed to add a dynamic light once and it looked awesome, but we need someone to figure out the masking. This thread is dedicated to finding ideas and working on adding hardware lighting to Minetest.