The Mandelbulb fractal has been the fractal of the year, yet the hype around it lasted for no more than a month. I guess taht gives an idea of how out of fashion fractals
are today. Nevertheless it's an interesting fractal that might encourages the most brave fractal resarchers left to further explore this branch of maths and computer
graphics. I don't consider myself a researcher in the field of fractals as I do recognize my lack of proper academic backgroud, depth of understanding of the field and
lack of dedication unlike others who know little and do bad yet they pretend being experts. Nevertheless, just as any other fractal hobbist that deserves such a geeky
title, I did my experiments on rendering Mandelbulb (and other further math investigations) when the innertia of the hype moment told me to do so. I must say it was a fun
time and I truly thank those who started the wave in the first place, that was really fun.
The ideaThe idea that originated the wave of Mandelbulb fractal was that of trying, once more, to extend the definition of the classic Mandelbrot set to three dimensions. Quaterinons, hypercomplex numbers and all other sort of (often inconsistent) algebras had been used as an attempt to generate the all-time-dream of a true 3D Mandelbrot set. Up to this point the closest thing to a 3D Mandelbrot set were very symetric extrapolations of the 2D set, like the once I did myself back in 2001. However the construction of the Mandelbulb has a different approach. Instead of thinking in algebra and in the usual iteration formula w->w^2+c, this time we think on the classic 2D set as the result of a geometric process of iterating points by squaring their distance to the origin, rotating them by an angle equal to the current angle with the positive x axis, and then translating by c. Now it's possible to try to extend this geometric process to three dimensions regardless of any algebraic correctness. And in fact the Mandelbulb formula is completelly wrong and incoherent in terms of a dynamic system, but it produces beautifull images, which is in itslef a sign that, perhaps, algebraic correctness is not what we always want. In fact, most of the proto-Mandelbulb images shown in the forums were produced with buggy code that implemented the geometric transformations completelly wrong, with incorrect derivatives calculation for the distance estimation, etc, yet the images were looking just right. The lesson learnt with this is that there is something about duplicating lengths and angles that for some reason makes sense, not only regardless of algebraic correctness of meaning, but even regardless of any geometric interpretation (remember wrong geometric formulas led to nice images anyway). This idea is reinforced by the fact that when breaking the rule of equal length exponentiation to equal angle multiplication, then the images do indeed (finally!) look wrong.
OptimizingThe above code is mathematically correct, and even fast enough to run in realtime in modern hardware (as shown thru this website, or in the Shader Toy section). However, one can still gain a 5x speed factor when rendering in some cases (like when rendering in the CPU in pure C or C++). The first thing to do is, as usual, to get rid of all those trascendental functions (the trigonometric ones) which not only are slow but also introducee unnecesary errors in the computations. By using the basic trigonometric identities of the cosinus and sinus of a doubled angle, one can replace the 8-times angle computations by repeatedly applying the identities (three times). The result is a polynomial which has to trigonometric functions and runs much faster: float x = w.x; float x2 = x*x; float x4 = x2*x2; float y = w.y; float y2 = y*y; float y4 = y2*y2; float z = w.z; float z2 = z*z; float z4 = z2*z2; float k3 = x2 + z2; float k2 = inversesqrt( k3*k3*k3*k3*k3*k3*k3 ); float k1 = x4 + y4 + z4 - 6.0*y2*z2 - 6.0*x2*y2 + 2.0*z2*x2; float k4 = x2 - y2 + z2; w.x = 64.0*x*y*z*(x2-z2)*k4*(x4-6.0*x2*z2+z4)*k1*k2; w.y = -16.0*y2*k3*k4*k4 + k1*k1; w.z = -8.0*y*k4*(x4*x4 - 28.0*x4*x2*z2 + 70.0*x4*z4 - 28.0*x2*z2*z4 + z4*z4)*k1*k2;
ExperimentsThe first video is a close zoom to the surface of the fractal object, and the second one is a morphing of the associated Julia sets of the Mandelbulb set.
|