Skip to content

Turtel216/ray-tracing-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Raytracer

A high-performance CPU-based raytracer implementation in Rust, featuring parallel rendering and optimized vector operations.

Rust License: MIT

Overview

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.

Sample Scene

Example Scene

Key Features

Parallel Rendering with Rayon

  • Multi-threaded ray tracing utilizing all available CPU cores
  • Automatic work distribution for optimal load balancing
  • Near-linear performance scaling with core count

SIMD Vector Operations

  • Hardware-accelerated vector mathematics using SIMD instructions
  • Optimized dot products, cross products, and vector arithmetic
  • Significant performance improvements for ray-geometry intersection tests

Positionable Camera System

  • Flexible camera positioning and orientation in 3D space
  • Configurable field of view and aspect ratio
  • Look-at functionality for intuitive scene composition

Core Raytracing Features

  • Sphere and plane primitive support
  • Diffuse, reflective, and refractive materials
  • Soft shadows and ambient lighting
  • Configurable anti-aliasing through supersampling

Installation

Prerequisites

  • Rust 1.93.0-nightly or higher
  • Cargo package manager

Building from Source

# 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 --release

Generating Docs

cargo doc --no-deps 

Performance Benchmarks

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

Optimization Techniques

  • Rayon: Parallelizes pixel rendering across all CPU cores
  • SIMD: Vectorizes mathematical operations for 4× throughput improvement

Conclusion TODO

Note

You can find each program version in its corresponding branch

Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Releases

No releases published

Packages

 
 
 

Contributors

Languages