Volumetric fog: no sunlight in fog beyond the last shadow cascade (cascade index not checked against `num_cascades`)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- computer-graphics, game-dev
Research direction
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.
Written by the indexing model from the issue text.
Description
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) {
- Dominant language
- Rust
- Stars
- 50k
- Forks
- 5.1k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 129
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
-
C-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bevyengine/bevy#26718 ·
Maintainers usually reply within 2 days
-
C-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bevyengine/bevy#26689 ·
Maintainers usually reply within 2 days
-
Volumetric fog: a `FogVolume` with `Visibility::Hidden` is still renderedPossibly taken @adityawrk claimed this 2 days ago. OpenC-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
bevyengine/bevy#26688 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
bevyengine/bevy#26684 ·
Maintainers usually reply within 2 days
-
Create a bevy_fuzzy examplePossibly taken @Tatsuya0330 claimed this 1 day ago. OpenA-UI C-Examples C-Feature D-Straightforward S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bevyengine/bevy#26676 ·
Maintainers usually reply within 2 days
Similar issues
-
area:ui effort:medium enhancement P7 source:agent
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
documentation priority: low tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
nledford/Ladderback#1823 ·
Maintainers usually reply within 1 day
-
psmux-resurrect: restoring a session with a numeric name puts its windows into the wrong session (`new-window -t 4` is read as window 4)Possibly taken @ealwanlee claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
psmux/psmux-plugins#47 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
Maintainers usually reply within 1 day