Extend the default 2d render range to -1000..1000#9214
Extend the default 2d render range to -1000..1000#9214opstic wants to merge 1 commit intobevyengine:mainfrom opstic:render-with-negative-z
-1000..1000#9214Conversation
These seem potentially confusing to me. I'd expect calling this function that the camera would have the far plane I specified, and the near plane isn't even mentioned. What are your thoughts on renaming this function? Maybe |
|
@jnhyatt By the |
|
I didn't see you submitted a PR sorry ><' I commented something here: #9138 (comment) waiting for Cart or Alice's reply. (Edit: Alice put a 👍 reaction) |
|
I think it makes the most sense to use a negative near plane rather than moving the camera backwards. It seems like this change would make it too easy to accidentally make half your sprites disappear with something innocuous-looking: // Re-center camera
transform.translation = Vec3::ZERO;In this case, all your sprites with Z<0 would disappear and the reason would not be entirely obvious. |
|
@Selene-Amanita How do you think the API should look like? The But also, if the behavior of |
|
You could split it in two PRs:
|
|
That seems like a good path forward to me |
|
Closed in favor of #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
farvalue ofCamera2dBundleso that 2d entities with z values within the range of -1000 to 1000 gets rendered (defaultfarvalue is now2000).new_with_farfunction ofCamera2dBundlenow means thefarvalue will be split in two for both the positive and negative ranges (ex:new_with_far(1000.)=>-500..500,new_with_far(2000.)=>-1000..1000).