Path Tracing

Programming Language

This project is written in C++, with multi-threading support provided by the C++11 standard library to speed up rendering.

Building and Running

Copies of the source are provided for you to check your work and compare against. If you wish to build the provided source, this project uses CMake. To build, go to the root of the project directory and run the following commands to create the debug version of every executable:

$ cmake -B build
$ cmake --build build

You should run cmake -B build whenever you change your project CMakeLists.txt file (like when adding a new source file).

You can specify the target with the --target <program> option, where the program may be inOneWeekend, theNextWeek, theRestOfYourLife, or any of the demonstration programs. By default (with no --target option), CMake will build all targets.

$ cmake --build build --target inOneWeekend

Optimized Builds

CMake supports Release and Debug configurations. These require slightly different invocations across Windows (MSVC) and Linux/macOS (using GCC or Clang). The following instructions will place optimized binaries under build/Release and debug binaries (unoptimized and containing debug symbols) under build/Debug:

On Windows:

$ cmake -B build
$ cmake --build build --config Release  # Create release binaries in `build\Release`
$ cmake --build build --config Debug    # Create debug binaries in `build\Debug`

On Linux / macOS:

# Configure and build release binaries under `build/Release`
$ cmake -B build/Release -DCMAKE_BUILD_TYPE=Release
$ cmake --build build/Release

# Configure and build debug binaries under `build/Debug`
$ cmake -B build/Debug -DCMAKE_BUILD_TYPE=Debug
$ cmake --build build/Debug

We recommend building and running the Release version (especially before the final render) for the fastest results, unless you need the extra debug information provided by the (default) debug build.

CMake GUI on Windows

You may choose to use the CMake GUI when building on windows.

  1. Open CMake GUI on Windows
  2. For "Where is the source code:", set to location of the copied directory. For example, C:\Users\Peter\raytracing.github.io.
  3. Add the folder "build" within the location of the copied directory. For example, C:\Users\Peter\raytracing.github.io\build.
  4. For "Where to build the binaries", set this to the newly-created "build" directory.
  5. Click "Configure".
  6. For "Specify the generator for this project", set this to your version of Visual Studio.
  7. Click "Done".
  8. Click "Configure" again.
  9. Click "Generate".
  10. In File Explorer, navigate to build directory and double click the newly-created .sln project.
  11. Build in Visual Studio.

If the project is succesfully cloned and built, you can then use the native terminal of your operating system to simply print the image to file.

Running The Programs

You can run the programs by executing the binaries placed in the build directory:

$ build\Debug\inOneWeekend > image.ppm

or, run the optimized version (if you compiled with the release configuration):

$ build\Release\inOneWeekend > image.ppm

The generated PPM file can be viewed directly as a regular computer image, if your operating system supports this image type. If your system doesn't handle PPM files, then you should be able to find PPM file viewers online. We like ImageMagick.