Skip to content

Commit

Permalink
Make attractors regular modifiers (#286)
Browse files Browse the repository at this point in the history
Remove the built-in code and shader handling a fixed-size array of force
field attractors/repulsors, and related types `ForceFieldSource` and
`ForceFieldModifier`. Replace them with a new `ConformToSphereModifier`
describing a single attractor/repulsor source, which can be repeated to
add more sources. The new modifier is a regular update context modifier
without any specific built-in codepath, making its handling a lot easier
and cleaner, while also allowing any custom attraction force expression
as well as customizing other parameters of the source in real time.

Revamp the `force_field.rs` example to showcase this new modifier, and
add a dedicated parameter tweaking panel to observe the effect of each
parameter.

Fix a panic in rendering code when no effect is present. This looks like
a race condition; for now simply early out to prevent the panic.

```rust
effects_meta.dr_indirect_bind_group.as_ref().unwrap()
```
  • Loading branch information
djeedai authored Feb 26, 2024
1 parent f3c1d21 commit fe3680b
Show file tree
Hide file tree
Showing 18 changed files with 1,053 additions and 399 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added a new `ScreenSpaceSizeModifier` which negates the effect of perspective projection, and makes the particle's size a pixel size in screen space, instead of a Bevy world unit size. This replaces the hard-coded behavior previously available on the `SetSizeModifier`.
- Added a new `ConformToSphereModifier` acting as an attractor applying a force toward a point (sphere center) to all particles in range, and making particles conform ("stick") to the sphere surface.

### Changed

- `ExprHandle` is now `#[repr(transparent)]`, which guarantees that `Option<ExprHandle>` has the same size as `ExprHandle` itself (4 bytes).
- `EffectProperties::set_if_changed()` now returns the `Mut` variable it takes as input, to allow subsequent calls.

### Removed

- Removed the `screen_space_size` field from the `SetSizeModifier`. Use the new `ScreenSpaceSizeModifier` to use a screen-space size.
- Removed the built-in `ForceFieldSource` and associated `ForceFieldModifier`. Use the new `ConformToSphereModifer` instead. The behavior might change a bit as the conforming code is not strictly identical; use the `force_field.rs` example with the `examples_world_inspector` feature to tweak the parameters in real time and observe how they work and change the effect.

### Fixed

- Fixed a panic in rendering randomly occurring when no effect is present.

## [0.10.0] 2024-02-24

Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ wgpu = "0.19.1"

# For world inspector; required if "examples_world_inspector" is used.
bevy-inspector-egui = "0.23"
bevy_egui = "0.25"
egui = "0.26"

# For procedural texture generation in examples
noise = "0.8"
Expand Down
Binary file added docs/conform-to-sphere.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fe3680b

Please sign in to comment.