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

Update defaults for OrthographicProjection #9537

Merged
merged 1 commit into from
Aug 28, 2023

Conversation

rdrpenguin04
Copy link
Contributor

@rdrpenguin04 rdrpenguin04 commented Aug 22, 2023

Objective

These new defaults match what is used by Camera2dBundle::default(), removing a potential footgun from overriding a field in the projection component of the bundle.

Solution

Adjusted the near clipping plane of OrthographicProjection::default() to -1000..


Changelog

Changed: OrthographicProjection::default() now matches the value used in Camera2dBundle::default()

Migration Guide

Workarounds used to keep the projection consistent with the bundle defaults are no longer required. Meanwhile, uses of OrthographicProjection in 2D scenes may need to be adjusted; the near clipping plane default was changed from 0.0 to -1000.0.

Copy link
Member

@Selene-Amanita Selene-Amanita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the methods of Camera2dBundle could be cleaned up in this PR, like suggested in the second bullet point here: #9214 (comment) ? But I'm good with it as it is.

I think the migration guide could be a bit more explicit, especially for people who use OrthographicProjection in a 3D context, just something like "default value for OrthographicProjection.near changed from 0. to -1000.".

@Selene-Amanita Selene-Amanita added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Aug 22, 2023
@rdrpenguin04
Copy link
Contributor Author

Updated the migration guide. I could probably do a code cleanup PR separately.

Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came from a discussion in the discord server: https://discord.com/channels/691052431525675048/692572690833473578/1143435136738803782

Note: Is it possible to update the impl Default for Camera2dBundle in crates/bevy_core_pipeline/src/core_2d/camera_2d.rs to use OrthographicProjection::default()? So that if there is any deviation in the future, it is always explicit.

@@ -197,14 +197,16 @@ pub enum ScalingMode {
///
/// Note that the scale of the projection and the apparent size of objects are inversely proportional.
/// As the size of the projection increases, the size of objects decreases.
///
/// Note also that the view frustum is centered at the origin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However a justification here would be useful, like "This helps in 2D when both the camera and sprites are likely to be placed at z=0.0"

@nicopap
Copy link
Contributor

nicopap commented Aug 23, 2023

Provided the discord discussion, I don't think it's controversial.

@rdrpenguin04
Copy link
Contributor Author

rdrpenguin04 commented Aug 23, 2023

(re. impl Default) I'll fix that; you're the second person to ask 😄

@nicopap nicopap added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Aug 23, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 24, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 25, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 25, 2023
These new defaults match what is used by `Camera2dBundle::default()`, removing a potential footgun from overriding a field in the projection component of the bundle.
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 28, 2023
Merged via the queue into bevyengine:main with commit 5012a0f Aug 28, 2023
@dmlary
Copy link
Contributor

dmlary commented Sep 20, 2023

As mentioned in the discord, this is gonna cause problems for 3d. With this objects behind the camera are going to be rendered when they shouldn’t be visible.

Example: two xz planes, you put the camera between them pointed at one, and only the other will be visible.

I don’t know what the proper solution is, but devil_ira pointed out this is coming in 0.12

@Selene-Amanita
Copy link
Member

Selene-Amanita commented Sep 20, 2023

@dmlary I brought that up in the discord yeah, but still approved this change, my reasoning/assumption is that a lot of beginners with Bevy would either use 2D, or 3D with perspective projection, and those default values are convenient to avoid footguns for them. People using orthographic projection in 3D would probably know better how projections work and be able to troubleshoot an eventual problem more easily.

Maybe there should be other "static methods"/associated functions/constructors on OrthographicProjection to create one with a near = 0. though.

mnmaita added a commit to mnmaita/bevy that referenced this pull request Sep 20, 2023
github-merge-queue bot pushed a commit that referenced this pull request Sep 20, 2023
# Objective

- Fixes #9876

## Solution

- Reverted commit `5012a0fd57748ab6f146776368b4cf988bba1eaa` to restore
the previous default values for `OrthographicProjection`.

---

## Migration Guide

- Migration guide steps from #9537 should be removed for next release.
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
…bevyengine#9878)

# Objective

- Fixes bevyengine#9876

## Solution

- Reverted commit `5012a0fd57748ab6f146776368b4cf988bba1eaa` to restore
the previous default values for `OrthographicProjection`.

---

## Migration Guide

- Migration guide steps from bevyengine#9537 should be removed for next release.
github-merge-queue bot pushed a commit that referenced this pull request Sep 9, 2024
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 <[email protected]>
Co-authored-by: Jan Hohenheim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants