A simple ray tracer built in C using the Phong lighting model. This project renders 3D scenes defined in .rt files, supporting spheres, planes, cylinders, and cones with configurable lighting and textures.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||
- Ray tracing with Phong lighting model (ambient, diffuse, and specular components)
- Multi-threaded rendering for improved performance
- Supported objects:
- Spheres (
sp) - Planes (
pl) - Cylinders (
cy) - Cones (
co)
- Spheres (
- Multiple light sources with configurable brightness and color
- Checkerboard texture pattern
- Configurable camera position, orientation, and field of view
- Linux with X11
- GCC compiler
- Make
- X11 development libraries (
libx11-dev,libxext-dev)
sudo apt-get install libx11-dev libxext-devsudo dnf install libX11-devel libXext-develmakeTo rebuild from scratch:
make reTo build with debug symbols and sanitizers:
make debug./miniRT -s <scene_file.rt>
./miniRT --scene=<scene_file.rt>| Option | Description |
|---|---|
-s, --scene=FILE |
Scene file to render (.rt format) |
-h, --help |
Display help message |
-V, --version |
Display version information |
ESCorQ- Close the window and exit
./miniRT -s scenes/room.rtScene files use a simple text format where each line defines an element.
A <ratio> <R,G,B>
ratio: Ambient lighting ratio (0.0 to 1.0)R,G,B: Color in RGB format (0-255 each)
Example: A 0.2 255,255,255
C <x,y,z> <vx,vy,vz> <fov>
x,y,z: Camera positionvx,vy,vz: Normalized orientation vector (-1.0 to 1.0)fov: Field of view in degrees (0 to 180)
Example: C 0,0,20 0,0,-1 70
L <x,y,z> <brightness> [R,G,B]
x,y,z: Light positionbrightness: Light brightness ratio (0.0 to 1.0)R,G,B: (Optional) Light color
Example: L -40,50,0 0.6 255,255,255
sp <x,y,z> <diameter> <R,G,B> [specular] [texture]
x,y,z: Center positiondiameter: Sphere diameterR,G,B: Colorspecular: (Optional) Specular coefficienttexture: (Optional)cfor checkerboard
Example: sp 0,0,20 12.6 10,0,255 0.5 c
pl <x,y,z> <nx,ny,nz> <R,G,B> [specular] [texture]
x,y,z: Point on the planenx,ny,nz: Normal vector (-1.0 to 1.0)R,G,B: Colorspecular: (Optional) Specular coefficienttexture: (Optional)cfor checkerboard
Example: pl 0,-10,0 0,1,0 0,255,0 0
cy <x,y,z> <nx,ny,nz> <diameter> <height> <R,G,B> [specular] [texture]
x,y,z: Center of the basenx,ny,nz: Axis direction (-1.0 to 1.0)diameter: Cylinder diameterheight: Cylinder heightR,G,B: Color
Example: cy 50,0,20.6 0,0,1 14.2 21.42 10,0,255 0.5
co <x,y,z> <nx,ny,nz> <diameter> <height> <R,G,B> [specular] [texture]
x,y,z: Apex positionnx,ny,nz: Axis direction (-1.0 to 1.0)diameter: Base diameterheight: Cone heightR,G,B: Color
Example: co 0,0,0 0,1,0 10 15 255,128,0 0.8
The scenes/ directory contains example scene files:
room.rt- Indoor scene with multiple objectsmultispheres.rt- Multiple spheres demonstrationcylindercaps.rt- Cylinder with capsscene.rt- Basic scene
.
├── incs/ # Header files
├── minilibx/ # MiniLibX graphics library
├── scenes/ # Example scene files
├── srcs/ # Source files
│ ├── parsing/ # Scene file parsing
│ └── render/ # Ray tracing and rendering
├── Makefile
└── README.md
- Ray Tracing in One Weekend - Excellent introduction to ray tracing
- Scratchapixel - Comprehensive computer graphics tutorials
- Ray Tracing (Wikipedia)
- Phong Reflection Model - The lighting model used in this project
- Phong Shading (Learn OpenGL)
- Ray-Sphere Intersection
- Ray-Plane Intersection
- Ray-Cylinder Intersection
- Quadric Surfaces - Mathematical basis for cones and cylinders
- "Fundamentals of Computer Graphics" by Peter Shirley
- "Physically Based Rendering: From Theory to Implementation" by Pharr, Jakob & Humphreys
- sdummett
- etran
This project was developed as part of the 42 school curriculum.
















