Atmosphere: dark speckles on lit surfaces when the sun is at zenith (NaN in calculate_visible_sun_ratio)

Aperta Adatta ai principianti
#26,558 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à
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Inizia da calculate_visible_sun_ratio in bevy_pbr/src/atmosphere/functions.wesl, dove il coseno dello zenit entra in fast_acos_4, e confrontalo con il prodotto scalare non limitato mu_light in bevy_pbr/src/render/pbr_lighting.wesl. Riproduci con una luce direzionale puntata verso il basso sotto una camera Atmosphere e verifica la presenza di macchie scure vicino al punto subsolare. È fatto quando la superficie illuminata è illuminata in modo uniforme e la visibilità del sole rimane finita per ogni pixel.

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 uses Atmosphere + AtmosphereSettings.

[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 scene with an atmosphere on the camera and a directional light (the sun) pointing
straight down, i.e. the sun is exactly at the local zenith of the lit surface.

What went wrong

  • Expected: surfaces under the sun are evenly lit.
  • Actual: random pixels on lit surfaces lose all direct sunlight (only scattered light
    remains), which looks like dark speckles. They appear within a few tens of meters
    around the subsolar point and are gone about 100 m away from it.

Additional information

Theory: a NaN in calculate_visible_sun_ratio.

bevy_pbr/src/render/pbr_lighting.wesl:

let mu_light = dot(L, local_up); // not clamped, can be slightly > 1.0 due to f32 rounding

bevy_pbr/src/atmosphere/functions.wesl, calculate_visible_sun_ratio:

let sun_zenith_angle = fast_acos_4(mu);

fast_acos_4 computes sqrt(1.0 - abs(x)), which is NaN for |x| > 1. The visibility
ratio then becomes 0, and color *= transmittance * sun_visibility removes the sun
light for that pixel. sample_sun_radiance in the same file already clamps its argument.

Workaround / proposed fix (one line):

let sun_zenith_angle = fast_acos_4(clamp(mu, -1.0, 1.0));

With this change the speckles are gone. Reproduced with two different atmosphere
setups, always around the point where the sun is exactly overhead. Tested on one
machine only. Before/after screenshots attached.

изображение изображение
Lingua principale
Rust
Stelle
49.7k
Fork
5k
Merge medio
3g 16h
PR unite (30g)
128

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.