Skip to content

Commit f1be89d

Browse files
committedAug 14, 2022
Remove unused DepthCalculation enum (#5684)
# Objective Remove unused `enum DepthCalculation` and its usages. This was used to compute visible entities in the [old renderer](https://github.com/bevyengine/bevy/blob/db665b96c07084f081b0c9ab367e67297fe35132/crates/bevy_render/src/camera/visible_entities.rs), but is now unused. ## Solution `sed 's/DepthCalculation//g'` --- ## Changelog ### Changed Removed `bevy_render::camera::DepthCalculation`. ## Migration Guide Remove references to `bevy_render::camera::DepthCalculation`, such as `use bevy_render::camera::DepthCalculation`. Remove `depth_calculation` fields from Projections.
1 parent e84e391 commit f1be89d

File tree

5 files changed

+2
-41
lines changed

5 files changed

+2
-41
lines changed
 

‎crates/bevy_core_pipeline/src/core_2d/camera_2d.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use crate::clear_color::ClearColorConfig;
22
use bevy_ecs::{prelude::*, query::QueryItem};
33
use bevy_reflect::Reflect;
44
use bevy_render::{
5-
camera::{
6-
Camera, CameraProjection, CameraRenderGraph, DepthCalculation, OrthographicProjection,
7-
},
5+
camera::{Camera, CameraProjection, CameraRenderGraph, OrthographicProjection},
86
extract_component::ExtractComponent,
97
primitives::Frustum,
108
view::VisibleEntities,
@@ -56,7 +54,6 @@ impl Camera2dBundle {
5654
// the camera's translation by far and use a right handed coordinate system
5755
let projection = OrthographicProjection {
5856
far,
59-
depth_calculation: DepthCalculation::ZDifference,
6057
..Default::default()
6158
};
6259
let transform = Transform::from_xyz(0.0, 0.0, far - 0.1);

‎crates/bevy_render/src/camera/camera.rs

-15
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use bevy_ecs::{
1919
};
2020
use bevy_math::{Mat4, UVec2, Vec2, Vec3};
2121
use bevy_reflect::prelude::*;
22-
use bevy_reflect::FromReflect;
2322
use bevy_transform::components::GlobalTransform;
2423
use bevy_utils::HashSet;
2524
use bevy_window::{WindowCreated, WindowId, WindowResized, Windows};
@@ -82,8 +81,6 @@ pub struct Camera {
8281
/// If this is set to true, this camera will be rendered to its specified [`RenderTarget`]. If false, this
8382
/// camera will not be rendered.
8483
pub is_active: bool,
85-
/// The method used to calculate this camera's depth. This will be used for projections and visibility.
86-
pub depth_calculation: DepthCalculation,
8784
/// Computed values for this camera, such as the projection matrix and the render target size.
8885
#[reflect(ignore)]
8986
pub computed: ComputedCameraValues,
@@ -100,7 +97,6 @@ impl Default for Camera {
10097
viewport: None,
10198
computed: Default::default(),
10299
target: Default::default(),
103-
depth_calculation: Default::default(),
104100
}
105101
}
106102
}
@@ -310,16 +306,6 @@ impl RenderTarget {
310306
}
311307
}
312308

313-
#[derive(Debug, Clone, Copy, Default, Reflect, FromReflect, Serialize, Deserialize)]
314-
#[reflect(Serialize, Deserialize)]
315-
pub enum DepthCalculation {
316-
/// Pythagorean distance; works everywhere, more expensive to compute.
317-
#[default]
318-
Distance,
319-
/// Optimization for 2D; assuming the camera points towards `-Z`.
320-
ZDifference,
321-
}
322-
323309
pub fn camera_system<T: CameraProjection + Component>(
324310
mut window_resized_events: EventReader<WindowResized>,
325311
mut window_created_events: EventReader<WindowCreated>,
@@ -378,7 +364,6 @@ pub fn camera_system<T: CameraProjection + Component>(
378364
if let Some(size) = camera.logical_viewport_size() {
379365
camera_projection.update(size.x, size.y);
380366
camera.computed.projection_matrix = camera_projection.get_projection_matrix();
381-
camera.depth_calculation = camera_projection.depth_calculation();
382367
}
383368
}
384369
}

‎crates/bevy_render/src/camera/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ impl Plugin for CameraPlugin {
2626
.register_type::<VisibleEntities>()
2727
.register_type::<WindowOrigin>()
2828
.register_type::<ScalingMode>()
29-
.register_type::<DepthCalculation>()
3029
.register_type::<Aabb>()
3130
.register_type::<CameraRenderGraph>()
3231
.add_plugin(CameraProjectionPlugin::<Projection>::default())

‎crates/bevy_render/src/camera/projection.rs

-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::marker::PhantomData;
22

3-
use super::DepthCalculation;
43
use bevy_app::{App, CoreStage, Plugin, StartupStage};
54
use bevy_ecs::{prelude::*, reflect::ReflectComponent};
65
use bevy_math::Mat4;
@@ -42,7 +41,6 @@ impl<T: CameraProjection + Component + GetTypeRegistration> Plugin for CameraPro
4241
pub trait CameraProjection {
4342
fn get_projection_matrix(&self) -> Mat4;
4443
fn update(&mut self, width: f32, height: f32);
45-
fn depth_calculation(&self) -> DepthCalculation;
4644
fn far(&self) -> f32;
4745
}
4846

@@ -81,13 +79,6 @@ impl CameraProjection for Projection {
8179
}
8280
}
8381

84-
fn depth_calculation(&self) -> DepthCalculation {
85-
match self {
86-
Projection::Perspective(projection) => projection.depth_calculation(),
87-
Projection::Orthographic(projection) => projection.depth_calculation(),
88-
}
89-
}
90-
9182
fn far(&self) -> f32 {
9283
match self {
9384
Projection::Perspective(projection) => projection.far(),
@@ -120,10 +111,6 @@ impl CameraProjection for PerspectiveProjection {
120111
self.aspect_ratio = width / height;
121112
}
122113

123-
fn depth_calculation(&self) -> DepthCalculation {
124-
DepthCalculation::Distance
125-
}
126-
127114
fn far(&self) -> f32 {
128115
self.far
129116
}
@@ -179,7 +166,6 @@ pub struct OrthographicProjection {
179166
pub window_origin: WindowOrigin,
180167
pub scaling_mode: ScalingMode,
181168
pub scale: f32,
182-
pub depth_calculation: DepthCalculation,
183169
}
184170

185171
impl CameraProjection for OrthographicProjection {
@@ -245,10 +231,6 @@ impl CameraProjection for OrthographicProjection {
245231
}
246232
}
247233

248-
fn depth_calculation(&self) -> DepthCalculation {
249-
self.depth_calculation
250-
}
251-
252234
fn far(&self) -> f32 {
253235
self.far
254236
}
@@ -266,7 +248,6 @@ impl Default for OrthographicProjection {
266248
window_origin: WindowOrigin::Center,
267249
scaling_mode: ScalingMode::WindowSize,
268250
scale: 1.0,
269-
depth_calculation: DepthCalculation::Distance,
270251
}
271252
}
272253
}

‎crates/bevy_ui/src/render/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bevy_ecs::prelude::*;
1212
use bevy_math::{Mat4, Vec2, Vec3, Vec4Swizzles};
1313
use bevy_reflect::TypeUuid;
1414
use bevy_render::{
15-
camera::{Camera, CameraProjection, DepthCalculation, OrthographicProjection, WindowOrigin},
15+
camera::{Camera, CameraProjection, OrthographicProjection, WindowOrigin},
1616
color::Color,
1717
render_asset::RenderAssets,
1818
render_graph::{RenderGraph, RunGraphOnViewNode, SlotInfo, SlotType},
@@ -245,7 +245,6 @@ pub fn extract_default_ui_camera_view<T: Component>(
245245
let mut projection = OrthographicProjection {
246246
far: UI_CAMERA_FAR,
247247
window_origin: WindowOrigin::BottomLeft,
248-
depth_calculation: DepthCalculation::ZDifference,
249248
..Default::default()
250249
};
251250
projection.update(logical_size.x, logical_size.y);

0 commit comments

Comments
 (0)