Directional lights sort shadow-casting and volumetric lights last, contrary to the comment, so they're the ones dropped past MAX_DIRECTIONAL_LIGHTS
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust, wasm
- Domain
- computer-graphics
Research direction
The sort is in prepare_lights in crates/bevy_pbr/src/render/light.rs, where directional_light_entities.sort_by_cached_key keys on (light.volumetric, light.shadow_maps_enabled, *entity) and the result is cut with .take(MAX_DIRECTIONAL_LIGHTS). Read that block alongside the comment above it, then confirm that false sorts first. Done means shadow-casting and volumetric lights are kept ahead of shadowless ones, with the entity tie-break left in place. Check the ordering reasoning by hand, since the issue gives no test to run.
Written by the indexing model from the issue text.
Description
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), whereMAX_DIRECTIONAL_LIGHTSis 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.
- Dominant language
- Rust
- Stars
- 49.8k
- Forks
- 5.1k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 136
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
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
bevyengine/bevy#26641 ·
Maintainers usually reply within 2 days
-
A-Animation AI-Assisted C-Bug D-Trivial S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bevyengine/bevy#26637 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bevyengine/bevy#26635 ·
Maintainers usually reply within 2 days
-
Feathers checkbox outline should have flex_shrink: 0Possibly taken @Tatsuya0330 claimed this today. OpenC-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
bevyengine/bevy#26630 ·
Maintainers usually reply within 2 days
-
A-UI C-Examples C-Refinement D-Straightforward S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bevyengine/bevy#26584 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
go good first issue test
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
bug triaged tui ux wontfix
Difficulty 2/5 Half a day Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day