Volumetric fog: rays are marched over the depth difference, not the ray length — off-axis rays are too short
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- computer-graphics
Research direction
Start in bevy_pbr/src/volumetric_fog/volumetric_fog.wesl and compare how ray_length_view is used for ray marching and the ambient term. The report gives the proposed correction for step_size_world and notes the ambient term has the same depth-versus-ray-length issue. Check the fog rendering path and relevant tests; done means off-axis rays use their full ray length and transmittance varies as expected across the screen.
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 wide-angle camera inside a large uniform FogVolume, a white unlit wall 50 m in front of it,
perpendicular to the view axis. The fog only absorbs (light_intensity: 0.0, no ambient), so the
wall shows the fog's transmittance exp(-σ · ray length) directly:
use bevy::light::{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(),
Projection::Perspective(PerspectiveProjection { fov: 100f32.to_radians(), ..default() }),
Transform::default(),
VolumetricFog { ambient_intensity: 0.0, ..default() },
));
// The fog needs a volumetric light to be drawn at all; the fog itself ignores it (light_intensity 0).
commands.spawn((
DirectionalLight::default(),
VolumetricLight,
Transform::from_xyz(0.0, 1.0, 1.0).looking_at(Vec3::ZERO, Vec3::Y),
));
// A white unlit wall 50 m in front of the camera, perpendicular to the view axis.
commands.spawn((
Mesh3d(meshes.add(Plane3d::new(Vec3::Z, Vec2::splat(500.0)))),
MeshMaterial3d(materials.add(StandardMaterial { base_color: Color::WHITE, unlit: true, ..default() })),
Transform::from_xyz(0.0, 0.0, -50.0),
));
// Uniform fog around the camera: absorption only, so the wall shows the transmittance exp(-σ·length).
commands.spawn((
FogVolume { density_factor: 0.02, light_intensity: 0.0, ..default() },
Transform::from_scale(Vec3::splat(400.0)),
));
}
What went wrong
- Expected: the wall gets darker towards the edges of the screen — the ray to the centre is 50 m
long, the ray to a corner of this frame about 130 m (50 / cos 68°). - Actual: the wall is one flat grey, as if every ray were 50 m long. Off-axis rays are shortened by
cos(angle to the view axis), so fog is always thinner at the sides of the screen than in the
middle. In our game (ultrawide, about 110° horizontally) this showed up as a bright blob in the
middle of the screen that followed the camera.
Left: the example above. Right: the same example with the one-line fix below.
Additional information
bevy_pbr/src/volumetric_fog/volumetric_fog.wesl:
let ray_length_view = max(0.0, end_depth_view - start_depth_view); // difference of view-space depths
...
let step_size_world = ray_length_view * inv_step_count;
...
let P_view = start_pos_view + Rd_view * f32(step) * step_size_world; // but steps go along the normalized ray
The length along the ray is (end_depth_view - start_depth_view) / -Rd_view.z. Suggested fix
(one line):
let step_size_world = ray_length_view * inv_step_count / max(-Rd_view.z, 1e-3);
The ambient term before the loop, exp(-ray_length_view * (absorption + scattering)), has the
same mistake.
- 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
-
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
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bevyengine/bevy#26649 ·
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