miniRT is a small ray tracer written in C as part of the 42 curriculum. It parses a .rt scene file, casts one ray per pixel, computes intersections against simple primitives, and displays the rendered image in a MiniLibX window.
This code was written by hand and thought through with my own head, with all its imperfections in code structure, algorithms, naming, and tradeoffs. It belongs to the moment just before AI became the inevitable standard in daily programming.
Today I alternate between deep dives and tests before allowing myself to use AI: I first make sure I understand the tool well enough to rely on it responsibly.
I also simply love coding, and I take less pleasure and satisfaction from generating code than from building it myself. Even after all the effort spent learning these tools before using them, I still sometimes feel a little less legitimate when AI is involved.
This is also a project where I pushed my limits again, discovered subtleties of the C language, and took deep dives into mathematical and physical concepts. I was fascinated by their beauty, and translating a physical phenomenon into code was a deeply interesting experience to live through.
- Scene parsing from
.rtfiles - Perspective camera with configurable position, orientation, and field of view
- Ambient and point light support
- Sphere, plane, and cylinder primitives
- Object colors in RGB format
- Diffuse lighting with hard shadows
- Matrix-based object transforms
- MiniLibX window rendering
Example scene file:
A 0.2 255,255,255
C 0,0,20 0,0,-1 90
L -4,4,4 3 255,255,255
pl 0,0,-6 0,0,1 80,80,80
pl 0,6,0 0,1,0 80,80,80
pl 6,0,0 1,0,0 80,80,80
pl -6,0,0 1,0,0 80,80,80
pl 0,-6,0 0,1,0 80,80,80
cy 2.5,0,0 0,1,1 2 1 120,0,120
sp -2.5,0,0 2 120,0,120
Each scene is described by one .rt file. Empty lines are allowed.
| Identifier | Description | Format |
|---|---|---|
A |
Ambient light | A <ratio> <R,G,B> |
C |
Camera | C <x,y,z> <orientation> <fov> |
L |
Point light | L <x,y,z> <brightness> <R,G,B> |
sp |
Sphere | sp <x,y,z> <diameter> <R,G,B> |
pl |
Plane | pl <x,y,z> <normal> <R,G,B> |
cy |
Cylinder | cy <x,y,z> <axis> <diameter> <height> <R,G,B> |
This project uses the Linux version of MiniLibX and links against X11.
On Debian/Ubuntu:
sudo apt update
sudo apt install build-essential xorg libxext-dev libbsd-dev zlib1g-devmakeThe executable is created as:
./mini_rt./mini_rt scene/valid.rtControls:
| Key | Action |
|---|---|
Esc |
Close the window |
inc/ Public headers
src/ Ray tracing, parsing, camera, lighting, geometry, and MLX code
lib/ Local libraries: libft, dlst, vector, matrix, MiniLibX
scene/ Example and test scenes
Makefile Build rules
make # Build mini_rt
make clean # Remove object files
make fclean # Remove object files and executable
make re # Rebuild from scratch
make norm # Run norminette on project sourcesThe project is intended to run in a Linux/X11 environment. On macOS, compilation may fail unless X11 headers and compatible MiniLibX dependencies are installed.