Ray Tracer in Python and Rust
This project implements a basic ray tracer from scratch in Python, later reimplemented in Rust for significant performance improvement. It renders spheres and triangles using the Phong illumination model, supporting shadows and recursive reflections.
Introduction
A simple illustration of how ray tracing works compared to natural vision.
Features
- Ray-object intersection (spheres and triangles)
- Phong illumination (ambient, diffuse, specular)
- Shadow ray casting
- Recursive reflections (mirror effects)
- Refraction can be implemented easily by extending the reflection model
- Parallel rendering using CPU cores
- Rust implementation for performance optimization
Core Algorithm Steps
- Cast a view ray for each pixel
- Find the closest intersection with scene objects
- Compute local color using:
- Surface normal
- Light position
- Shadow ray
- Reflection
- If the material is reflective, compute reflected ray color recursively
Sample Renderings


Left: reflections and shadows between two colored spheres
Right: super HD sample with random spheres at random positions
Tools Used
- Python: initial version,
multiprocessing
for parallel rendering - Rust: optimized version