A high-performance CPU-based raytracer implementation in Rust, featuring parallel rendering and optimized vector operations.
This raytracer is a from-scratch implementation that leverages modern CPU capabilities to generate photorealistic images through ray tracing techniques. Built with performance in mind, it demonstrates the power of Rust's safety guarantees combined with low-level optimization strategies.
- Multi-threaded ray tracing utilizing all available CPU cores
- Automatic work distribution for optimal load balancing
- Near-linear performance scaling with core count
- Hardware-accelerated vector mathematics using SIMD instructions
- Optimized dot products, cross products, and vector arithmetic
- Significant performance improvements for ray-geometry intersection tests
- Flexible camera positioning and orientation in 3D space
- Configurable field of view and aspect ratio
- Look-at functionality for intuitive scene composition
- Sphere and plane primitive support
- Diffuse, reflective, and refractive materials
- Soft shadows and ambient lighting
- Configurable anti-aliasing through supersampling
- Rust 1.93.0-nightly or higher
- Cargo package manager
# Clone the repository
git clone https://github.com/Turtel216/raytracer-rs.git
cd raytracer-rs
# Build in release mode (recommended for performance)
cargo build --release
# Run the raytracer
cargo run --releasecargo doc --no-deps Benchmark results on an AMD Ryzen 5 3600 (6 cores / 12 threads) using hyperfine. The scene across all benchmarks is generated by the benchmark_scene() function in main.rs
| Method | Render Time |
|---|---|
| Single Threaded | 24.420 |
| Single Threaded + SIMD | 21.908 |
| Multi-threaded | 14.362 |
| Multi-threaded + SIMD | 13.922 |
- Rayon: Parallelizes pixel rendering across all CPU cores
- SIMD: Vectorizes mathematical operations for 4× throughput improvement
Note
You can find each program version in its corresponding branch
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Ray Tracing in One Weekend by Peter Shirley
- Rayon for effortless parallelism
- The Rust community for excellent documentation and support
