Skip to content
C-Ray is a small, simple path tracer written in C
C CMake Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Rendering with SDL installed

Example render (2000 samples, 1920x1080, 50 bounces, 1h 55min)


Build Status


C-ray is a simple path tracer built for studying computer graphics. It's also a great platform for developing your own raytracing algorithms. Just write your own rayTrace() function! Multithreading, 3D model loading and render previews are handled by C-ray, so you can concentrate on the core principles.

C-ray currently supports:

  • Real-time render preview using SDL
  • Easy scene compositing using JSON
  • Multithreading
  • OBJ loading with matrix transforms for compositing a scene
  • PNG and BMP file output
  • k-d tree acceleration structure for fast intersection checks even with millions of primitives
  • Antialiasing
  • Multi-sampling
  • Russian Roulette path optimization

The default recursive path tracing algorithm supports:

  • metal
  • glass
  • lambertian diffuse
  • triangles and spheres
  • Depth of field
  • Diffuse textures

Things I'm looking to implement:

  • Built a more robust API with a scene state.
  • Some procedural textures
  • Expand the default path tracer to use PBR


Please see the Wiki for details on how to use the JSON scene interface!


  • CMake for the build system
  • SDL2 (Optional, CMake will link and enable it if it is found on your system.)
  • Standard C99/GNU99 with some standard libraries

All other libraries are included as source


macOS: Either follow these instructions, or the instructions for Linux below. Both work fine.

  1. Install SDL2 (See installing SDL below)
  2. Open the .xcodeproj file in Xcode
  3. Edit scheme by clicking C-Ray in top left, make sure 'Use custom working directory' is ticked and set it to the root directory of this project.
  4. Go into the Arguments tab, and add by clicking +. Type in ./input/scene.json, then click close
  5. Uncomment the UI_ENABLED define at the top of src/includes.h if you have SDL2 installed.
  6. Build&Run with CMD+R


  1. (Optional) Install SDL2 (See installing SDL below)
  2. Run cmake ., or optionally cmake . -DNO_SDL2=True to disable SDL2.
  3. Run make to build the project
  4. Run binary: ./bin/c-ray ./input/scene.json (Making sure the working dir is the root directory). You can also pipe files into C-ray and it will read from there. This is useful for scripts that invoke C-ray. Example: cat input/scene.json | ./bin/c-ray


  1. Download SDL2 Development libaries from here and extract: (
  2. Open a x64 Native Tools Command Prompt and set path to SDL2DIR (where you extracted the files to, should have a few folders like 'include' and 'lib'): set SDL2DIR=E:\sdl2\SDL2-devel-2.0.8-VC\SDL2-2.0.8
  3. Run cmake: cmake -G "Visual Studio 15 2017 Win64" .
  4. (Optional) Edit src\includes.h to uncomment #define UI_ENABLED and copy your SDL2.dll into bin\Release\
  5. Build the generated solution: msbuild c-ray.sln /p:Configuration=Release
  6. Run: bin\Release\c-ray.exe input\scene.json or type input\scene.json | bin\Release\c-ray.exe

Installing SDL

On macOS, use homebrew to install SDL. brew install sdl2

On Windows, download from

On Linux using APT, run sudo apt install libsdl2-dev

Writing your own raytracing algorithm

See writing your own rayTrace()


No tests yet! Maybe soon!


3rd party libraries included in this project

OBJ Loader library:

lodePNG PNG compression library:


JSON parsing library:

PCG random number generator:


If you know more than me, please do get in touch at vkoskiv [at] gmail (dot) com!

You can also ping me on Discord!: vkoskiv#3100

You can’t perform that action at this time.