A CPU ray tracer built from scratch. One pixel at a time.
A path-tracing renderer built from first principles. No OpenGL, no Vulkan, no game engines—just a framebuffer, a ray, and the rendering equation. The goal is to understand how light behaves by simulating it directly.
- Fundamentals: Every graphics engine is a layer on top of ray tracing. Start at the bottom.
- Beautiful Results: Even simple diffuse + metal + glass produces images that feel real.
- Reference: This project follows the structure of Peter Shirley's "Ray Tracing in One Weekend" series (books 1–3). The code is a ground-up rewrite for practice, not a copy.
- C++17
- CMake — build system
- stb_image_write — PNG output (header-only)
- PPM — raw RGB output for early debugging
cd raytracer
mkdir build && cd build
cmake ..
cmake --build . -j
./raytracer > image.ppm
# or for PNG:
./raytracer --png output.png[image_placeholder: first_sphere.png]
[image_placeholder: glass_metal_scene.png]
| Flag | Description |
|---|---|
--ppm |
Raw PPM, stdout (default) |
--png FILE |
PNG via stb_image_write |
--width N |
Image width (default 400) |
--height N |
Image height (default 225) |
--samples N |
Samples per pixel (default 100) |
--depth N |
Max ray bounce depth (default 50) |
Apache-2.0
If this project saved you time, solved a problem, or just made your day a little more neon, you can fuel the next one:

