-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Improve documentation relating to Frustum
and HalfSpace
#9136
Improve documentation relating to Frustum
and HalfSpace
#9136
Conversation
Frustum
and HalfSpace
Frustum
and HalfSpace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precise documentation is great to see!
Can't answer your questions except to say that I agree that visibility_propagate
should be pub (which isn't a breaking change). I actually have a question of my own now: Why are UpdateOrthographicFrusta
, UpdatePerspectiveFrusta
and UpdateProjectionFrusta
separate system sets?
Made some minor suggestions, feel free to ignore.
Co-authored-by: SpecificProtagonist <[email protected]>
Thanks for reviewing!
I... don't know actually, they're used for ordering but I think this could be made with the systems themselves inside the same SystemSet? I'll make another PR to make |
You'll get my review tomorrow. |
/// It represents a box covering the local space occupied by the entity, with faces | ||
/// orthogonal to the local axis. It is used as a component on an entity to determine | ||
/// if it should be rendered by a [`Camera`](crate::camera::Camera) entity if it | ||
/// intersects with its [`Frustum`], in a process called frustum culling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saying it's used for frustum culling is very limiting to Aabb
, which is why it's in the primitive module and not in view. Aabb
are often used for collisions, for debug, for sorting in space, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really? By third party crates or Bevy itself?
Because it's not inserted to entities with NoFrustumCulling
, so if it is used for something else, shouldn't NoFrustumCulling
be handled differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Bevy it's used just for frustum culling, but an aabb is a general type that have many uses. It's a component that users can use however they want, we shouldn't restrict it to frustum culling in its doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but since it's linked to NoFrustumCulling
(and not updated in some cases), I don't see it being used for something else, and I would not advise people to use it (as a component and without tweaking how Bevy inserts, uses and updates it) for something else either for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed partially by 936a912
/// It includes all the points from the bisecting plane towards `NEG_Z`, and the distance | ||
/// from the plane to the origin is `-8.0` along `NEG_Z`. | ||
/// | ||
/// It is used to define a [`Frustum`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
among other things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it used for something else in Bevy? I didn't want to imply it's the only usage, I just wanted to say it's only used for that in Bevy.
Edit: it is used for lights also, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to It is used to define a [Frustum], and for light computation.
in dee7a95
Is that okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as aabb, those are general types and component, doc shouldn't restrict how they are used.
I'm not sure I see the point of documenting that here anyway. being able to go from the frustrum doc to the half space is interesting, not the reverse in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to have a concrete example of what it is used for instead of just having it and not knowing how it can be used or fits in Bevy.
I don't really see how my sentence implies it can't be used for something else? I can add "for example", or "among other things" (which feels a bit like lying because in official Bevy it's not), at the end?
Edit: added "for example".
…d add HalfSpace usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the phrasing could be streamlined.
/// It represents a box covering the local space occupied by the entity, with faces | ||
/// orthogonal to the axis. It is used as a component on an entity to determine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is convoluted because it tries to define the AABB as two different things:
- An axis-aligned bounding box: cube aligned to axis
- The space occcupied by mesh entities.
I'd suggest to keeping to (1) as definition, and mentioning "this is also used as" in a subsequent sentence (or maybe remove it, you describe (2) already in the rest of this paragraph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adressed by: 936a912
/// if it should be rendered by a [`Camera`](crate::camera::Camera) entity if it | ||
/// intersects with its [`Frustum`], in a process called frustum culling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "in a process called frustum culling" Here feels dissociated from the rest of the sentence. You probably need to start a sentence, using it a subject, in order to make the sentence coherent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used as a component on an entity during "frustum culling", a process to determine if the entity should be rendered [...]
?
/// It will be added automatically to entities that could be subject to frustum | ||
/// culling, and don't have the [`NoFrustumCulling`](crate::view::visibility::NoFrustumCulling) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless this is describe in NoFrustrumCulling
it could be nice to specify what a "entity that could be subject to frustum culling" is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't but I'm not sure myself why would you want to opt out of it actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #4971. Also in situations related to global lighting/reflection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because in animation the Mesh's vertices positions are updated, but the Aabb is not, right?
Lighting/reflection is for when you have a Mesh with a reflective material and you want to see something in it that is out of frustum, right?
I'm trying to write meaningful examples, I have this:
/// It can be used for example:
/// - when a [`Mesh`] is updated but its [`Aabb`] is not, which might happen with animations,
/// - when using some light effects, like wanting a [`Mesh`] out of the [`Frustum`]
/// to appear in the reflection of a [`Mesh`] within.```
/// component, using the systems in | ||
/// [`CalculateBounds`](crate::view::visibility::VisibilitySystems::CalculateBounds). | ||
/// | ||
/// It won't be updated automatically if the space occupied by the entity changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing. Here is a suggestion: "Currently, bevy doesn't update AABB based on changes to the Mesh
pointed to by the handle."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add that in a "for example" section after (I think it's a good idea), but Aabb don't apply only to Handle<Mesh>
.
Edit: added this:
/// It won't be updated automatically if the space occupied by the entity changes,
/// for example if the vertex positions of a [`Mesh`] inside a `Handle<Mesh>` are
/// updated.
/// This distance helps determine the position of a point `p` on the bisecting plane, as per the equation `n.p + d = 0`. | ||
/// Returns the signed distance from the bisecting plane to the origin along | ||
/// the plane's unit normal vector. | ||
/// This distance helps determine the position of a point `p` relative to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: (I know it is pre-existing text) the "helps determine" is complex, could the sentence be simplified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I would kinda be in favor of removing that sentence completely, it's already explained in the HalfSpace
doc and you can do nothing with the distance alone anyway you need the normal for the formula, if this formula should be copied somewhere I would argue it should be in normal_d
.
This sentence was written for Plane
to know on which side of the plane we are.
Edit: I just removed it.
/// or the `Camera3dBundle`, and is typically updated automatically by | ||
/// [`update_frusta`](crate::view::visibility::update_frusta) from the | ||
/// [`CameraProjection`](crate::camera::CameraProjection) component of the camera entity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentence would benefit from being split in two, such as the updating can be explained in isolation from the adding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My French brain struggles to make short sentences 😄 (I agree)
Edit: changed to:
/// The frustum component is typically added from a bundle, either the `Camera2dBundle`
/// or the `Camera3dBundle`.
/// It is usually updated automatically by [`update_frusta`] from the
/// [`CameraProjection`] component and [`GlobalTransform`] of the camera entity.
@@ -253,6 +259,10 @@ impl Plugin for VisibilityPlugin { | |||
} | |||
} | |||
|
|||
/// System calculating and inserting an [`Aabb`] component to entities with a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// System calculating and inserting an [`Aabb`] component to entities with a | |
/// Computes and adds an [`Aabb`] component to entities with a |
I find sentences in the present participle (-ing) are much more difficult to parse than in the simple present. I'd suggest avoiding (I know) them. Ideally avoid indirection in your sentences, it helps clarity; Much like in programming languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the sentence bellow to keep the information that it's a system: Used in system set
-> This system is used [...]
/// System updating the [`Frustum`] component of an entity, typically a [`Camera`], | ||
/// using its [`GlobalTransform`] and the projection matrix from its [`CameraProjection`] | ||
/// component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least remove "of an entity" here. Components are necessarily part of an entity, it's redundant. Also, if split into two paragraphs, it will be much easier to read. Though I'm not sure the second paragraph is necessary, since it doesn't provide much more information than the type signature of the function.
/// System updating the [`Frustum`] component of an entity, typically a [`Camera`], | |
/// using its [`GlobalTransform`] and the projection matrix from its [`CameraProjection`] | |
/// component. | |
/// Updates [`Frustrum`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should still mention Camera
, or Camera3dBundle
/Camera2dBundle
, to add context?
I guess the context is in the doc of Frustum
and CameraProjection
already.
…ly, and how it is not used only for frustum culling
After testing and analysis of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a bit more work, but definitely a marked improvement.
Co-authored-by: Alice Cecile <[email protected]>
Example |
1 similar comment
Example |
…ne#9136) # Objective This PR's first aim is to fix a mistake in `HalfSpace`'s documentation. When defining a `Frustum` myself in bevy_basic_portals, I realised that the "distance" of the `HalfSpace` is not, as the current doc defines, the "distance from the origin along the normal", but actually the opposite of that. See the example I gave in this PR. This means one of two things: 1. The documentation about `HalfSpace` is wrong (it is either way because of the `n.p + d > 0` formula given later anyway, which is how it behaves, but in that formula `d` is indeed the opposite of the "distance from the origin along the normal", otherwise it should be `n.p > d`) 2. The distance is supposed to be the "distance from the origin along the normal" but when used in a Frustum it's used as the opposite, and it is a mistake 3. Same as 2, but it is somehow intended Since I think `HalfSpace` is only used for `Frustum`, and it's easier to fix documentation than code, I assumed for this PR we're in case number 1. If we're in case number 3, the documentation of `Frustum` needs to change, and in case number 2, the code needs to be fixed. While I was at it, I also : - Tried to improve the documentation for `Frustum`, `Aabb`, and `VisibilitySystems`, among others, since they're all related to `Frustum`. - Fixed documentation about frustum culling not applying to 2d objects, which is not true since bevyengine#7885 ## Remarks and questions - What about a `HalfSpace` with an infinite distance, is it allowed and does it represents the whole space? If so it should probably be mentioned. - I referenced the `update_frusta` system in `bevy_render::view::visibility` directly instead of referencing its system set, should I reference the system set instead? It's a bit annoying since it's in 3 sets. - `visibility_propagate` is not public for some reason, I think it probably should be, but for now I only documented its system set, should I make it public? I don't think that would count as a breaking change? - Why is `Aabb` inserted by a system, with `NoFrustumCulling` as an opt-out, instead of having it inserted by default in `PbrBundle` for example and then the system calculating it when it's added? Is it because there is still no way to have an optional component inside a bundle? --------- Co-authored-by: SpecificProtagonist <[email protected]> Co-authored-by: Alice Cecile <[email protected]>
Objective
This PR's first aim is to fix a mistake in
HalfSpace
's documentation.When defining a
Frustum
myself in bevy_basic_portals, I realised that the "distance" of theHalfSpace
is not, as the current doc defines, the "distance from the origin along the normal", but actually the opposite of that.See the example I gave in this PR.
This means one of two things:
HalfSpace
is wrong (it is either way because of then.p + d > 0
formula given later anyway, which is how it behaves, but in that formulad
is indeed the opposite of the "distance from the origin along the normal", otherwise it should ben.p > d
)Since I think
HalfSpace
is only used forFrustum
, and it's easier to fix documentation than code, I assumed for this PR we're in case number 1. If we're in case number 3, the documentation ofFrustum
needs to change, and in case number 2, the code needs to be fixed.While I was at it, I also :
Frustum
,Aabb
, andVisibilitySystems
, among others, since they're all related toFrustum
.Aabb
calculation forSprite
,TextureAtlasSprite
andMesh2d
#7885Remarks and questions
HalfSpace
with an infinite distance, is it allowed and does it represents the whole space? If so it should probably be mentioned.update_frusta
system inbevy_render::view::visibility
directly instead of referencing its system set, should I reference the system set instead? It's a bit annoying since it's in 3 sets.visibility_propagate
is not public for some reason, I think it probably should be, but for now I only documented its system set, should I make it public? I don't think that would count as a breaking change?Aabb
inserted by a system, withNoFrustumCulling
as an opt-out, instead of having it inserted by default inPbrBundle
for example and then the system calculating it when it's added? Is it because there is still no way to have an optional component inside a bundle?