This is the second part of Fractals 101, a series of tutorial dedicated to fractals. This post will investigate two popular fractals: the Mandelbrot set and its 3D cousin, the Mandelbulb.

- Introduction
- Part 1. The Mandelbrot Set
- Part 2. Colouring the Fractal
- Part 3. The Mandelbulb
- Part 4. Visualising the Mandelbulb
- Conclusion

#### Introduction

The previous post in this series, Fractals 101, showed how fractals can be constructed by iteration. Fractals created this way have indeed an infinite complexity, but they are also very boring. Their strong self-similarity doesn’t really allow for any *interesting* complexity to arise. Luckily, this is not always the case. Most fractals appear in the most unexpected places, rewarding you with endless beauty.

#### The Mandelbrot Set

One of the most famous fractals of this kind is the Mandelbrot set. Firstly defined in the 1978 , it was later computed and visualised by the mathematician Benoit Mandelbrot in 1980. The Mandelbrot set arises from an extremely simple equation:

In order for this fractal to appear, both and must be *complex numbers*. This blog has dedicated an entire post on Complex Numbers, in the context of 2D rotations.

The complexity hidden in comes to light when you keep repeating iterating the function, over and over. Which means, when you keep feeding the result of to itself. Starting with , we obtain the following sequence:

…and so on.

For any , this sequence has two possible behaviours: it either diverse towards infinity, or it stays forever bounded. The Mandelbrot is made of all those complex numbers for which iterating does not escape to infinity. When computing the Mandelbrot set, is iterated several times; if it stays small enough, it is assumed to be part of the set.

At a first glance, this produces a black and white figure:

White points are the values of for which diverges to infinity; while black hones are the values of for which stays confined.

The really interesting behaviour happens on the edge of the Mandelbrot set, where the white and black parts of the plane meet. Not only the edge exhibits self-similarity; it also hides an endless sea of complexity.

#### Colouring the Fractal

The original equation that defines the Mandelbrot set only allows for a black and white figure. Many coloured version of the Mandelbrot set exist, using several different technique. The most common relies on the speed at which changes. This produces stunning animations that truly highlights the complexity that hides in the fringe of the Mandelbrot set:

If you’re familiar with Shaders, the following code will allow you to calculate a Mandelbrot fractal. It requires as an input, and it outputs and a number from to that indicates how many iterations were performed before the function diverged:

float mandelbrot (float2 c) { float2 z = 0; float2 zNext; int i; for (i = 0; i < _MaxIterations; i ++) { // f(z) = z^2 + c zNext.x = z.x * z.x - z.y * z.y + c.x; zNext.y = 2 * z.x * z.y + c.y; z = zNext; // Bounded? if ( dist(z,float2(0,0)) > 2) break; } return i / float(_MaxIterations); }

The

`mandelbrot`

function can be fed with the UV of a piece of geometry. Its return value can be used to sample a ramp texture. This allows a fine control over the final colour of the produced fractal.
It’s important to notice that and are complex numbers; they are not simple 2D vectors. As such, the operation squaring results in the following expression:

And, since , we obtain:

#### The Mandelbulb

The concept behind the Mandelbrot set has been subject of extensive research. While a 3D equivalent of the Mandelbrot set does not exist, Daniel White and Paul Nylander came up with a 3D shape that exhibits similar properties. This shape has been called the Mandelbulb, since its similarity with a round bulb.

The logic behind its creation is similar to the one that generated the Mandelbrot set. Starting from zero, we iterate a 3D function . Both and are 3-dimensional vector, and .

With:

The parameters is known as the *power factor* of the Mandelbulb, and it’s used to control its shape. The introduction of trigonometric functions are used to express the Mandelbulb in spherical coordinates. Exactly like we did before, the 3D points that belongs to the Mandelbub are the ones for which the sequence:

stays bounded.

#### Visualising the Mandelbulb

To give a better understanding of what the Mandelbulb looks like, I have created a 360 video that shows the birth of this fractal, slowly changing its power factor from to .

The Mandelbulb has been rendered inside out, using a volumetric shader in Unity. The 360 effect has been achieved using 3 cameras with a large field of view. All images are wrapped to an equirectangular projection using another shader. Despite being rendered at a very high resolution, the compression of YouTube makes some parts of video slightly blurred.

#### Conclusion

#### Other resources

- Part 1. Fractals 101
- Part 2.
**Fractals 101: The Mandelbrot Set**

##### 💖 Support this blog

This websites exists thanks to the contribution of patrons on Patreon. If you think these posts have either helped or inspired you, please consider supporting this blog.

##### 📧 Stay updated

You will be notified when a new tutorial is relesed!

##### 📝 Licensing

You are free to use, adapt and build upon this tutorial for your own projects (even commercially) as long as you credit me.

You are not allowed to redistribute the content of this tutorial on other platforms. Especially the parts that are only available on Patreon.

If the knowledge you have gained had a significant impact on your project, a mention in the credit would be very appreciated. ❤️🧔🏻

I just came across your site, what an incredible work, the top notch quality !

Are you a former demoscener ?

I already plan to spend a lot of time reading your posts, so for sure I will start donating the next month.

Anyway, thanks a lot and keep up the good work 🙂

PS: “In order for this fractal to appear, both x and c must be complex numbers. This blog has dedicated an entire post on Complex Numbers, in the context of 2D rotations.”

=> The link to the post is broken.

Hey!

Thank you very much for your kind words. It’s because of comments like this one that I keep writing tutorials.

Yes, I could say I’m a demoscener. But I have never really released the stuff I’ve been working on, unfortunately! 😀