[Media] I've made a simple GPU-accelerated Mandelbrot explorer in Rust! :)

94 points bambamboo15 34 comments
[Media] I've made a simple GPU-accelerated Mandelbrot explorer in Rust! :)

Hello everyone! I wanted to experiment with wgpu and WASM to make a simple fractal explorer for the browser :)

The code is entirely hand-crafted (by me!!), although high-level algorithmic design and wgpu boilerplate were AI-assisted.

The renderer is somewhat laggy, but it uses perturbation algorithms where I only calculate the center in full precision on CPU and the pixels are calculated using low-precision offsets around that on the GPU. Instead of using f32 directly, which underflows after zooming a little, I thought of a custom FloatExp type which has f32 precision but an i32 exponent. This allows me to zoom as far as I want while still using the GPU!

To be honest, this project still needs a lot of improvement, such as not blocking when the calculations take too long, and supporting better rendering. I had to scale down the resolution for performance, but I'm happy with how it is for now!

Along with the wgpu and wasm-bindgen APIs, I also appreciate dashu for providing easy CPU multiprecision calculations. I did catch a bug with base conversion in dashu, which was fixed quickly. It's manually pulled in the repository to keep the fix.

My code: github.com/bambamboo15/mandelbrot-website

Try it here: bamburac.com/mandelbrot