A miniature ray tracer written in C that renders 3D scenes using ray casting and the Phong lighting model.
- Shapes: Spheres, planes, and cylinders (with endcaps)
- Lighting: Phong shading (ambient, diffuse, specular), multiple light sources, shadows
- Textures: Checkerboard patterns on planes, UV mapping on spheres
- Camera: Perspective projection with configurable position, orientation, and FOV
- Scene format: Simple
.rttext-based scene description files
- macOS (uses
libmlxfor windowed display) gcc/clang
makeThis compiles libft, libmlx, and the main program, producing the miniRT executable.
./miniRT <scene.rt>Press ESC to close the window.
Each line in a .rt file starts with a type identifier. The following elements are required:
| Identifier | Description | Syntax |
|---|---|---|
A |
Ambient light | A <brightness 0-1> <R,G,B> |
C |
Camera | C <x,y,z> <look-at x,y,z> <FOV> |
L |
Point light | L <x,y,z> <brightness 0-1> <R,G,B> |
sp |
Sphere | sp <x,y,z center> <diameter> <R,G,B> |
pl |
Plane | pl <x,y,z point> <normal x,y,z> <R,G,B> |
cy |
Cylinder | cy <x,y,z center> <axis x,y,z> <radius> <height> <R,G,B> |
A 0.2 255,255,255
C 0,0,20 0,0,-1 90
L 12.5,7.5,5 1 255,255,255
sp 0,0,0 5 150,0,200
pl 0,-5,0 0,1,0 250,150,50
cy 5,0,10 0,1,0 2 8 50,250,50
Sample scenes are available in the sample/ directory.
minirt/
├── minirt.c # Entry point
├── include/ # Header files
├── source/
│ ├── render/ # Rendering loop and MLX event handling
│ │ └── ray/ # Ray tracing, lighting, intersection tests
│ ├── data/ # Scene loading and parsing
│ └── error.c
├── libft/ # Custom C library
├── libmlx/ # macOS graphics library
└── sample/ # Sample .rt scene files
