This project implements a simple ray tracer using Python, Numpy, Matplotlib, and Numba for performance improvements. It supports basic geometric objects like spheres and planes while calculating reflections, diffuse lighting, and specular highlights. The final output is a 1920x1080 image rendered from a scene defined by these objects.
The initial implementation produced a 400x300 resolution image and ran without optimizations. Through performance enhancements and upscaling techniques, the latest version now renders at a higher resolution while maintaining the same ray depth and significantly reducing rendering time.
- Ray Depth Consistency: Despite the resolution increase, the ray depth for reflections remains consistent at a maximum of 5.
- Optimized with Numba: Numba’s
@njit
decorator drastically improves the performance of key functions, reducing computation time. - Supersampling for High Resolution: The original image is rendered at a lower resolution of 960x540 and then upscaled to 1920x1080 using nearest neighbor interpolation, achieving a high-quality result faster than direct rendering at full resolution.
- Lighting and Shading: Includes ambient, diffuse, and specular lighting models for more realistic scenes, along with reflections for both spheres and planes.
- Original Resolution: 400x300 (120,000 pixels)
- New Resolution (via supersampling): 1920x1080 (2,073,600 pixels)
The new resolution is nearly 17.3 times larger than the original while maintaining consistent ray tracing depth.
- The image is first rendered at a lower resolution (960x540) and then upscaled to 1920x1080 using interpolation. This approach balances quality and speed.
- Even though the upscaled image has over 2 million pixels, the optimized code ensures that the rendering time is kept minimal.
Version | Resolution | Time Taken | Pixel Count | Ray Depth |
---|---|---|---|---|
Original | 400x300 | 4.98 sec | 120,000 | 5 |
Optimized | 1920x1080 | 3.35 sec | 2,073,600 | 5 |
| Resolution: 3840x2160 | Pixel Count: 8,294,400 |
Notice the reduced jagged edges!
- Python 3.x
- Required Libraries:
numpy
,matplotlib
,numba
- Clone the repository:
git clone https://github.com/your-username/ray-tracing-optimization.git pip install numpy matplotlib numba python raytracer.py