-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
update OrthographicProjection/Camera2dBundle default implementations #12454
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
Conversation
|
It seems kinda weird to me for a 3d ortho cam to render things behind it. I've seen that cause bugs as well, namely in picking and rendering, because people expect the camera near plane to be at the same position as the camera origin, especially in 3D. E.g.: aevyrie/bevy_mod_picking#209 (comment) Maybe it makes sense for us to have different camera projection types for ortho 2d and 3d? We could then warn if a 2d camera has a 3d projection component, or vice versa. Having a different projection type in commands.spawn(Camera2dBundle {
transform: Transform::from_translation(Vec2::splat(10.0).extend(0.0)),
..Default::default()
});
// produces the same OrthographicProjection2d as below:
commands.spawn(Camera2dBunde {
transform: Transform::from_translation(Vec2::splat(10.0).extend(0.0)),
projection: OrthographicProjection2d {
ScalingMode: ScalingMode::WindowSize(200.0),
..Default::default()
}
..Default::default()
});As it stands, I think the proposed change would just end up causing the inverse problem for 3D users. |
|
I agree the inverse problem could occur, however, the code for a 3D orthographic perspective is far more likely to be scrutinized. I'm willing to find a proper replacement, although I'm not sure more perspectives is the answer. This change was more motivated by multiple people having issues with objects not rendering, and hopefully making it better for the person new to bevy. |
What makes you say that? The code and usage are effectively identical. Changing the defaults is just pushing the errors onto 3d users. From a quick search, it looks like Godot, Unreal, and Unity all use 0.0 or 0.01 as their default 3d ortho near clipping planes, so this would be a pretty surprising divergence from norms. Current behavior of default impls is definitely a footgun for 2D users, but this looks more like a design problem than a problem with the default values. It seems to me that 2D ortho and 3d ortho have different semantic meaning, which could be a good argument for a split type. There is also an ongoing discussion in the math channel in discord, about improving bevy's The other reason to avoid changing the defaults as a solution is that this seems likely to become an issue that bounces back and forth, where 3D users want to change the default to 0.0, and we are back to the same problem with 2D. 🙂 |
|
It looks like there are a number of open issues/PRs related to this. Notably:
Additionally, it looks like the change you made here has already happened once, and I assume was reverted: Yup, looks like this exact change was made, then reverted due to how it would effect 3d: |
This is worded better.
As this has already been reverted, I'll close this and will probably drop in on the discussions on discord. |
|
@Laocoon7, thanks for the link, I think I understand your point a bit better. Sorry to be the bearer of bad news, it looks like this issue is deceptively tricky to get right. |
Objective
I have seen or heard of at least 3 instances in the last week of people asking for help with things not appearing in their world due to
Camera2dBundle::default()using a different orthographic projection settings thanOrthographicProjection::default().This causes many issues were objects don't display as expected when updating values inside the projection field (such as
ScalingMode).I say unexpected because:
Most people would not expect to be required to manually set the
near/farfields after usingDefault::default().Solution
Default
OrthographicProjection.nearto the value of-1000.0This would bring the default orthographic projection into line with what is expected from most 2d cameras. I think OrthographicProjection should treat 2d as first class, and 3d should specify their near value at 0 if they don't want to see behind them.
Camera2dBundlecould be changed to not override the near/far values in it's default implementation.Camera2dBundle::new_with_far()would need to be discussed? and probably just left aloneexamples/3d/orthographic.rsshould be fine, however we may want to set near back to 0 for this so that one cannot see behind them in a 3d environment?examples/3d/pbr.rssame as other examplesexamples/3d/many_lights.rssame as other examplesChangelog
Changed
OrthographicProjection::default()now has a near value of-1000.0from0.0bringing it into parity with expected results when building aCamera2dBundleMigration Guide
Verify any
OrthographicProjections built using..Default::default()have your expectednearfield set to the value you would like.