Split OrthographicProjection::default into 2d & 3d#9915
Split OrthographicProjection::default into 2d & 3d#9915dmlary wants to merge 1 commit intobevyengine:mainfrom dmlary:orthographic_projection-defaults
Conversation
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 was discussion about other options in the discord [0], but this seemed like the lowest cost approach. This commit splits `OrthographicProjection::default` into `default_2d` and `default_3d`. [0]: https://discord.com/channels/691052431525675048/1154114310042292325
|
I'll be honest, I'm not in love with I'm opening this PR mostly for feedback and to continue the discussion about better options. |
|
Would it make sense to match how things like |
This was mentioned in discord. The net result of this is duplicating the entirety of the class, for different defaults. That feels wrong for code maintenance, despite providing a cleaner API. There’s a trait-based approach where all the code is implemented in trait default implementations, but that felt like a lot of added complexity to allow for one default value to be different. That said, if maintainers are ok with either option, we can definitely go that route. |
|
Another example of why it could be useful: https://discord.com/channels/691052431525675048/1167754343638904912/1167754343638904912 |
|
I would absolutely love to have projection settings be completely separate for 2d, with clipping planes removed completely. They just introduce complexity to 2d games, without providing any use cases that can't be solved by just changing visibility. Z-order of a sprite should not make it disappear just because of some arbitrary value on the 2d camera. Current system feels very Unity-like, where 2d is just an afterthought of a 3d system. |
|
This keeps coming up as a big footgun for beginners. Examples: It's a frustrating problem for beginners because it's easy to fall into this trap when simply trying to adjust scaling, and they end up thinking there's something wrong with scaling instead of it being related to near planes. |
|
This PR looks like it’s seeing movement, but I’m tied up and won’t be able to resolve the merge conflicts, and test. If someone wants to adopt it, please do so. |
1 similar comment
|
This PR looks like it’s seeing movement, but I’m tied up and won’t be able to resolve the merge conflicts, and test. If someone wants to adopt it, please do so. |
Done 👌 #15073 |
|
Adopted and merged :D |
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
The default value for
nearinOrthographicProjectionshould be different for 2d & 3d.For 2d using
near = -1000allows bevy users to build up scenes using backgroundz = 0, and foreground elementsz > 0similar to css. However in 3dnear = -1000results in objects behind the camera being rendered. Usingnear = 0works for 3d, but forces 2d users to assignz <= 0for rendered elements, putting the background at some arbitrary negative value.There is no common value for
nearthat 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, but splitting
default()intodefault_2d()anddefault_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::defaultintodefault_2danddefault_3d.Changelog
OrthographicProjection::default()removedOrthographicProjection::default_3d()addedOrthographicProjection::default_2d()addedimpl FromWorld for OrthographicProjectionadded; callsdefault_3d()#[derive(Reflect)]whenimpl DefaultremovedMigration Guide
OrthographicProjectionchange..default()to..OrthographicProjection::default_2d()or..OrthographicProjection::default_3d()Example: