FogVolume planes are rendered incorrectly when looked at from certain angles
Open
A-Rendering
C-Bug
S-Needs-Investigation
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
Bevy v0.15.0-dev 739007f
## What you did
I created a simple scene with a small `FogVolume` and a camera that rotates with mouse movement.
## What went wrong
When looking at the volume from certain angles, its planes suddenly begin to render in the wrong place.
https://github.com/user-attachments/assets/fadb3756-1f47-45a8-807a-d0154c20fb87
Minimal reproduction example
use bevy::input::mouse::MouseMotion;
use bevy::pbr::{FogVolume, FogVolumeBundle, VolumetricFogSettings, VolumetricLight};
use bevy::prelude::*;
use bevy::window::{CursorGrabMode, CursorOptions};
use std::f32::consts::PI;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
cursor_options: CursorOptions {
visible: false,
grab_mode: CursorGrabMode::Confined,
..default()
},
..default()
}),
..default()
}))
.add_systems(Startup, setup)
.add_systems(Update, rotate_camera)
.run();
}
fn setup(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(1.1, 0.8, 0.7)
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
..default()
},
VolumetricFogSettings {
ambient_intensity: 0.01,
..default()
},
));
commands.spawn((
DirectionalLightBundle {
transform: Transform::from_xyz(-6.0, 5.0, -9.0)
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
directional_light: DirectionalLight {
illuminance: 32_000.0,
shadows_enabled: true,
..default()
},
..default()
},
VolumetricLight,
));
commands.spawn(FogVolumeBundle {
fog_volume: FogVolume {
density_factor: 1.0,
density_texture: Some(assets.load("volumes/fog_noise.ktx2")),
..default()
},
..default()
});
}
fn rotate_camera(
mut mouse_motions: EventReader<MouseMotion>,
mut query: Query<&mut Transform, With<Camera>>,
) {
for mut transform in query.iter_mut() {
for mouse_motion in mouse_motions.read() {
let (mut yaw, mut pitch, _) = transform.rotation.to_euler(EulerRot::YXZ);
let sensitivity = 0.2;
yaw -= (mouse_motion.delta.x * sensitivity).to_radians();
pitch -= (mouse_motion.delta.y * sensitivity).to_radians();
let max_pitch = PI * 0.5 - 0.001;
pitch = pitch.clamp(-max_pitch, max_pitch);
transform.rotation =
Quat::from_axis_angle(Vec3::Y, yaw) * Quat::from_axis_angle(Vec3::X, pitch);
}
}
}
I used subtle ambient intensity to highlight the bounds of the volume.
Contributor guide
Assessment
This issue has not been assessed yet.