Ray tracing with Zig and WASM

I’ve been working on a Zig implementation of The Ray Tracer Challenge by Jamis Buck, and I’m finally at a point where I’m happy to share it. You can find the source code in the project repo (please ignore the hideous code for scene description parsing and the frontend).

You can also see the ray tracer in action on the online playground, where you can make your own scenes with the scene description editor. The scene description format is a JSON version of the YAML format that the Ray Tracer Challenge’s author uses, with some tweaks. You can choose from an array of pre-made scenes to get a feel for it.

This is my first project with Zig, and I’m really happy with how it turned out! Despite some of its current shortcomings when dealing with concurrent WASM, I think Zig was a good choice. I never dived too deep into optimizations, and yet the ray tracer is still very fast compared to other ray tracer challenge implementations I’ve seen. Zig also made targeting WASM (mostly) painless. And for anyone here who finds this interesting, I’d highly recommend picking up The Ray Tracer Challenge; it’s very well put-together and has made for a fun project.

12 Likes

Wow, awesome! Great job!

1 Like