Skip to content

Commit fb19b81

Browse files
authored
Extend the default render range of 2D camera (#9310)
# Objective - Fixes #9138 ## Solution - Calling `Camera2dBundle::default()` will now result in a `Camera2dBundle` with `Vec3::ZERO` transform, `far` value of `1000.` and `near` value of `-1000.`. - This will enable the rendering of 2d entities in negative z space by default. - I did not modify `new_with_far` as moving the camera to `Vec3::ZERO` in that function will cause entities in the positive z space to become hidden without further changes. And the further changes cannot be applied without it being a breaking change.
1 parent f14300e commit fb19b81

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

crates/bevy_core_pipeline/src/core_2d/camera_2d.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,32 @@ pub struct Camera2dBundle {
3535

3636
impl Default for Camera2dBundle {
3737
fn default() -> Self {
38-
Self::new_with_far(1000.0)
38+
let projection = OrthographicProjection {
39+
far: 1000.,
40+
near: -1000.,
41+
..Default::default()
42+
};
43+
let transform = Transform::default();
44+
let view_projection =
45+
projection.get_projection_matrix() * transform.compute_matrix().inverse();
46+
let frustum = Frustum::from_view_projection_custom_far(
47+
&view_projection,
48+
&transform.translation,
49+
&transform.back(),
50+
projection.far(),
51+
);
52+
Self {
53+
camera_render_graph: CameraRenderGraph::new(crate::core_2d::graph::NAME),
54+
projection,
55+
visible_entities: VisibleEntities::default(),
56+
frustum,
57+
transform,
58+
global_transform: Default::default(),
59+
camera: Camera::default(),
60+
camera_2d: Camera2d::default(),
61+
tonemapping: Tonemapping::None,
62+
deband_dither: DebandDither::Disabled,
63+
}
3964
}
4065
}
4166

0 commit comments

Comments
 (0)