WebAssembly (C interface) → Web workers (one band each)
Web workers (one band each) → Project page (progressive render): pass after pass
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.
Workers
Time per pass (ms)
Speed-up
1
46.8
× 1.00
2
25.1
× 1.86
4
14.5
× 3.23
8
11.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.
The three spheres in glass, matte and metal, with two small ones, on the cream and chocolate checkerboard.The glass torus: the checkerboard shows through, bent by refraction.The Möbius strip in almost polished metal, reflecting the checkerboard.The matte saddle under a low, warm light (2600 K), like a setting sun.
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