Directional lights sort shadow-casting and volumetric lights last, contrary to the comment, so they're the ones dropped past MAX_DIRECTIONAL_LIGHTS

Aperta Adatta ai principianti
#26,642 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
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, wasm

Direzione di ricerca

L'ordinamento si trova in prepare_lights in crates/bevy_pbr/src/render/light.rs, dove directional_light_entities.sort_by_cached_key ordina per (light.volumetric, light.shadow_maps_enabled, *entity) e il risultato viene troncato con .take(MAX_DIRECTIONAL_LIGHTS). Leggi questo blocco insieme al commento sopra, poi conferma che false viene ordinato per primo. Il lavoro è completo quando le luci che proiettano ombre e quelle volumetriche restano davanti a quelle senza ombra, e lo spareggio per entità è lasciato al suo posto. Verifica a mano il ragionamento sull'ordine, dato che l'issue non fornisce alcun test da eseguire.

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

Descrizione

Bevy version and features

  • 0.20.1. The same code is on main (crates/bevy_pbr/src/render/light.rs, prepare_lights).
  • Seen on WebGL2 (webgl2, wasm32), where MAX_DIRECTIONAL_LIGHTS is 1.

[Optional] Relevant system information

  • Rust 1.97.1, Chromium 156 on Linux.
AdapterInfo { name: "ANGLE (AMD, AMD Radeon RX 6650 XT (radeonsi navi23 ACO), OpenGL ES 3.2)", vendor: 4098, device: 0, device_type: Other, driver_info: "WebGL 2.0 (OpenGL ES 3.0 Chromium)", backend: Gl, .. }

What you did

Lit a scene with two DirectionalLights on the same layers: a bright sun and a dim fill light from the opposite side with shadow_maps_enabled: false. Built it for WebGL2, which warns The amount of directional lights of 2 is exceeding the supported limit of 1.

What went wrong

The comment above the sort says lights with volumetrics, then shadows, come first:

// Sort lights by
// - those with volumetric (and shadows) enabled first, ...
// - then those with shadows enabled second, ...
// - then by entity as a stable key ...
directional_light_entities.sort_by_cached_key(|entity| {
    let light = directional_lights.get(*entity).unwrap().2;
    (light.volumetric, light.shadow_maps_enabled, *entity)
});

But false sorts before true, so lights without volumetrics or shadows come first. Each view then keeps .take(MAX_DIRECTIONAL_LIGHTS), so past the limit it's the shadow-casting (or volumetric) light that gets dropped.

What we saw: on WebGL2, our scene was lit only by the dim fill light. With the sun's shadows on, the fill wins outright. With both lights shadowless, the entity tie-break decides, and which light won flipped between two builds of our app when we added an unrelated plugin.

Expected: the order the comment describes, Reverse on the first two keys or !light.volumetric, !light.shadow_maps_enabled. Then a shadowed sun is kept over a shadowless fill.

Additional information

  • Natively this only matters past 10 directional lights (or the volumetric/shadow counts derived from .take(MAX_DIRECTIONAL_LIGHTS)), since per-view shadow maps are capped by a running cascade count, not by index.
  • Workaround: we don't spawn the fill light on WebGL2.
Lingua principale
Rust
Stelle
49.8k
Fork
5.1k
Merge medio
3g 4h
PR unite (30g)
136

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.