Fix black areas on generated maps by initializing Minetest lighting - #195
Fix black areas on generated maps by initializing Minetest lighting#195naulan-chrzaszcz wants to merge 2 commits into
Conversation
0a2d188 to
7c2270b
Compare
[Maven Build Status]📑 Commit: 📦 Download artifact: Generator.jar |
|
@FLecordix will be happy about this (even if he can't see this repo) 😉 |
Wouldn't this cause reverse bug: illuminate parts that shouldn't be ? |
|
Before fixing it, have you been able to identify the causes, in a reproducible manner? |
4c3f1a3 to
e6c66fd
Compare
e6c66fd to
24b764a
Compare
For the cause, for now, i'm not sure, but the tool uses |
Yeah, it's a consequence of my change :/ |
|
|
||
| int nodeIndex = (localZ << 8) | (localY << 4) | localX; | ||
| int param0 = block.getParam0()[nodeIndex] & 0xFFFF; | ||
| if (block.getNameIdMapping().get(param0).equals("default:water_source") || block.getNameIdMapping().get(param0).equals("air")) |
There was a problem hiding this comment.
What is this hardcoded stuff ?
| byte[] param1 = block.getParam1(); | ||
| for (int localZ = 0; localZ < Block.SIZE; localZ++) { | ||
| int worldZ = (blockZ << 4) + localZ; | ||
| for (int localX = 0; localX < Block.SIZE; localX++) { | ||
| int worldX = (blockX << 4) + localX; | ||
| for (int localY = 0; localY < Block.SIZE; localY++) { | ||
| int worldY = (blockY << 4) + localY; | ||
| if (!limits().contains(worldX, worldZ, worldY)) | ||
| continue; |
There was a problem hiding this comment.
Why make things so complicated while a single line in MTVoxel constructor would do the job?
There was a problem hiding this comment.
“Compared to human-generated code, LLMs often generated code with a higher cyclomatic complexity. Our outcomes suggest that LLMs tend to over-engineer solutions, which could result in code that is harder to maintain and more prone to errors during the later stages of software development.”
There was a problem hiding this comment.
Powered by Copilot
There was a problem hiding this comment.
That's because you didn't do what @pyrollo suggested (and his suggestion is also incomplete). His code was defining the param1 to 15 on every instance of the default voxel. You defined it in the parameters file, so only for the instances coming from the user.
There is also MTVoxel.DEFAULTVOXEL which should have that param1 value (I guess). BUT, there's something else!
When a Block is initialized, it is full of air, but not using the MTVoxel.DEFAULTVOXEL nor anything coming from the parameters. So, to make it work, you need to do (in addition to defining param1 = 15 on every instance of air voxel, either in the params like you did, or in the constructor like Pierre-Yves suggested) what you already tried in the first place: Filling the param1 array of the Block with 15 initially. It'll work because, by default, every air voxel (which means every voxel when the block is initialized) will be illuminated, and later on, voxels placed in the block by renderers will either erase that light value (replacing it with their own param1 value, most likely 0), or keep it if it was an air voxel because every air voxel already had a param1 value of 15 when you created them
There was a problem hiding this comment.
I forgot about this initialization. I think DEFAULTVOXEL should be used for initialization if there is no problem with that. We may also have DEFAULTVOXEL definition in settings (next to "format").
Anyway, that param1=15 thing will only be a workaround not solving the issue. Should we adopt that ?
There was a problem hiding this comment.
"Full bright" (and leaky buildings) is better than seemingly random pitch dark areas... I think.
Proper solution would be to either instruct Luanti to recompute light as soon as it loads the world, or to have a task that computes lighting ourselves (which might not be impossible thanks to the "max voxel" heightmap, it would probably look a little bit like the "populate minimap" task (to light up voxels exposed to direct sunlight), with then a propagation step to nearby voxels. Some margin would probably be required to correctly light up tile borders as well).
I suggest that we accept this workaround for now
There was a problem hiding this comment.
I propose a much better solution, which is more or less the same, but fully relying on parameters:
- Make DEFAULTVOXEL defined (or overridable) in parameters.
- Make blocks initialized with DEFAULTVOXEL
This will make it possible to use @naulan-chrzaszcz solution (by setting proper parameters) but it won't be hardcoded.
As a bonus, this may ease adaptation to other games (in Luanti and maybe other).
This shouldn't be much more complicated to do (anyway way simpler than the first proposed solution).
pyrollo
left a comment
There was a problem hiding this comment.
Seems that PR could be done in two lines and no hardcoded names:
@@ -45,6 +45,8 @@ public class MTVoxel implements Placeable {
this.type = type;
this.param1 = param1;
this.param2 = param2;
+ if (type == DEFAULT_VOXEL.type)
+ this.param1 = 0x0F;
}
This is still not satisfying because:
- It supposes default voxel (i.e. air) is defined with param1 = light
- It only lighten all default voxels but does not do any shadow computation
But it's still better than having large dark areas.
e637efa to
e6c75f0
Compare
An unsuspected consequence of that: Usually, only "under the sun" nodes gets a light of 15. This is used by many mods to detect "outside" nodes. A good example is weather mods. So you will have rain and snow inside your building (for example playing with Kidscode). |
|
Isn't there a flag or something in Luanti that indicates that the mapblock currently has nodes generated but lighting not yet computed? Something that we could do to instruct the Luanti engine to compute lightings on the first world loading? |
This is a long time bug that appears (it seems) randomly. I thought it had been fixed in recent version but this show that it's not the case. But it doesn't seem to have any simple solution. It looks more like a bug triggered in specific case in engine light calculation. I'll try to find out more. |
|
@naulan-chrzaszcz can you provide a working parameter file that produces such shadows ? I tried with main branch (commit 3339370) and Luanti 5.10.0 (quite outdated). I also have the shadows but... they disappear almost instantly when I get to them. I guess light is updated when a new empty map block is generated above the dark area. |
|
We are correctly setting I can't figure out where these flags are actually used in Luanti. Interesting, tried the same map with Luanti 5.10.0 and 5.15.2. Now, a big bisect have to be performed ! Other noticeable thing: dark areas are random. Running game several times on the same generated map gives different results. There must be some kind of race condition. |





Issue
#196
Changes
Initialized the
param1to0x0F(full daylight) for all air and water voxels.Showcase
Before the changes :


After :


Reason
For my blog, I often need to take screenshots of the worlds generated by the tool to illustrate my posts. But the main issue is that every time I generate a world, large black areas appear. Most of the time, these areas just stay there and won't disappear, even if you do something like break blocks inside the dark zone or walk over it.
Consequences of this change
By forcing maximum light on all transparent voxels, natural light attenuation and dynamic shadows are disabled. Areas that would typically be shaded will appear uniformly bright, as natural occlusion is no longer calculated.
Self-checks
/docsfolder has been updatedexamples/work the same (or have been adapted if subject to changes in this PR)