← All projects

Science

Ray tracer

Ray-traced rendering of the common-thread meshes, in C++ compiled to WebAssembly, usable online.

Done Sprint S33-S34 · 8 points
In short, no jargon for non-developersRead the summaryClose
What it is
A program that makes realistic images of 3D objects by simulating the path of light (reflections, transparency, soft shadows), right in the page.
What it is for
This is the technique of animated films and architectural images.
What it shows
Command of image rendering, at the heart of computer graphics, with the work spread over every processor core.
Source code

How the pieces fit together

Diagram: lib-c → Engine (OBJ, PLY, STL) ; Engine → Command line (native render) ; Engine → WebAssembly ; WebAssembly → Web workers ; Web workers → Project page (pass after pass). OBJ, PLY, STL native render pass after pass lib-c reads the meshes Engine C++, BVH, path tracing Command line reference images, PSNR WebAssembly C interface Web workers one band each Project page progressive render

Ray tracing in the browser

This project's C++ engine, compiled to WebAssembly, computes the image in web workers, one per CPU core: each pass adds one ray per pixel and the picture sharpens as you watch (soft shadows, reflections, refraction through glass). Pick a scene or your own mesh, a material, then orbit by dragging the image or with the sliders.

or drop it on the image: it stays in your browser.

Light and materials

One spherical light, no caustics; 256 passes at most. The meshes are those of the 3D topology project, read by lib-c.

Measured gain with several workers

A 480 x 270 pixel image, the three spheres scene, mean of 8 passes (best of three runs), same WebAssembly module and same bands as the page, in Node threads; Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz processor, 12 threads.

WorkersTime per pass (ms)Speed-up
146.8× 1.00
225.1× 1.86
414.5× 3.23
811.6× 4.03

Beyond 4 workers the gain slows down: this processor has only 6 physical cores, the other threads share their execution units. In your browser, the time per pass shows under the image; change the number of workers to compare.

High-definition captures

Rendered by the native engine (the same C++ code, compiled for the processor) at 640 × 360, 256 passes, by scripts/captures.mjs.

Tech stack

  • C++
  • WebAssembly
  • Emscripten
  • CMake
  • GoogleTest

Who does what

C++
The engine: intersections, surface-area-heuristic BVH, path tracing, materials, light settings.
WebAssembly
The engine runs in the browser, spread over several web workers, on the project page.
Emscripten
Compiles the C++ and lib-c's reader to WebAssembly, pinned version; CI checks the build byte for byte.
CMake
The native build and tests on Linux, Windows and macOS, with ASan and UBSan.
GoogleTest
Physics tests (white furnace, analytic irradiance), the BVH against brute force, the reference images.

Definition of Done

  • Code reviewed, diff by diff
  • Unit and integration tests green
  • Green CI on Linux, Windows and macOS when compiled
  • README, REVIEW.md and DECISIONS.md up to date
  • Texts in French and English
  • Demo deployed and tested on mobile