Volumetric fog: ambient light is added once per ray and ignores density
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- computer-graphics, game-dev
Research direction
Read bevy_pbr/src/volumetric_fog/volumetric_fog.wesl, especially the ambient initialization before the ray march and the directional light accumulation inside it. Compare the ambient term with the march's density and background_alpha handling. Done when ambient glow follows fog density and empty areas no longer show a veil; check the result with a density texture that has both dense and zero-density regions.
Written by the indexing model from the issue text.
Description
Bevy version and features
- 0.20.1
- Default features; the camera has
VolumetricFogwith a non-zeroambient_intensity.
[Optional] Relevant system information
cargo 1.99.1 (5f94df478 2026-08-27)- Windows 11
AdapterInfo { name: "NVIDIA GeForce RTX 5080", vendor: 4318, device: 11266, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "616.92", backend: Vulkan }
What you did
A FogVolume with a 3D density texture (patchy ground fog: dense in some places, zero in
others) and VolumetricFog::ambient_intensity > 0.
What went wrong
- Expected: ambient light scattered by the fog, so more fog → more ambient glow, and no glow
where the density is zero. - Actual: the ambient term doesn't depend on density at all. Pixels with short rays through
the volume (objects close to the camera) get the fullambient_color * ambient_intensity,
including where the density texture is zero: a uniform veil. Long rays through a large volume
get almost none, so large volumes look dark.
Additional information
bevy_pbr/src/volumetric_fog/volumetric_fog.wesl, before the ray march:
// Use Beer's law again to accumulate the ambient light all along the path.
var accumulated_color = exp(-ray_length_view * (absorption + scattering)) * ambient_color *
ambient_intensity;
The comment says the ambient light is accumulated along the path, but it is added once, before
the march. It isn't multiplied by density, fog_color or scattering, and the
exp(-ray_length_view * ...) term uses the full ray length without density, so it doesn't
match the background_alpha that the march computes.
Workaround / proposed fix: start from zero and accumulate the ambient light inside the march
loop, the same way as the directional light:
var accumulated_color = vec3(0.0);
...
background_alpha *= sample_attenuation;
accumulated_color += ambient_color * ambient_intensity * fog_color * scattering * density *
step_size_world * exposure * background_alpha;
With this change the ambient glow follows the fog density and the veil over empty areas is
gone. Note that it changes how bright a given ambient_intensity looks.
Related: #26669 (direct light in large volumes).
Tested on one machine.
- Dominant language
- Rust
- Stars
- 50k
- Forks
- 5.1k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 129
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bevyengine/bevy
-
C-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bevyengine/bevy#26718 ·
Maintainers usually reply within 2 days
-
C-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bevyengine/bevy#26689 ·
Maintainers usually reply within 2 days
-
Volumetric fog: a `FogVolume` with `Visibility::Hidden` is still renderedPossibly taken @adityawrk claimed this 2 days ago. OpenC-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
bevyengine/bevy#26688 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
bevyengine/bevy#26684 ·
Maintainers usually reply within 2 days
-
Create a bevy_fuzzy examplePossibly taken @Tatsuya0330 claimed this 1 day ago. OpenA-UI C-Examples C-Feature D-Straightforward S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bevyengine/bevy#26676 ·
Maintainers usually reply within 2 days
Similar issues
-
area:ui effort:medium enhancement P7 source:agent
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
documentation priority: low tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
nledford/Ladderback#1823 ·
Maintainers usually reply within 1 day
-
psmux-resurrect: restoring a session with a numeric name puts its windows into the wrong session (`new-window -t 4` is read as window 4)Possibly taken @ealwanlee claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
psmux/psmux-plugins#47 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
Maintainers usually reply within 1 day