TwentyFiveSoftware / ocaml-ray-tracing

OCaml implementation of Peter Shirley's Ray Tracing in One Weekend book.

Repository from Github https://github.comTwentyFiveSoftware/ocaml-ray-tracingRepository from Github https://github.comTwentyFiveSoftware/ocaml-ray-tracing

Ray Tracing

Overview

This is my take on Peter Shirley's Ray Tracing in One Weekend book.

This project uses the OCaml programming language, which is a general-purpose, functional programming language.

Build & Run this project

  1. Install OCaml (including the opam package manager)
  2. Switch to a OCaml version that has the flambda compiler enabled (the ocaml-option-flambda option) Check the releases page for the newest verson
    opam switch create flambda ocaml-variants.5.1.0+options ocaml-option-flambda
  3. Clone the repository
  4. Optional: Change sample and thread count in bin/ray_tracing.ml
  5. Install dependencies
    opam install . --deps-only
  6. Build the project
    dune build --release
  7. Run the executable
     ./bin/ray_tracing.exe

Performance

I've already implemented Peter Shirley's ray tracing in various programming languages running on CPU & GPU and compared their performance.

The performance was measured on the same scene (see image above) with the same amount of objects, the same recursive depth, the same resolution (1920 x 1080). The measured times are averaged over multiple runs.

Reference system: AMD Ryzen 9 5900X (12 Cores / 24 Threads) | AMD Radeon RX 6800 XT

1 sample / pixel 100 samples / pixel
Elixir 67,200 ms N/A
JavaScript - Node.js 4,870 ms 308 s
Go 1,410 ms 142 s
OCaml 795 ms 75 s
Java 770 ms 59 s
C++ 685 ms 70 s
Rust 362 ms 36 s
C 329 ms 33 s
GPU - Compute Shader 21 ms 2 s
GPU - Vulkan Ray Tracing Extension 1 ms 0.1 s

About

OCaml implementation of Peter Shirley's Ray Tracing in One Weekend book.


Languages

Language:OCaml 99.3%Language:Makefile 0.7%