godotengine / godotengine/godot
LightmapGI Environment lighting is polluting closed spaces
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in: v4.3.beta.custom_build.daa81bbb7d
### System information
Windows 10 - Godot v4.3.beta.custom_build.daa81bbb7d - Vulcan (Forward+) - Geforce GTX 960
### Issue description
# Info
It seems that when baking lightmaps, random rays miss the geometry and cause the interior of closed spaces to be illuminated by environment light.
Godot with `DEBUG_TEXTURES` enabled in `lightmapper_rd.cpp`.
# Example scene
a) basic 3D scene with solid color for background, ambient and reflected turned off for clarity

b) lightmap gi node with different solid color for environment, denoiser off, use texture off

c) omnilight with yet another color in the center
d) basic blender cube with normals pointing **inside**
# Results
Before bake:

After bake:

Although the geometry is closed on all sides, a lot of light from the environment gets in and hits the faces. This only happens in the “light_secondary” step. The green color of the environment is set from LightmapGI settings.
`2_light_primary_0.exr`

`4_light_secondary_0.exr`

# Box inside box
The situation changes a bit when the above cube is placed inside a larger one. In Blender, it looks as follows:

After bake:

You can see that fewer rays missed the geometry, but despite the thick walls surrounding the cube, environment leaks still occur (green).
Switching Environment in LightmapGI to “Scene” gives this result: environment still appears, but consistent with the WorldEnvironment setting (blue).

Increased exposure:

# Source
This section of `lm_compute.glsl` is most likely responsible for adding color of the environment:
https://github.com/godotengine/godot/blob/40b4130c93d08235a60996d29e5869a22b6ae53d/modules/lightmapper_rd/lm_compute.glsl#L532-L535
When you turn off the line **534** all the green environment from baked ligtmap disappears. Naturally, this causes the environment to be completely ignored, so it is not a solution. The question remains why and in what cases `trace_result == RAY_MISS`, if we are talking about closed spaces (and even closed spaces inside other closed spaces).
No green dots anywhere:

`4_light_secondary_0.exr` after commenting line 534:

### Steps to reproduce
Minimal reproduction project below.
### Minimal reproduction project (MRP)
[environment-pollute.zip](https://github.com/godotengine/godot/files/15381515/environment-pollute.zip)
Contributor guide
Research direction
Start with the minimal reproduction project and inspect the environment-light handling around lines 532-535 of modules/lightmapper_rd/lm_compute.glsl, using the DEBUG_TEXTURES output from lightmapper_rd.cpp. Determine why rays report RAY_MISS inside closed geometry, then verify that closed spaces no longer receive leaked environment light while valid environment lighting remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100