-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Extend the default render range of 2D camera #9310
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context, point 1 of #9214 (comment) (calling new_with_far
then setting the near
) could lead to a problem if someone tries to read the Frustum after calling default
from the Bundle
directly (before insertion), and changing the behavior of new_with_far
would be a problem if someone relies on it.
I talked with @opstic and we agreed that duplicating the code of new_with_far
might be the best course of action for 0.11.1, and then we can clean-up code for 0.12.0 as explained in the previous comment.
# 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.
Done in order to match similar change in Bevy's camera (see bevyengine/bevy#9310)
Done in order to match similar change in Bevy's camera (see bevyengine/bevy#9310)
Adopted PR from dmlary, all credit to them! #9915 Original description: # Objective The default value for `near` in `OrthographicProjection` should be different for 2d & 3d. For 2d using `near = -1000` allows bevy users to build up scenes using background `z = 0`, and foreground elements `z > 0` similar to css. However in 3d `near = -1000` results in objects behind the camera being rendered. Using `near = 0` works for 3d, but forces 2d users to assign `z <= 0` for rendered elements, putting the background at some arbitrary negative value. There is no common value for `near` that doesn't result in a footgun or usability issue for either 2d or 3d, so they should have separate values. There was discussion about other options in the discord [0](https://discord.com/channels/691052431525675048/1154114310042292325), but splitting `default()` into `default_2d()` and `default_3d()` seemed like the lowest cost approach. Related/past work #9138, #9214, #9310, #9537 (thanks to @Selene-Amanita for the list) ## Solution This commit splits `OrthographicProjection::default` into `default_2d` and `default_3d`. ## Migration Guide - In initialization of `OrthographicProjection`, change `..default()` to `..OrthographicProjection::default_2d()` or `..OrthographicProjection::default_3d()` Example: ```diff --- a/examples/3d/orthographic.rs +++ b/examples/3d/orthographic.rs @@ -20,7 +20,7 @@ fn setup( projection: OrthographicProjection { scale: 3.0, scaling_mode: ScalingMode::FixedVertical(2.0), - ..default() + ..OrthographicProjection::default_3d() } .into(), transform: Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ``` --------- Co-authored-by: David M. Lary <dmlary@gmail.com> Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Objective
Solution
Camera2dBundle::default()
will now result in aCamera2dBundle
withVec3::ZERO
transform,far
value of1000.
andnear
value of-1000.
.new_with_far
as moving the camera toVec3::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.