Volumetric fog: ambient light is added once per ray and ignores density

Open
#26,670 0 comments 0 reactions 0 assignees View on GitHub

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

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

C-Bug S-Needs-Triage

Bevy version and features

  • 0.20.1
  • Default features; the camera has VolumetricFog with a non-zero ambient_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 full ambient_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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bevyengine/bevy

All issues in bevyengine/bevy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.