Geodesic
A high-performance ray tracing library for Rust, designed for both educational use and production applications. Geodesic provides a clean, type-safe API for building ray tracers with support for various geometric primitives, acceleration structures, and scene management.
Features
- 🚀 High Performance: Optimized ray-primitive intersection algorithms with BVH acceleration
- 🎯 Type Safety: Generic over floating-point types with comprehensive error handling
- 📐 Rich Geometry: Support for spheres, planes, triangles, and complex meshes
- 🏗️ Scene Management: Flexible scene construction with asset management and instancing
- 📦 Serialization: JSON-based scene, camera, and asset serialization
- 🎥 Camera Models: Perspective and orthographic projections with configurable resolution
- ⚡ Acceleration Structures: Bounding Volume Hierarchy (BVH) with Surface Area Heuristic
- 🔧 Configurable: Extensive configuration options for performance tuning
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Ray Tracing
use *;
use ;
// Create a simple scene with a sphere
let scene = builder
.add_sphere?
.build?;
// Set up a camera
let camera = new?;
// Render a pixel
let ray = camera.generate_ray?;
if let Some = scene.intersect?
Loading Scenes from Files
use *;
// Load assets (meshes, textures, etc.)
let assets = load?.build?;
// Load scene configuration
let scene = load?.build?;
// Load camera settings
let camera = load?.build?;
// Ready to render!
Mesh Loading
use *;
// Load a Wavefront OBJ file
let bvh_config = default;
let mesh = load?;
// Add to scene with transformation
let transform = new_translation;
let scene = builder
.add_instance?
.build?;
Architecture
Core Components
- Geometry: Primitives like
Sphere,Plane,Triangle, andMesh - Ray Tracing:
RayandHitstructures for intersection calculations - Acceleration:
Bvh(Bounding Volume Hierarchy) for fast ray-scene intersection - Scene Management:
Scene,Camera, andAssetsfor organizing render data - Serialization: JSON-based configuration for scenes, cameras, and assets
Traits
Traceable: Ray intersection testing for any geometryBounded: Axis-aligned bounding box computationPersistable: JSON serialization/deserialization
Performance
Geodesic is designed for performance with:
- BVH Acceleration: O(log n) ray-scene intersection complexity
- SIMD-Friendly: Compatible with nalgebra's SIMD optimizations
- Memory Efficient: Minimal allocations during rendering
- Parallel Ready: Thread-safe structures for parallel rendering
Examples
Simple Light Map Renderer
use *;
use *;
Scene Configuration
Create JSON configuration files for complex scenes:
assets.json
scene.json
camera.json
Configuration
BVH Tuning
The BVH acceleration structure can be tuned for different scene types:
let bvh_config = new?;
Generic Precision
Geodesic supports different floating-point precisions:
// Single precision (faster)
type Scene32 = ;
// Double precision (more accurate)
type Scene64 = ;
Error Handling
Geodesic provides comprehensive error handling with detailed error types:
match scene.intersect
Supported File Formats
- Wavefront OBJ: Triangle mesh loading with vertex normals
- JSON: Scene, camera, and asset configuration
Minimum Supported Rust Version (MSRV)
Geodesic requires Rust 1.70 or later.
Development
# Clone the repository
# Create example scene and camera files
# Load and render the example scene
# Check documentation
License
This project is licensed under the MIT License - see the LICENSE file for details.