Flying through the Mandelbrot

Wilf (Neil Wilkinson)
4 min readOct 31, 2020

--

About 35 years ago I typed out some code from a magazine (back then this was the only way to “download” software) and saw my very first fractal as a Mandelbrot set.

It looked something like this:

c = (-2, -2) => (2,2)

My mission has been to turn this into a 3D landscape that I can fly through…

For the impatient, here is the result:

There is a lot of information about how this is done on the internet for those that are interested, but for now, just know that for every x, y coordinate there is a number of iterations to get to an answer. Either the coordinate is “in the set” represented by the black part or it is “out of the set” represented by the colourful parts.

The colour at each x, y represents the number of iterations in an attempt to discover the “in” or “out”. “In” (black) means at that coordinate, we’ve given up, it’s in. “Out” is “how many iterations did we attempt before we determined it was out”. The subtle variations in the iterations is the depth of the coordinate.

All those years ago (I was 13 at the time) I realised that colour was just an attempt by the programmer to represent a third dimension. It’s been on my mind occasionally since then that one day I will see the third dimension as height instead of colour.

Side note: really this is another artificial 3rd dimension, just replacing one artificial representation (colour) with another (height). The calculations behind the scenes are 2 dimensional (real and imaginary).

And success, here a screenshot of the exact same coordinates as the picture above, but in 3 dimensions.

c = (-2, -2) => (2, 2)

But that isn’t the most interesting part. As anyone that has explored the Mandelbrot will know, the interesting stuff comes when you generate pictures of tiny fragments on the boundary of “out” and “in”.

So annoyed that I didn’t save the coordinates for this one

But this isn’t just a picture, it’s a 3D model.

So let’s fly together through the Mandelbrot set:

How I did this

I’ll wont bore you with all the details of various things I tried (UE4 C++ is great, but the landscape stuff is complicated and poorly documented).

Ultimately, I’m using UE4 just for a way to explore a 3D landscape.

In any language of your choice, create a program that does the basic Mandelbrot algorithm, but importantly spits out a greyscale PNG. This is the output for -3.0,-2.0 to 1.0, 2.0. Quite simply, the darker the pixel, the less height it has.

In UE4:

Create a landscape in your project, I created 64x64 component resolution, 1x1 subsections and maxed the number to create a 2017x2017 resolution landscape.

Then go to Landscape Mode, right-click on “Heightmap” and “Import from file” and select your greyscale PNG.

Select a material for your landscape, rebuild the lighting and there you have it.

My lighting setup is very primitive right now, I’m sure there is a lot I can do to optimise it. I have the default Light Source that UE4 provides, plus I added a directional light behind my player pawn.

Adding some basic flying blueprint enables me to fly through the landscape when the program runs.

This greyscale:

Turned into this model:

Turned into this fly-by video:

This greyscale:

Turned into this 3D model:

Which turned into this fly-by:

And then I discovered how to create 16-bit greyscale heightmaps (the above are all 8-bit), so need to redo everything :)

--

--

Wilf (Neil Wilkinson)
Wilf (Neil Wilkinson)

Written by Wilf (Neil Wilkinson)

A self-professed nerd that works as a CTO by day and a gamer/programmer by night

No responses yet