fractal renderer
you can find the code for this project on gitlab.
how everything began
i already explained how i got interested in fractals in this page, but what you need to know is that i first experimented with escape-time fractals on my calculator...
after some fiddling, i realized that rendering fractals this way was
- inefficient
- giving ugly results
- insanely annoying to tweak
with this in mind i started working on a tiny program written in rust to render escape-time fractals.
basic features
when i started working on this project, i wanted to get pretty pictures as early as possible.
i used serde – which is a rust crate – to directly (de)serialize the struct representing a fractal configuration (formula, position, zoom, coloring, etc.), which made it easy to tinker with some formulas and get a few renders.
the rendering part of the program was also very simple and quite rustic, if i dare say.
the anti-aliasing spiral
after establishing the basic functionality of my software, i posted some of my renders on a certain fractal discord server. someone on this server pointed out that my images were not anti-aliased.
indeed, without anti-aliasing, my renders looked a bit crispy. i was given a link to a google collab notebook which explained a sampling scheme allowing for anti-aliased image outputs. however, i wanted to try and implement anti-aliasing myself.
spoiler: there is a reason why signal processing classes exist ;)
even after watching countless videos and trying a lot of different hacks, my results were not convincing and i had to give up and use the implementation from the colab... it works wonders by the way.
some of its key tricks are:
- to use fibonacci lattices to generate uniformly distributed sampling points over a square
- to have a different yet very similar sampling pattern for each pixel, as shown in the figure below
this allows for a good approximation of each pixel's average color while reducing aliasing effects which partly originate from sampling with the same sampling pattern everywhere.
(the difference is very subtle)
gui
did you know ? manually editing floating point numbers to change the render position/zoom in a text parameter file for exploring a fractal is a bit finicky.
this is why i created a simple gui with a preview. it made exploration much easier. it has now evolved into quite a polished one in my opinion.
optimization
at some time, i also added the use of simd operations to speed up computation and theoretically, it almost halved rendering time.
final word
working on this project was a lot of fun and i learned a lot, especially about anti-aliasing, which is – in my opinion – a fascinating subject.
you can find some of my fractal renders