From 81f4c903ae664a10531567e18f081170769087e6 Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Thu, 22 Feb 2024 20:26:17 -0800 Subject: [PATCH] update to bevy 0.13 (#109) * update to bevy 0.13 * clippy * touch up examples * free perf lying around in a hot loop * Bump version * add no culling to benches * add perf notes to changelog * Fix CI in bevy-0.13 branch (#111) * fix(tests): QueryFilter fixed to be in filter position Authored-by: RobWalt * chore(cleanup): remove unneeded `Mesh::from` Authored-by: RobWalt * chore(cleanup): use Direction3D API directly Ok to be fair this doesn't change a lot. It saves one indirection through the `TryFrom` trait which might even gets optimized away in the first place. Nevertheless it is a bit more explicit which will help newer people to understand the code and develop good habits. Authored-by: RobWalt --------- Co-authored-by: Robert Walter <26892280+RobWalt@users.noreply.github.com> --- CHANGELOG.md | 14 +- Cargo.toml | 28 ++-- README.md | 1 + benches/ray_mesh_intersection.rs | 30 +++- examples/minimal.rs | 12 +- examples/minimal_deferred.rs | 14 +- examples/mouse_picking.rs | 4 +- examples/mouse_picking_2d.rs | 7 +- examples/mouse_picking_deferred.rs | 4 +- examples/reflecting_laser.rs | 24 ++- examples/simplified_mesh.rs | 16 +- examples/stress_test.rs | 8 +- src/deferred.rs | 31 ++-- src/immediate.rs | 23 ++- src/lib.rs | 3 +- src/primitives.rs | 248 ++++++++++------------------- src/raycast.rs | 200 +++++++++-------------- 17 files changed, 291 insertions(+), 376 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d56d83..0063202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ +# 0.17.0 + +Raycasting is now 20-50% faster. + +- Changed: updated to Bevy 0.13. +- Removed: This crate's `Ray3d` type has been replaced with Bevy's new `Ray3d` type. + - Methods on `Ray3d` have been replaced with standalone functions. + - This has resulted in a ~10% drop in performance in benchmarks. +- Changed: `Ray3d::from_transform` is now `ray_from_transform` +- Changed: `Ray3d::from_screenspace` is now `ray_from_screenspace` +- Changed: `Triangle` removed in favor of a simpler `[Vec3A; 3]`. + # 0.16.0 -- Changed: updated to bevy 0.12. +- Changed: updated to Bevy 0.12. - Changed: plugin depends on bevy sub-crates (e.g. `bevy_ecs`) instead of `bevy` to reduce dependency count. diff --git a/Cargo.toml b/Cargo.toml index b7e899b..5a17dfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_raycast" -version = "0.16.0" +version = "0.17.0" authors = ["Aevyrie "] edition = "2021" license = "MIT" @@ -11,22 +11,22 @@ categories = ["game-engines", "rendering"] resolver = "2" [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_asset = { version = "0.12", default-features = false } -bevy_derive = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_gizmos = { version = "0.12", optional = true, default-features = false } -bevy_math = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_sprite = { version = "0.12", optional = true, default-features = false } -bevy_transform = { version = "0.12", default-features = false } -bevy_utils = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_asset = { version = "0.13", default-features = false } +bevy_derive = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_gizmos = { version = "0.13", optional = true, default-features = false } +bevy_math = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_sprite = { version = "0.13", optional = true, default-features = false } +bevy_transform = { version = "0.13", default-features = false } +bevy_utils = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } crossbeam-channel = "0.5" [dev-dependencies] -bevy = { version = "0.12", default-features = true, features = [ +bevy = { version = "0.13", default-features = true, features = [ "default_font", "ktx2", "tonemapping_luts", diff --git a/README.md b/README.md index 1f2018e..2883931 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome! | bevy | bevy_mod_raycast | | ---- | ---------------- | +| 0.13 | 0.17 | | 0.12 | 0.16 | | 0.11 | 0.9 - 0.15 | | 0.10 | 0.8 | diff --git a/benches/ray_mesh_intersection.rs b/benches/ray_mesh_intersection.rs index 6d3a90c..ddbb05e 100644 --- a/benches/ray_mesh_intersection.rs +++ b/benches/ray_mesh_intersection.rs @@ -1,4 +1,5 @@ use bevy::math::{Mat4, Vec3}; +use bevy_math::Ray3d; use bevy_mod_raycast::prelude::*; use criterion::{black_box, criterion_group, criterion_main, Criterion}; @@ -54,7 +55,7 @@ fn ray_mesh_intersection(c: &mut Criterion) { &mesh_to_world, &mesh.positions, Some(&mesh.normals), - &ray, + ray, Some(&mesh.indices), Backfaces::Cull, )); @@ -63,6 +64,30 @@ fn ray_mesh_intersection(c: &mut Criterion) { } } +fn ray_mesh_intersection_no_cull(c: &mut Criterion) { + let mut group = c.benchmark_group("ray_mesh_intersection_no_cull"); + group.warm_up_time(std::time::Duration::from_millis(500)); + + for vertices_per_side in [10_u32, 100, 1000] { + group.bench_function(format!("{}_vertices", vertices_per_side.pow(2)), |b| { + let ray = Ray3d::new(Vec3::new(0.0, 1.0, 0.0), Vec3::new(0.0, -1.0, 0.0)); + let mesh_to_world = Mat4::IDENTITY; + let mesh = mesh_creation(vertices_per_side); + + b.iter(|| { + black_box(bevy_mod_raycast::prelude::ray_mesh_intersection( + &mesh_to_world, + &mesh.positions, + Some(&mesh.normals), + ray, + Some(&mesh.indices), + Backfaces::Include, + )); + }); + }); + } +} + fn ray_mesh_intersection_no_intersection(c: &mut Criterion) { let mut group = c.benchmark_group("ray_mesh_intersection_no_intersection"); group.warm_up_time(std::time::Duration::from_millis(500)); @@ -78,7 +103,7 @@ fn ray_mesh_intersection_no_intersection(c: &mut Criterion) { &mesh_to_world, &mesh.positions, Some(&mesh.normals), - &ray, + ray, Some(&mesh.indices), Backfaces::Cull, )); @@ -90,6 +115,7 @@ fn ray_mesh_intersection_no_intersection(c: &mut Criterion) { criterion_group!( benches, ray_mesh_intersection, + ray_mesh_intersection_no_cull, ray_mesh_intersection_no_intersection ); criterion_main!(benches); diff --git a/examples/minimal.rs b/examples/minimal.rs index c919e56..c9ad3e7 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -13,12 +13,12 @@ fn main() { .run(); } -const DIST: Vec3 = Vec3::new(0.0, 0.0, -7.0); +const RAY_DIST: Vec3 = Vec3::new(0.0, 0.0, -7.0); fn raycast(mut raycast: Raycast, mut gizmos: Gizmos, time: Res