A ray tracer written in C++17 that renders 3D scenes described via a configuration file. Outputs images in PPM format.
- Primitives: Sphere, Plane, Cone, Torus
- Lighting: Ambient, diffuse (Lambert), point lights, directional lights, shadow casting
- Anti-aliasing: 30 samples per pixel with random jitter
- Camera: Configurable position, field of view, and resolution
- Implicit surfaces: Cone and Torus solved via algebraic equation solvers (quadratic, quartic)
- Scene config: Declarative
.cfgfiles via libconfig++
- C++17 compiler (clang++ recommended)
- libconfig++
On macOS:
brew install libconfigOn Ubuntu/Debian:
sudo apt-get install libconfig++-devmakeThis produces the rtx executable.
make clean # Remove object files
make fclean # Remove object files and binary
make re # Full rebuild./rtx <scene_file.cfg> > output.ppmExample:
./rtx config.cfg > render.ppmThe image is written to stdout in PPM format. Redirect it to a file and open it with any image viewer that supports PPM (e.g., GIMP, Preview on macOS, feh on Linux).
Scenes are described in libconfig format.
camera:
{
resolution = {width = 1920; height = 1080;};
position = {x = -1.0; y = 0.0; z = 10.0;};
rotation = {x = 0.0; y = 0.0; z = 0.0;};
fieldOfView = 60.0; # degrees
};primitives:
{
spheres = (
{x = 0.0; y = 0.0; z = -1.2; r = 0.5; color = {r = 199; g = 21; b = 133;};}
);
planes = (
{
position = {x = 0.0; y = -2.0; z = 0.0;};
vector = {x = 0.0; y = 1.0; z = 0.0;}; # normal
color = {r = 152; g = 251; b = 152;};
}
);
cones = (
{x = 2.0; y = 3.0; z = -3.0; r = 3.0; h = 5.0; color = {r = 180; g = 180; b = 180;};}
);
tori = (
{
center = {x = -1.0; y = 0.0; z = 1.5;};
major_radius = 1.0;
minor_radius = 0.65;
color = {r = 200; g = 50; b = 200;};
}
);
};lights:
{
ambient = 0.2;
diffuse = 0.8;
point = (
{x = 5.0; y = 5.0; z = 5.0; intensity = 1.0;}
);
directional = (
{x = 0.0; y = -1.0; z = 0.0; intensity = 0.3;}
);
};RTX/
├── Makefile
├── config.cfg # Example scene
├── include/ # Header files
│ ├── Camera.hpp
│ ├── Color.hpp
│ ├── Cone.hpp
│ ├── HitRecord.hpp
│ ├── Image.hpp
│ ├── Light.hpp
│ ├── Lights.hpp
│ ├── Material.hpp
│ ├── Object.hpp
│ ├── Plane.hpp
│ ├── Point3D.hpp
│ ├── Ray.hpp
│ ├── RayTracer.hpp
│ ├── Rectangle3D.hpp
│ ├── Setup.hpp
│ ├── Sphere.hpp
│ ├── Torus.hpp
│ └── Vector3D.hpp
└── src/
├── Main.cpp
├── Camera/
├── Color/
├── Image/
├── Math/ # Polynomial solvers (cubic, quartic)
├── Point3D/
├── Ray/
├── RayTracer/
├── Rectangle3D/
├── Setup/
├── Shapes/ # Sphere, Plane, Cone, Torus
└── Vector3D/
| Component | Role |
|---|---|
Object |
Abstract base class for all scene primitives |
RayTracer |
Core rendering loop with shadow and shading logic |
Setup |
Parses .cfg file and builds scene objects |
Camera |
Generates primary rays from a viewpoint |
Image |
Pixel buffer; writes PPM to stdout |
poly34 |
Algebraic solvers for cone/torus intersections |