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

Extend the default render range of 2D camera #9310

Merged
merged 1 commit into from
Jul 31, 2023
Merged

Extend the default render range of 2D camera #9310

merged 1 commit into from
Jul 31, 2023

Conversation

opstic
Copy link
Contributor

@opstic opstic commented Jul 30, 2023

Objective

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.

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.

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.

@Selene-Amanita Selene-Amanita added A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use labels Jul 30, 2023
@Selene-Amanita Selene-Amanita added this to the 0.11.1 milestone Jul 30, 2023
@Selene-Amanita Selene-Amanita 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 Jul 31, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 31, 2023
Merged via the queue into bevyengine:main with commit fb19b81 Jul 31, 2023
24 checks passed
@opstic opstic deleted the negative-z-default branch July 31, 2023 22:59
cart pushed a commit that referenced this pull request Aug 10, 2023
# 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.
drakmaniso pushed a commit to drakmaniso/bevy_pixel_camera that referenced this pull request Sep 8, 2023
Done in order to match similar change in Bevy's camera (see
bevyengine/bevy#9310)
drakmaniso added a commit to drakmaniso/bevy_pixel_camera that referenced this pull request Sep 8, 2023
Done in order to match similar change in Bevy's camera (see
bevyengine/bevy#9310)
@cart cart mentioned this pull request Oct 13, 2023
43 tasks
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 <dmlary@gmail.com>
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
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 simple quality-of-life change that makes Bevy easier to use 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.

Sprites not being rendered with translation.z < 0.0
4 participants