A simple ray tracing renderer implemented in Python for computer graphics education.
This project implements a basic ray tracer that can render 3D scenes with geometric primitives like spheres and planes. It features refraction simulation for transparent objects and supports basic scene setup with colored walls and objects.
- Ray tracing algorithm implementation
- Support for spheres and planes
- Refraction effects for transparent materials
- Configurable camera with field of view
- Image output in PNG format
- Anti-aliasing support (configurable samples)
- Python 3.x
- NumPy
- PyGLM (OpenGL Mathematics for Python)
- Pillow (PIL)
- Clone the repository:
git clone https://github.com/Sghaier9/ray-tracer-python.git
cd ray-tracer-python- Install dependencies:
pip install numpy pyglm pillowRun the main script to generate a rendered image:
python main.pyThis will create image_refraction.png in the current directory, showing a scene with colored walls and a refractive sphere.
The default scene includes:
- A room with colored walls (red, blue, magenta, yellow, green)
- A refractive sphere (simulating glass/water) positioned in the center
- A camera positioned at the origin looking down the negative Z-axis
├── main.py # Main ray tracing script
├── image_utils.py # Image saving utilities
├── classes/
│ ├── camera.py # Camera and ray classes
│ └── objects/
│ ├── __init__.py
│ ├── object.py # Base object class
│ ├── sphere.py # Sphere implementation
│ └── plane.py # Plane implementation
└── README.md # This file
The repository includes several rendered images demonstrating different features:
image1.png-image4.png: Basic rendersimage4_aa.png: Anti-aliased versionimage_lumiere.png: Lighting effectsimage_ombres.png: Shadowsimage_phong.png: Phong shadingimage_refraction.png: Refraction effects
You can modify the scene in main.py by:
- Changing camera parameters (position, FOV, target)
- Adding/removing objects
- Adjusting material properties (colors, refraction indices)
- Modifying rendering parameters (resolution, depth, anti-aliasing)
MIT License - feel free to use for educational purposes.