Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Fixing confusing near and far fields in Camera #4457

Closed
wants to merge 11 commits into from
Closed
4 changes: 0 additions & 4 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ fn load_node(

node.insert(Camera {
projection_matrix: orthographic_projection.get_projection_matrix(),
near: orthographic_projection.near,
far: orthographic_projection.far,
..Default::default()
});
node.insert(orthographic_projection);
Expand All @@ -753,8 +751,6 @@ fn load_node(
}
node.insert(Camera {
projection_matrix: perspective_projection.get_projection_matrix(),
near: perspective_projection.near,
far: perspective_projection.far,
..Default::default()
});
node.insert(perspective_projection);
Expand Down
3 changes: 0 additions & 3 deletions crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ pub enum SimulationLightSystems {
/// rendering
#[derive(Debug, Copy, Clone)]
pub enum ClusterFarZMode {
/// Use the camera far-plane to determine the z-depth of the furthest cluster layer
CameraFarPlane,
/// Calculate the required maximum z-depth based on currently visible lights.
/// Makes better use of available clusters, speeding up GPU lighting operations
/// at the expense of some CPU time and using more indices in the cluster light
Expand Down Expand Up @@ -806,7 +804,6 @@ pub(crate) fn assign_lights_to_clusters(
let is_orthographic = camera.projection_matrix.w_axis.w == 1.0;

let far_z = match config.far_z_mode() {
ClusterFarZMode::CameraFarPlane => camera.far,
ClusterFarZMode::MaxLightRange => {
let inverse_view_row_2 = inverse_view_transform.row(2);
lights
Expand Down
8 changes: 0 additions & 8 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ pub struct ExtractedDirectionalLight {
shadows_enabled: bool,
shadow_depth_bias: f32,
shadow_normal_bias: f32,
near: f32,
far: f32,
}

pub type ExtractedDirectionalLightShadowMap = DirectionalLightShadowMap;
Expand Down Expand Up @@ -513,8 +511,6 @@ pub fn extract_lights(
shadow_normal_bias: directional_light.shadow_normal_bias
* directional_light_texel_size
* std::f32::consts::SQRT_2,
near: directional_light.shadow_projection.near,
far: directional_light.shadow_projection.far,
},
render_visible_entities,
));
Expand Down Expand Up @@ -861,8 +857,6 @@ pub fn prepare_lights(
height: point_light_shadow_map.size as u32,
transform: view_translation * *view_rotation,
projection: cube_face_projection,
near: POINT_LIGHT_NEAR_Z,
far: light.range,
},
RenderPhase::<Shadow>::default(),
LightEntity::Point {
Expand Down Expand Up @@ -946,8 +940,6 @@ pub fn prepare_lights(
height: directional_light_shadow_map.size as u32,
transform: GlobalTransform::from_matrix(view.inverse()),
projection,
near: light.near,
far: light.far,
},
RenderPhase::<Shadow>::default(),
LightEntity::Directional { light_entity },
Expand Down
18 changes: 3 additions & 15 deletions crates/bevy_render/src/camera/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ impl<M: Component + Default> PerspectiveCameraBundle<M> {
perspective_projection.far(),
);
PerspectiveCameraBundle {
camera: Camera {
near: perspective_projection.near,
far: perspective_projection.far,
..Default::default()
},
camera: Camera::default(),
perspective_projection,
visible_entities: VisibleEntities::default(),
frustum,
Expand Down Expand Up @@ -99,11 +95,7 @@ impl OrthographicCameraBundle<Camera3d> {
orthographic_projection.far(),
);
OrthographicCameraBundle {
camera: Camera {
near: orthographic_projection.near,
far: orthographic_projection.far,
..Default::default()
},
camera: Camera::default(),
orthographic_projection,
visible_entities: VisibleEntities::default(),
frustum,
Expand Down Expand Up @@ -151,11 +143,7 @@ impl OrthographicCameraBundle<Camera2d> {
orthographic_projection.far(),
);
OrthographicCameraBundle {
camera: Camera {
near: orthographic_projection.near,
far: orthographic_projection.far,
..Default::default()
},
camera: Camera::default(),
orthographic_projection,
visible_entities: VisibleEntities::default(),
frustum,
Expand Down
4 changes: 0 additions & 4 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ pub struct Camera {
pub target: RenderTarget,
#[reflect(ignore)]
pub depth_calculation: DepthCalculation,
pub near: f32,
pub far: f32,
}

#[derive(Debug, Clone, Reflect, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -314,8 +312,6 @@ pub fn extract_cameras<M: Component + Default>(
transform: *transform,
width: size.x.max(1),
height: size.y.max(1),
near: camera.near,
far: camera.far,
},
visible_entities.clone(),
M::default(),
Expand Down
6 changes: 0 additions & 6 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ pub struct ExtractedView {
pub transform: GlobalTransform,
pub width: u32,
pub height: u32,
pub near: f32,
pub far: f32,
}

#[derive(Clone, AsStd140)]
Expand All @@ -91,8 +89,6 @@ pub struct ViewUniform {
inverse_view: Mat4,
projection: Mat4,
world_position: Vec3,
near: f32,
far: f32,
AronDerenyi marked this conversation as resolved.
Show resolved Hide resolved
width: f32,
height: f32,
}
Expand Down Expand Up @@ -156,8 +152,6 @@ fn prepare_view_uniforms(
inverse_view,
projection,
world_position: camera.transform.translation,
near: camera.near,
far: camera.far,
width: camera.width as f32,
height: camera.height as f32,
}),
Expand Down
6 changes: 1 addition & 5 deletions examples/tools/scene_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,7 @@ fn camera_spawn_check(

info!("Spawning a 3D perspective camera");
commands.spawn_bundle(PerspectiveCameraBundle {
camera: Camera {
near: perspective_projection.near,
far: perspective_projection.far,
..default()
},
camera: Camera::default(),
perspective_projection,
frustum,
transform,
Expand Down