Skip to content
p-siraPublic

About

Rust ray intersection library using Baldwin-Weber's Intersection

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

36 Commits

Folders and files

Repository files navigation

RayX

Crate Documentation License CodSpeed

rayx is a small Rust ray intersection library using Baldwin-Weber's Fast Ray-Triangle Intersections by Coordinate Transformation (JCGT 2016). Precomputed triangle transforms reduce per-ray arithmetic at the cost of additional memory.

Usage

cargo add rayx
use rayx::{Ray, Triangle};

let tri = Triangle::<f64>::new(
    [0.0, 0.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
)
.unwrap();

let ray = Ray::new([0.25, 0.25, 1.0], [0.0, 0.0, -1.0]);
let hit = tri.intersect(ray, 0.0, 10.0).unwrap();
assert_eq!(hit.t, 1.0);

Performance

Release benchmarks on an AMD Ryzen 5 4600H (rustc 1.99.1), pinned to one core. Each mesh uses 64 downward, 16 oblique, and 16 miss rays, scanning triangles until the first hit. Results are medians of five local wall-clock runs.

Model (triangles) Type BW init (µs) Downward BW / MT / Chunked (ms) Downward Oblique Miss
Suzanne (698) f32 10.0 0.291 / 0.303 / 0.367 +4.1% +61.6% +32.5%
Suzanne (698) f64 10.6 0.284 / 0.334 / 0.354 +17.5% +71.9% +39.5%
Bunny Low (908) f32 16.5 0.445 / 0.486 / 0.462 +9.2% +55.8% +29.2%
Bunny Low (908) f64 17.5 0.446 / 0.536 / 0.457 +20.2% +81.0% +32.7%
Bunny Medium (3,851) f32 67.3 1.991 / 2.103 / 1.967 +5.6% +21.8% +43.5%
Bunny Medium (3,851) f64 75.1 2.122 / 2.223 / 1.965 +4.8% +4.0% +87.3%
Bunny High (16,214) f32 290.7 6.899 / 7.812 / 7.612 +13.2% +9.3% +6.1%
Bunny High (16,214) f64 339.7 7.404 / 7.602 / 7.771 +2.7% +2.9% +21.2%
Thai Statue wide (100,000) f32 2195.1 76.877 / 72.048 / 52.806 -6.3% -6.2% -8.0%
Thai Statue wide (100,000) f64 2706.0 87.658 / 83.513 / 53.829 -4.7% -13.9% -11.2%
Thai Statue narrow (100,000) f32 2255.3 65.705 / 61.806 / 43.628 -5.9% -6.8% -10.1%
Thai Statue narrow (100,000) f64 2496.4 77.373 / 70.611 / 43.149 -8.7% -8.1% -9.5%

BW = Baldwin–Weber; MT = Möller–Trumbore. The final three columns show BW advantage: (MT / BW − 1) × 100%; positive values favor BW. BW initialization is measured separately. Chunked timings include preprocessing but exclude scratch-buffer allocation.

The Bunny High f32 downward case has differing hit counts (BW: 33; MT: 32), affecting the comparison. All other workloads have matching hit counts. Statue wide/narrow cases use different ray bounds on the same mesh.

Larger transform sets can increase cache pressure. The statue requires about 4.6 MiB (f32) or 9.2 MiB (f64), exceeding this CPU's 4 MiB L3 cache per group. Processing batches of rays in 512-triangle chunks improved these statue timings; individual rays may be slower. Chunks fit in L2, though cache misses were not measured directly.

To reproduce, run each command five times and take the median:

taskset -c 2 cargo run --release --locked --example local_intersection
taskset -c 2 cargo run --release --locked --example local_chunked

About

Rust ray intersection library using Baldwin-Weber's Intersection

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages