Skip to content

tufteddeer/raytracing-gleam

Repository files navigation

This is a Gleam rewrite of the raytracer in the Ray Tracing in One Weekend book. It covers the first 10 chapters, up to metal materials.

This project is used as a demo for my Gleam to WebAssembly compiler and won't work with the regular Gleam compiler.

Try it

Tested in Chrome 139.0.7258.139 and Firefox Developer Edition 140.0b9.

Safari 18.5 does not work because they do not support JS builtin string constants used by the WebAssembly module.

Building and running

Use docker or one of the other methods described in the compiler readme to build the project.

docker run -v ./:/src -it ghcr.io/tufteddeer/gleam-webassembly:webassembly bash -c "gleam build --target webassembly"
docker run -v ./:/src -it ghcr.io/tufteddeer/gleam-webassembly:webassembly bash -c "gleam build --target javascript"

Then use caddy or any other static file server:

caddy file-server

Deployment

After building, use the provided script to assemble the dist directory that can be deployed as a static site:

./dist.sh

Benchmarking script

To make comparing the performance of different Wasm binaries easier, the bench_wasm.js script takes a path to the module file and executes it. It will not render an image but print the pixel coordinates and colors to the console to prevent unrealistic optimization.

deno run -A bench_wasm.js raytracing.wasm

classless.css source: https://github.com/emareg/classlesscss, MIT

About

A showcase for my Gleam to WebAssembly compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors