2020-05-30 19:31:04 +00:00
|
|
|
[package]
|
|
|
|
name = "bevy_sprite"
|
2023-11-04 17:24:23 +00:00
|
|
|
version = "0.12.0"
|
2021-10-27 00:12:14 +00:00
|
|
|
edition = "2021"
|
2020-08-10 00:24:27 +00:00
|
|
|
description = "Provides sprite functionality for Bevy Engine"
|
|
|
|
homepage = "https://bevyengine.org"
|
|
|
|
repository = "https://github.com/bevyengine/bevy"
|
2021-07-23 21:11:51 +00:00
|
|
|
license = "MIT OR Apache-2.0"
|
2020-08-10 00:24:27 +00:00
|
|
|
keywords = ["bevy"]
|
2020-05-30 19:31:04 +00:00
|
|
|
|
2023-10-08 20:17:01 +00:00
|
|
|
[features]
|
|
|
|
webgl = []
|
|
|
|
|
2020-05-30 19:31:04 +00:00
|
|
|
[dependencies]
|
2020-08-10 00:39:28 +00:00
|
|
|
# bevy
|
2023-11-04 17:24:23 +00:00
|
|
|
bevy_app = { path = "../bevy_app", version = "0.12.0" }
|
|
|
|
bevy_asset = { path = "../bevy_asset", version = "0.12.0" }
|
|
|
|
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.12.0" }
|
|
|
|
bevy_ecs = { path = "../bevy_ecs", version = "0.12.0" }
|
|
|
|
bevy_log = { path = "../bevy_log", version = "0.12.0" }
|
|
|
|
bevy_math = { path = "../bevy_math", version = "0.12.0" }
|
|
|
|
bevy_reflect = { path = "../bevy_reflect", version = "0.12.0", features = [
|
2021-12-14 03:58:23 +00:00
|
|
|
"bevy",
|
|
|
|
] }
|
2023-11-04 17:24:23 +00:00
|
|
|
bevy_render = { path = "../bevy_render", version = "0.12.0" }
|
|
|
|
bevy_transform = { path = "../bevy_transform", version = "0.12.0" }
|
|
|
|
bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
|
|
|
|
bevy_derive = { path = "../bevy_derive", version = "0.12.0" }
|
2020-06-06 07:12:38 +00:00
|
|
|
|
2020-08-10 00:39:28 +00:00
|
|
|
# other
|
2021-12-14 03:58:23 +00:00
|
|
|
bytemuck = { version = "1.5", features = ["derive"] }
|
Visibilty Inheritance, universal ComputedVisibility and RenderLayers support (#5310)
# Objective
Fixes #4907. Fixes #838. Fixes #5089.
Supersedes #5146. Supersedes #2087. Supersedes #865. Supersedes #5114
Visibility is currently entirely local. Set a parent entity to be invisible, and the children are still visible. This makes it hard for users to hide entire hierarchies of entities.
Additionally, the semantics of `Visibility` vs `ComputedVisibility` are inconsistent across entity types. 3D meshes use `ComputedVisibility` as the "definitive" visibility component, with `Visibility` being just one data source. Sprites just use `Visibility`, which means they can't feed off of `ComputedVisibility` data, such as culling information, RenderLayers, and (added in this pr) visibility inheritance information.
## Solution
Splits `ComputedVisibilty::is_visible` into `ComputedVisibilty::is_visible_in_view` and `ComputedVisibilty::is_visible_in_hierarchy`. For each visible entity, `is_visible_in_hierarchy` is computed by propagating visibility down the hierarchy. The `ComputedVisibility::is_visible()` function combines these two booleans for the canonical "is this entity visible" function.
Additionally, all entities that have `Visibility` now also have `ComputedVisibility`. Sprites, Lights, and UI entities now use `ComputedVisibility` when appropriate.
This means that in addition to visibility inheritance, everything using Visibility now also supports RenderLayers. Notably, Sprites (and other 2d objects) now support `RenderLayers` and work properly across multiple views.
Also note that this does increase the amount of work done per sprite. Bevymark with 100,000 sprites on `main` runs in `0.017612` seconds and this runs in `0.01902`. That is certainly a gap, but I believe the api consistency and extra functionality this buys us is worth it. See [this thread](https://github.com/bevyengine/bevy/pull/5146#issuecomment-1182783452) for more info. Note that #5146 in combination with #5114 _are_ a viable alternative to this PR and _would_ perform better, but that comes at the cost of api inconsistencies and doing visibility calculations in the "wrong" place. The current visibility system does have potential for performance improvements. I would prefer to evolve that one system as a whole rather than doing custom hacks / different behaviors for each feature slice.
Here is a "split screen" example where the left camera uses RenderLayers to filter out the blue sprite.
![image](https://user-images.githubusercontent.com/2694663/178814868-2e9a2173-bf8c-4c79-8815-633899d492c3.png)
Note that this builds directly on #5146 and that @james7132 deserves the credit for the baseline visibility inheritance work. This pr moves the inherited visibility field into `ComputedVisibility`, then does the additional work of porting everything to `ComputedVisibility`. See my [comments here](https://github.com/bevyengine/bevy/pull/5146#issuecomment-1182783452) for rationale.
## Follow up work
* Now that lights use ComputedVisibility, VisibleEntities now includes "visible lights" in the entity list. Functionally not a problem as we use queries to filter the list down in the desired context. But we should consider splitting this out into a separate`VisibleLights` collection for both clarity and performance reasons. And _maybe_ even consider scoping `VisibleEntities` down to `VisibleMeshes`?.
* Investigate alternative sprite rendering impls (in combination with visibility system tweaks) that avoid re-generating a per-view fixedbitset of visible entities every frame, then checking each ExtractedEntity. This is where most of the performance overhead lives. Ex: we could generate ExtractedEntities per-view using the VisibleEntities list, avoiding the need for the bitset.
* Should ComputedVisibility use bitflags under the hood? This would cut down on the size of the component, potentially speed up the `is_visible()` function, and allow us to cheaply expand ComputedVisibility with more data (ex: split out local visibility and parent visibility, add more culling classes, etc).
---
## Changelog
* ComputedVisibility now takes hierarchy visibility into account.
* 2D, UI and Light entities now use the ComputedVisibility component.
## Migration Guide
If you were previously reading `Visibility::is_visible` as the "actual visibility" for sprites or lights, use `ComputedVisibilty::is_visible()` instead:
```rust
// before (0.7)
fn system(query: Query<&Visibility>) {
for visibility in query.iter() {
if visibility.is_visible {
log!("found visible entity");
}
}
}
// after (0.8)
fn system(query: Query<&ComputedVisibility>) {
for visibility in query.iter() {
if visibility.is_visible() {
log!("found visible entity");
}
}
}
```
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2022-07-15 23:24:42 +00:00
|
|
|
fixedbitset = "0.4"
|
2020-09-10 19:54:24 +00:00
|
|
|
guillotiere = "0.6.0"
|
2021-12-14 03:58:23 +00:00
|
|
|
thiserror = "1.0"
|
|
|
|
rectangle-pack = "0.4"
|
2023-06-01 08:41:42 +00:00
|
|
|
bitflags = "2.3"
|
2023-09-21 17:53:20 +00:00
|
|
|
radsort = "0.1"
|