Geodesic
A high-performance ray tracing library for Rust, featuring efficient Bounding Volume Hierarchy (BVH) acceleration structures and support for a range of geometric primitives.
Features
- 🚀 High Performance: Optimized BVH acceleration structures with Surface Area Heuristic (SAH)
- 📐 Multiple Primitives: Support for spheres, AABBs, triangles, and meshes
- 🎯 Ray Tracing: Efficient ray-geometry intersection testing
- 📦 Mesh Loading: Built-in Wavefront (.obj) file loader
- 🔄 Instancing: Mesh instancing with transformation matrices
- 📸 Camera System: Configurable perspective camera with field-of-view controls
- 🎨 Rendering Pipeline: Complete ray casting to distance field rendering
- 📊 Generic Design: Works with any real number type (f32, f64, etc.)
Quick Start
Add this to your Cargo.toml:
[]
= "0.0.0"
Basic Example
use *;
use Point3;
// Configure BVH acceleration structure
let bvh_config = new;
// Set up camera
let resolution = ; // [height, width]
let camera = new;
// Create scene objects
let mut objects = Vecnew;
objects.push;
objects.push;
// Build scene with BVH acceleration
let scene = new;
// Render distance field
for row in 0..resolution
Core Components
Geometry Primitives
- Sphere: Basic sphere primitive with center and radius
- AABB: Axis-Aligned Bounding Box with min/max corners
- Triangle: Optimised triangle with pre-computed edges and normals
- Mesh: Triangle mesh with BVH acceleration and .obj loading support
Scene Management
- Scene: Top-level container for all objects with BVH acceleration
- SceneObject: Enumeration wrapper for different geometry types
- Instance: Mesh instancing with transformation matrices
Acceleration Structures
- BvhConfig: Configurable parameters for BVH construction
- BVH: Bounding Volume Hierarchy with Surface Area Heuristic
Ray Tracing
- Ray: Ray structure with origin, direction, and optimisation data
- Hit: Intersection result with distance and normal information
- Camera: Perspective camera for generating sampling rays
File Format Support
Wavefront OBJ
The library supports loading triangle meshes from Wavefront (.obj) files:
let mesh = load;
Supported features:
- Vertex positions (
v) - Vertex normals (
vn) - Triangular faces (
f)
Requirements:
- Meshes must be triangulated
- Faces must include both vertex and normal indices (format:
v//vn)
Performance Considerations
BVH Optimization
The library uses Surface Area Heuristic (SAH) for optimal BVH construction:
- Traverse Cost: Higher values favor broader trees (fewer internal nodes)
- Intersect Cost: Higher values favor deeper trees (fewer primitives per leaf)
- SAH Buckets: More buckets provide better splits but trade-off with a slower construction time
- Max Shapes Per Node: Controls leaf size vs. tree depth trade-off
Memory Usage
- BVH construction requires temporary memory proportional to scene size
- Mesh data is stored efficiently with pre-computed edge vectors
- Ray intersection uses stack-based traversal (no heap allocation)
Examples
See the simple.rs example for a complete rendering pipeline that:
- Sets up a scene with a sphere and mesh
- Configures a perspective camera
- Renders a distance field image
- Saves the result as a PNG file