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

Aperta
#26,670 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
50k
Fork
5.1k
Merge medio
2g 20h
PR unite (30g)
129

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bevyengine/bevy

Tutte le issue di bevyengine/bevy

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.