`PerspectiveProjection::near` does not work.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version and features
- Bevy 0.18.1
## What you did
1. Change the camera projection's near field.
2. Put something close to the near field.
```rust
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn((
Camera3d::default(),
Projection::Perspective(PerspectiveProjection {
near: 0.01,
// Explicitly calculating the near clip plane works.
// near_clip_plane: vec4(0.0, 0.0, -1.0, -0.01),
..Default::default()
}),
));
commands.spawn(DirectionalLight::default());
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(
materials.add(StandardMaterial::from_color(Color::Srgba(Srgba::rgb(
1.0, 0.0, 0.0,
)))),
),
Transform::from_xyz(0.0, 0.0, -0.55),
// Moving it outside the default near plane of 0.1 works.
// Transform::from_xyz(0.0, 0.0, -0.65),
));
}
```
This renders red of the cube is beyond the near clipping plane. It renders grey if the cube is in front of the near clipping plane.
## What went wrong
The `near` field does nothing now. Only setting the `near_clip_plane` field works.
Contributor guide
Research direction
Start by reproducing the supplied Bevy 0.18.1 example and inspect the PerspectiveProjection near and near_clip_plane entry points. Verify how each affects the camera's clipping behavior, then confirm that changing near alone clips the cube at the requested distance while the existing near_clip_plane behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 63/100