Commit graph

1021 commits

Author SHA1 Message Date
Logan Magee
d508923eb7 Allow deriving SystemParam on private types (#1936)
Examples creating a public type to derive `SystemParam` on were updated
to create a private type where a public one is no longer needed.

Resolves #1869
2021-04-16 18:40:49 +00:00
Jakob Hellermann
cf221f9659 calculate flat normals for mesh if missing (#1808)
If the gltf loader encounters a mesh without normal attributes, it will duplicate the vertex attributes and compute flat normals, as defined by https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes:

> **Implementation Note**: When normals are not specified, client implementations should calculate flat normals.

![image](https://user-images.githubusercontent.com/22177966/113483243-bb204880-94a2-11eb-8fa1-c4828a4882c5.png)

Helps with #1802 

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-15 21:06:49 +00:00
Lukas Wirth
0a6fee5d17 Improve bevy_ecs::system module docs (#1932)
This includes a lot of single line comments where either saying more wasn't helpful or due to me not knowing enough about things yet to be able to go more indepth. Proofreading is very much welcome.
2021-04-15 20:36:16 +00:00
Boxy
9657f58f6a Fix unsoundness in query component access (#1929)
Pretty much does what it says in the title lol
2021-04-15 20:17:59 +00:00
Yoh Deadfall
22314923d9 Angle bracket annotated types to support generics (#1919)
Fixes #1873. Types should be enclosed in angular brackets to avoid ambiquity and to correctly resolve associated functions.
2021-04-15 00:16:40 +00:00
Richard Tjerngren
490a957542 Document Query.single() (#1915) 2021-04-15 00:16:39 +00:00
bg
55d6c2c34a fixing compilation error on macos aarch64 (#1905)
just so
2021-04-14 23:58:29 +00:00
Daniel McNab
a137df7d57 Fix SytemParam handling of Commands (#1899)
Fixes https://github.com/bevyengine/bevy/issues/1896
2021-04-14 23:58:27 +00:00
TehPers
e0b52079da Implement RenderResource for Box<T> (#1893)
Allows render resources to move data to the heap by boxing them. I did this as a workaround to #1892, but it seems like it'd be useful regardless. If not, feel free to close this PR.
2021-04-14 23:58:25 +00:00
Denis Laprise
d8392e7a3e Add a UV sphere implementation (#1887)
Added a UV sphere implementation
2021-04-14 23:39:58 +00:00
Philipp Mildenberger
ad546a9502 Fix pbr shader compiliation error, #version has to be in the first line (#1884)
I've had problems with compiling and running the pbr example:

```
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Compilation("glslang_shader_preprocess:\nInfo log:\nERROR: 0:40: \'#version\' : must occur first in shader \nERROR: 0:40: \'#version\' : bad profile name; use es, core, or compatibility \nERROR: 0:40: \'#version\' : bad tokens following profile -- expected newline \nERROR: 3 compilation errors.  No code generated.\n\n\nDebug log:\n\n")', crates/bevy_render/src/pipeline/pipeline_compiler.rs:161:22
```

I've checked each shader, and only one shader hasn't had `#version` in the first line.

This change fixed my issue.
2021-04-14 23:39:57 +00:00
aloucks
294feeedc0 Add additional vertex formats (#1878)
- `Short2`
- `Short2Norm`
- `Ushort2`
- `Ushort2Norm`
- `Short4`
- `Short4Norm`
- `Ushort4`
- `Ushort4Norm`
- `Char2`
- `Char2Norm`
- `Uchar2`
- `Uchar2Norm`
- `Char4`
- `Char4Norm`
- `Uchar4`
2021-04-14 23:21:53 +00:00
therealstork
c86d490a20 More detailed errors when resource not found (#1864)
Fixes #1846

Got scared of the other "Requested resource does not exist" error at line 395 in `system_param.rs`, under `impl<'a, T: Component> SystemParamFetch<'a> for ResMutState<T> {`. Someone with better knowledge of the code might be able to go in and improve that one.
2021-04-14 22:52:43 +00:00
TehPers
deb9f23667 Implement Byteable and RenderResource for [T; N] (#1872)
Implements `Byteable` and `RenderResource` for any array containing `Byteable` elements. This allows `RenderResources` to be implemented on structs with arbitrarily-sized arrays, among other things:

```rust
#[derive(RenderResources, TypeUuid)]
#[uuid = "2733ff34-8f95-459f-bf04-3274e686ac5f"]
struct Foo {
    buffer: [i32; 256],
}
```
2021-04-14 22:20:25 +00:00
Patrik Buhring
df3f40afd4 Fix IcoSphere UV coordinates (#1871)
Changes made:
- Swap Y/Z when calculating UV coordinates
- Correct mapping in the UV coordinates
- Fix typo in Azimuth
2021-04-14 22:20:24 +00:00
François
d868d07d0b run some examples on CI using swiftshader (#1826)
From suggestion from Godot workflows: https://github.com/bevyengine/bevy/issues/1730#issuecomment-810321110

* Add a feature `bevy_debug` that will make Bevy read a debug config file to setup some debug systems
  * Currently, only one that will exit after x frames
  * Could add option to dump screen to image file once that's possible
* Add a job in CI workflow that will run a few examples using [`swiftshader`](https://github.com/google/swiftshader)
  * This job takes around 13 minutes, so doesn't add to global CI duration

|example|number of frames|duration|
|-|-|-|
|`alien_cake_addict`|300|1:50|
|`breakout`|1800|0:44|
|`contributors`|1800|0:43|
|`load_gltf`|300|2:37|
|`scene`|1800|0:44|
2021-04-14 21:40:36 +00:00
Jakob Hellermann
d119c1ce14 gltf-loader: support data url for images (#1828)
This allows the `glTF-Embedded` variants in the [sample models](https://github.com/KhronosGroup/glTF-Sample-Models/) to be used.
The data url format is relatively small, so I didn't include a crate like [docs.rs/data-url](https://docs.rs/data-url/0.1.0/data_url/).

Also fixes the 'Box With Spaces' model as URIs are now percent-decoded.

cc #1802
2021-04-13 21:30:32 +00:00
Yoh Deadfall
04a37f722a Moved events to ECS (#1823)
Fixes #1809. It makes it also possible to use `derive` for `SystemParam` inside ECS and avoid manual implementation. An alternative solution to macro changes is to use `use crate as bevy_ecs;` in `event.rs`.
2021-04-13 20:36:37 +00:00
Jonas Matser
7342d463b8 Use a sorted Map for vertex buffer attributes (#1796)
The `VertexBufferLayout` returned by `crates\bevy_render\src\mesh\mesh.rs:308` was unstable, because `HashMap.iter()` has a random order. This caused the pipeline_compiler to wrongly consider a specialization to be different (`crates\bevy_render\src\pipeline\pipeline_compiler.rs:123`), causing each mesh changed event to potentially result in a different `PipelineSpecialization`. This in turn caused `Draw` to emit a `set_pipeline` much more often than needed.

This fix shaves off a `BindPipeline` and two `BindDescriptorSets` (for the Camera and for global renderresources) for every mesh after the first that can now use the same specialization, where it didn't before (which was random).

`StableHashMap` was not a good replacement, because it isn't `Clone`, so instead I replaced it with a `BTreeMap` which is OK in this instance, because there shouldn't be many insertions on `Mesh.attributes` after the mesh is created.
2021-04-13 03:31:29 +00:00
François
4c1099a77f add documentation on Input (#1781)
related to #1700 

This PR:
* documents all methods on `Input<T>`
* adds documentation on the struct about how to use it, and how to implement it for a new input type
* renames method `update` to a easier to understand `clear`
* adds two methods to check for state and clear it after, allowing easier use in the case of #1700 

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-13 03:13:48 +00:00
Jakob Hellermann
9e55d8dbb4 Error message improvements for shader compilation/gltf loading (#1786)
- prints glsl compile error message in multiple lines instead of `thread 'main' panicked at 'called Result::unwrap() on an Err value: Compilation("glslang_shader_parse:\nInfo log:\nERROR: 0:335: \'assign\' :  l-value required \"anon@7\" (can\'t modify a uniform)\nERROR: 0:335: \'\' : compilation terminated \nERROR: 2 compilation errors.  No code generated.\n\n\nDebug log:\n\n")', crates/bevy_render/src/pipeline/pipeline_compiler.rs:161:22`
- makes gltf error messages have more context

New error:
```rust
thread 'Compute Task Pool (5)' panicked at 'Shader compilation error:
glslang_shader_parse:
Info log:
ERROR: 0:12: 'assign' :  l-value required "anon@1" (can't modify a uniform)
ERROR: 0:12: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.
', crates/bevy_render/src/pipeline/pipeline_compiler.rs:364:5
```


These changes are a bit unrelated. I can open separate PRs if someone wants that.
2021-04-13 02:56:30 +00:00
Jonas Matser
5c4f3554f9 Rename Light => PointLight and remove unused properties (#1778)
After an inquiry on Reddit about support for Directional Lights and the unused properties on Light, I wanted to clean it up, to hopefully make it ever so slightly more clear for anyone wanting to add additional light types.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-13 02:21:24 +00:00
Julian Heinken
8f1eaa6db5 glTF: added color attribute support (#1775) 2021-04-13 01:47:25 +00:00
MinerSebas
0fce6f0406 Override size_hint for all Iterators and add ExactSizeIterator where applicable (#1734)
After #1697 I looked at all other Iterators from Bevy and added overrides for `size_hint` where it wasn't done.
Also implemented `ExactSizeIterator` where applicable.
2021-04-13 01:28:14 +00:00
Guim Caballero
b060e16f62 Add synonyms for transform relative vectors (#1667)
Fixes #1663.

I think the directions are correct (same as [here](https://docs.godotengine.org/en/stable/classes/class_vector3.html?highlight=forward#constants)), but please double check because I might have mixed them up.

Co-authored-by: guimcaballero <guim.caballero@gmail.com>
Co-authored-by: Guim Caballero <guim.caballero@gmail.com>
2021-04-12 21:53:05 +00:00
Jakob Hellermann
ed36c21e7e fix 'attempted to subtract with overflow' for State::inactives (#1668) 2021-04-10 16:33:35 +00:00
bjorn3
6a4051be3a Make some asset loading functions monomorphic (#1861)
This reduces the size of executables when using bevy as dylib by
ensuring that they get codegened in bevy_assets instead of the game
itself. This by extension avoids pulling in parts of bevy_tasks and
async_task.

Before this change the breakout example was 923k big after this change
it is only 775k big for cg_clif. For cg_llvm in release mode breakout
shrinks from 356k to 316k. For cg_llvm in debug mode breakout shrinks
from 3814k to 3057k.
2021-04-10 16:17:32 +00:00
r00ster
bc13d11c78 Update old docs mentioning Camera2dBundle (#1836)
This replaces some outdated mentions of the `Camera2dBundle` that is removed now with 0.5.
2021-04-06 21:05:08 +00:00
Carter Anderson
97d8e4e179 Release 0.5.0 (#1835) 2021-04-06 18:48:48 +00:00
Jakob Hellermann
aaf204cbac remove active camera entity when despawned (#1825)
fixes #1452

This should probably be in 0.5, as the previous workaround isn't possible after dd4a196329 because the hashmap is now private.
2021-04-06 17:09:28 +00:00
François
3e285d5c0b allow deriving bundle for struct with generics with where clause (#1811)
fixes #1777 

Seems the `_where_clause` parameter to lost somewhere, adding it back
2021-04-03 23:30:30 +00:00
François
9098df3034 make pbr shader std140 compatible (#1798)
In shaders, `vec3` should be avoided for `std140` layout, as they take the size of a `vec4` and won't support manual padding by adding an additional `float`.

This change is needed for 3D to work in WebGL2. With it, I get PBR to render
<img width="1407" alt="Screenshot 2021-04-02 at 02 57 14" src="https://user-images.githubusercontent.com/8672791/113368551-5a3c2780-935f-11eb-8c8d-e9ba65b5ee98.png">

Without it, nothing renders... @cart Could this be considered for 0.5 release?

Also, I learned shaders 2 days ago, so don't hesitate to correct any issue or misunderstanding I may have

bevy_webgl2 PR in progress for Bevy 0.5 is here if you want to test: https://github.com/rparrett/bevy_webgl2/pull/1
2021-04-03 23:30:28 +00:00
François
276a81cc30 allow up to 16 parameters for systems (#1805)
fixes #1772 

1st commit: the limit was at 11 as the macro was not using a range including the upper end. I changed that as it feels the purpose of the macro is clearer that way.

2nd commit: as suggested in the `// TODO`, I added a `Config` trait to go to 16 elements tuples. This means that if someone has a custom system parameter with a config that is not a tuple or an `Option`, they will have to implement `Config` for it instead of the standard `Default`.
2021-04-03 23:13:54 +00:00
Jakob Hellermann
1df3b74d38 fix attempt to modify emissive uniform (#1771)
Previously loading the boom box gltf file panic'd with `ERROR: 0:335: 'assign' :  l-value required "anon@7" (can't modify a uniform)`
2021-04-03 22:51:52 +00:00
Carter Anderson
f520a341d5 flip resource scope order (#1793)
I think [collection, thing_removed_from_collection] is a more natural order than [thing_removed_from_collection, collection]. Just a small tweak that I think we should include in 0.5.
2021-04-01 02:24:42 +00:00
TheRawMeatball
b657a9b39f Add on_in_stack_update to SystemSet (#1792) 2021-03-31 20:24:04 +00:00
Carter Anderson
d6bc414bf0 check for duplicate archetypes in QueryState::new_archetype (#1789)
Fixes #1788

See discussion in that issue for details.
2021-03-30 21:21:47 +00:00
Carter Anderson
94c4184068 Text responds to scale factor changes (#1769)
Fixes #1768

If the scale factor changes, queue up all text to be drawn instead of just changed text.
2021-03-27 03:03:47 +00:00
Jonas Matser
9a78addff0 Add PBR textures (#1632)
This PR adds normal maps on top of PBR #1554. Once that PR lands, the changes should look simpler.

Edit: Turned out to be so little extra work, I added metallic/roughness texture too. And occlusion and emissive.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-03-26 21:00:34 +00:00
davier
0c374df712 Add insert_children and push_children to EntityMut (#1728)
The only API to add a parent/child relationship between existing entities is through commands, there is no easy way to do it from `World`. Manually inserting the components is not completely possible since `PreviousParent` has no public constructor.

This PR adds two methods to set entities as children of an `EntityMut`: `insert_children` and `push_children`. ~~The API is similar to the one on `Commands`, except that the parent is the `EntityMut`.~~ The API is the same as in #1703.
However, the `Parent` and `Children` components are defined in `bevy_transform` which depends on `bevy_ecs`, while `EntityMut` is defined in `bevy_ecs`, so the methods are added to the `BuildWorldChildren` trait instead.
If #1545 is merged this should be fixed too.

I'm aware cart was experimenting with entity hierarchies, but unless it's a coming soon this PR would be useful to have meanwhile.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-03-26 20:03:12 +00:00
François
d90d19f1c7 gltf: load normal and occlusion as linear textures (#1762)
Load textures from gltf as linear when needed.

This is for #1632, but can be done independently and won't have any visible impact before.

* during iteration over materials, register textures that need to be loaded as linear
* during iteration over textures
  * directly load bytes from external files instead of adding them as dependencies in the load context
  * configure the texture the same way for buffered and external textures
  * if the texture is linear rgb, set as linear rgb
2021-03-26 18:47:47 +00:00
Ixentus
80bd378aa0 Fix tiny state docs inconsistency (#1764)
@TheRawMeatball
2021-03-26 18:30:28 +00:00
Carter Anderson
7a511394ac Add register_component to AppBuilder and improve error message (#1750) 2021-03-26 04:15:07 +00:00
Alexander Sepity
500d7469e7 Fixed criteria-less systems being re-ran unnecessarily (#1754)
Fixes #1753.

The problem was introduced while reworking the logic around stages' own criteria. Before #1675 they used to be stored and processed inline with the systems' criteria, and systems without criteria used that of their stage. After, criteria-less systems think they should run, always. This PR more or less restores previous behavior; a less cludge solution can wait until after 0.5 - ideally, until stageless.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-03-26 00:31:58 +00:00
Carter Anderson
bf053218bf Disable frustum culling and add warning (#1761)
Frustum culling has some pretty major gaps right now (such as not supporting sprite transform scaling and not taking into account projections). It should be disabled by default until it provides a solid experience across all bevy use cases.
2021-03-25 22:05:28 +00:00
Jakob Hellermann
ad60046982 fix clippy lints (#1756) 2021-03-25 20:48:18 +00:00
Carter Anderson
1d7196da4f Add state app builder docs (#1746)
This is intended to help protect users against #1671. It doesn't resolve the issue, but I think its a good stop-gap solution for 0.5. A "full" fix would be very involved (and maybe not worth the added complexity).
2021-03-25 06:12:14 +00:00
Carter Anderson
80961d1bd0 Fix sparse insert (#1748)
Removing the checks on this line https://github.com/bevyengine/bevy/blob/main/crates/bevy_sprite/src/frustum_culling.rs#L64 and running the "many_sprites" example revealed two corner case bugs in bevy_ecs. The first, a simple and honest missed line introduced in #1471. The other, an insidious monster that has been there since the ECS v2 rewrite, just waiting for the time to strike:

1. #1471 accidentally removed the "insert" line for sparse set components with the "mutated" bundle state. Re-adding it fixes the problem. I did a slight refactor here to make the implementation simpler and remove a branch.
2. The other issue is nastier. ECS v2 added an "archetype graph". When determining what components were added/mutated during an archetype change, we read the FromBundle edge (which encodes this state) on the "new" archetype.  The problem is that unlike "add edges" which are guaranteed to be unique for a given ("graph node", "bundle id") pair, FromBundle edges are not necessarily unique:

```rust
// OLD_ARCHETYPE -> NEW_ARCHETYPE

// [] -> [usize]
e.insert(2usize);
// [usize] -> [usize, i32]
e.insert(1i32);
// [usize, i32] -> [usize, i32]
e.insert(1i32);
// [usize, i32] -> [usize]
e.remove::<i32>();
// [usize] -> [usize, i32]
e.insert(1i32);
```

Note that the second `e.insert(1i32)` command has a different "archetype graph edge" than the first, but they both lead to the same "new archetype".

The fix here is simple: just remove FromBundle edges because they are broken and store the information in the "add edges", which are guaranteed to be unique.

FromBundle edges were added to cut down on the number of archetype accesses / make the archetype access patterns nicer. But benching this change resulted in no significant perf changes and the addition of get_2_mut() for archetypes resolves the access pattern issue.
2021-03-25 05:56:00 +00:00
TheRawMeatball
78edec2e45 Change State::*_next to *_replace, add proper next (#1676)
In the current impl, next clears out the entire stack and replaces it with a new state. This PR moves this functionality into a replace method, and changes the behavior of next to only change the top state.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-03-25 03:28:40 +00:00
Aaron Winter
b65ec82d46 Frustum Culling (for Sprites) (#1492)
This PR adds two systems to the sprite module that culls Sprites and AtlasSprites that are not within the camera's view.
This is achieved by removing / adding a new  `Viewable` Component dynamically.

Some of the render queries now use a `With<Viewable>` filter to only process the sprites that are actually on screen, which improves performance drastically for scene swith a large amount of sprites off-screen.

https://streamable.com/vvzh2u

This scene shows a map with a 320x320 tiles, with a grid size of 64p.
This is exactly 102400 Sprites in the entire scene.

Without this PR, this scene runs with 1 to 4 FPS.

With this PR..
.. at 720p, there are around 600 visible sprites and runs at ~215 FPS
.. at 1440p there are around 2000 visible sprites and runs at ~135 FPS

The Systems this PR adds take around 1.2ms (with 100K+ sprites in the scene)

Note:
This is only implemented for Sprites and AtlasTextureSprites.
There is no culling for 3D in this PR.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-03-24 21:29:53 +00:00