godotengine / godotengine/godot
LightmapGI producing incorrect, misaligned lightmaps
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in: 4.1.2.stable onwards (though not identically)
- Not reproducible in 4.1.1.stable and earlier
### System information
Godot v4.5.1.stable - Windows 10 (build 19045)
### Issue description
In 4.5.1, if I use LightmapGI to bake the light from an OmniLight3D on to a 1x1m PlaneMesh sitting centrally below it this is the resulting lightmap. Denoiser and Use Bicubic Filter are both off to get as 'raw' a result as possible. If I switch to Compatibility and reimport the .exr as Lossless you can see the issue more clearly. (As an aside I'm not sure why I can only get this to display like this with no filtering in Compatibility). The lightmap appears to be incorrectly shifting the centre of the light up and right (+X, -Z).
So I went back in time and this hasn't always been a problem. In 4.1.1 the lightmap looks as expected with the light centred on the plane, brightest section in the middle and everything symmetrical. The issue first arises in 4.1.2 - although the misalignment is actually different here - this time being a shift up and left (-X, -Z).
However when we look at the lightmap file we see that they have actually changed, not just shifted. As this happened between 4.1.1 and 4.1.2 I'm guessing this is caused by https://github.com/godotengine/godot/pull/81872.
Finally the change in the direction of the shift happened in 4.4. Again this is due to the actual generation of the lightmap being changed. The shift changed from up and left to up and right as it is now in 4.5.1.
How LightmapGI generates a lightmap has obviously been changed over time for good reasons but it seems to me that this has caused a fundamental problem where the lightmap no longer looks as you would logically expect it to. In this case the lightmap is not symmetrical despite the light being centred over the plane. Presumably this becomes less of an issue with higher resolution lightmaps as the shift distance will be much less, however I should note that these examples were all done with the default setting of 0.2m for a texel so I would expect it to work fine at this resolution.
There is also another issue in that the lightmaps generated for a PlaneMesh and an identically sized imported mesh are not the same which could certainly cause problems applying a consistent fix. I'd originally also discussed this here but it was overcomplicating things so I will open a separate issue for it. EDIT - I have now created a new issue for this here: https://github.com/godotengine/godot/issues/112786.
I haven't added an MRP as this is not project specific and it can replicated in less than a minute but the MRP in https://github.com/godotengine/godot/issues/112786 demonstrates the same thing for both a PlaneMesh and an imported mesh.
### Steps to reproduce
Using LightmapGI, bake the light from an OmniLight3D on to a 1x1m PlaneMesh sitting below the light. The light should be centred over the plane on X and Z. In my example screenshots the OmniLight3D is 0.75m above the plane on the Y and has Range 1m, Attenuation 2, Specular 0. Denoiser and Use Bicubic Filter are both off.
### Minimal reproduction project (MRP)
The MRP in https://github.com/godotengine/godot/issues/112786 demonstrates the same thing for both a PlaneMesh and an imported mesh.
Contributor guide
Research direction
Start with the LightmapGI baking path and reproduce the centered OmniLight3D over a 1x1m PlaneMesh, using the MRP referenced in issue #112786. Compare generated lightmaps across 4.1.1, 4.1.2, 4.4, and 4.5.1; done means the baked light is centered and symmetrical when the light is centered over the plane.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100