Volumetric fog: no sunlight in fog beyond the last shadow cascade (cascade index not checked against `num_cascades`)
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
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- computer-graphics, game-dev
Direzione di ricerca
Start with bevy_pbr/src/volumetric_fog/volumetric_fog.wesl and compare its cascade handling with shadows.wesl in fetch_directional_shadow. Check how get_cascade_index behaves beyond num_cascades and how the fog shader accesses the cascades array. Done when fog beyond the last shadow cascade receives sunlight without accessing an out-of-range cascade.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bevy version and features
- 0.20.1 (the code is the same on
main) - Features: default +
dlss
[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 DirectionalLight with shadows and VolumetricLight, one shadow cascade up to 20 m, and a row
of small fog cubes 5…50 m from the camera:
use bevy::light::{CascadeShadowConfigBuilder, FogVolume, VolumetricFog, VolumetricLight};
use bevy::prelude::*;
fn main() {
App::new().add_plugins(DefaultPlugins).add_systems(Startup, setup).run();
}
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>) {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(4.0, 4.0, 5.0).looking_at(Vec3::new(0.0, 1.0, -20.0), Vec3::Y),
VolumetricFog { ambient_intensity: 0.0, ..default() },
));
// One shadow cascade, 20 m.
commands.spawn((
DirectionalLight { shadow_maps_enabled: true, illuminance: 32000.0, ..default() },
VolumetricLight,
CascadeShadowConfigBuilder { num_cascades: 1, maximum_distance: 20.0, ..default() }.build(),
Transform::from_xyz(1.0, 1.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
));
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(400.0, 400.0))),
MeshMaterial3d(materials.add(Color::srgb(0.05, 0.05, 0.05))),
));
// A row of small fog cubes, 5 m apart, 5…50 m from the camera.
for i in 0..10 {
commands.spawn((
FogVolume { density_factor: 1.0, ..default() },
Transform::from_xyz(0.0, 1.0, -5.0 * i as f32).with_scale(Vec3::splat(2.0)),
));
}
}
What went wrong
- Expected: all cubes are lit by the sun. Beyond the last cascade there is no shadow information,
so the fog should be lit, the same as surfaces there. - Actual: every cube farther than 20 m from the camera gets no sunlight at all and only darkens
what is behind it. With 4 cascades the index goes past the end of thecascadesarray
(MAX_CASCADES_PER_LIGHT = 4), so the result depends on how the backend clamps it.
Left: the example above. Right: the same example with the fix below.
Additional information
bevy_pbr/src/volumetric_fog/volumetric_fog.wesl:
let cascade_index = get_cascade_index(light_index, P_view.z); // == num_cascades beyond the last cascade
let light_local = world_to_directional_light_local(light_index, cascade_index, ...);
var local_light_attenuation = f32(light_local.w != 0.0); // unused cascade → w == 0 → no light
if (local_light_attenuation != 0.0) {
let cascade = &(*light).cascades[cascade_index];
Regular shadows check this case (shadows.wesl, fetch_directional_shadow:
if (cascade_index >= (*light).num_cascades) { return 1.0; }), the fog doesn't. Suggested fix:
let cascade_found = get_cascade_index(light_index, P_view.z);
let in_cascades = cascade_found < (*light).num_cascades;
let cascade_index = min(cascade_found, max((*light).num_cascades, 1u) - 1u);
...
var local_light_attenuation = select(1.0, f32(light_local.w != 0.0), in_cascades);
if (in_cascades && local_light_attenuation != 0.0) {
- Lingua principale
- Rust
- Stelle
- 50k
- Fork
- 5.1k
- Merge medio
- 2g 20h
- PR unite (30g)
- 129
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bevyengine/bevy
-
C-Bug S-Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
bevyengine/bevy#26718 ·
I maintainer di solito rispondono entro 2 giorni
-
C-Bug S-Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
bevyengine/bevy#26689 ·
I maintainer di solito rispondono entro 2 giorni
-
Volumetric fog: a `FogVolume` with `Visibility::Hidden` is still renderedForse già presa @adityawrk l’ha presa 2 giorni fa. ApertaC-Bug S-Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
bevyengine/bevy#26688 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
bevyengine/bevy#26684 ·
I maintainer di solito rispondono entro 2 giorni
-
Create a bevy_fuzzy exampleForse già presa @Tatsuya0330 l’ha presa 1 giorno fa. ApertaA-UI C-Examples C-Feature D-Straightforward S-Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
bevyengine/bevy#26676 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di bevyengine/bevy
Issue simili
-
area:ui effort:medium enhancement P7 source:agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousApertamaintainer-needed p2 remote triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug help wanted ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#4605 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno