Several years ago I began to notice very beautiful 3D images on the Internet. I started to wonder how they were created as I was surprised by their realism and complexity, clearly unattainable through traditional 3D graphic methods. It turned out that in 2010 a programmer named Tom Lowe came up with an interesting algorithm for generating three-dimensional fractal objects which he called Mandelbox. It should be mentioned that shortly before that, in 2009, another mathematician -- Daniel White -- proposed a concept of 3D fractals using polar coordinates he called Mandelbulb, but Tom went the other way, even though he had both methods available to him.

Several years ago I began to notice very beautiful 3D images on the Internet. I started to wonder how they were created as I was surprised by their realism and complexity, clearly unattainable through traditional 3D graphic methods. It turned out that in 2010 a programmer named Tom Lowe came up with an interesting algorithm for generating three-dimensional fractal objects which he called Mandelbox. It should be mentioned that shortly before that, in 2009, another mathematician -- Daniel White -- proposed a concept of 3D fractals using polar coordinates he called Mandelbulb, but Tom went the other way, even though he had both methods available to him.

The first mention of Mandelbox appeared on the site “Images des Math” , then there were several publications, but they all boil down to a formula reminiscent of the Mandelbrot set:

v = s*ballFold(r, f*boxFold(v)) + c

where boxFold(v) means for each axis a:
if v[a]>1 v[a] = 2-v[a]
else if v[a]<-1 v[a] =-2-v[a]

and ballFold(r, v) means for v's magnitude m:
if m else if m<1 m = 1/m

v is the three-dimensional vector describing the coordinates of a point in 3D space. The specific implementation of this algorithm using the GLSL language is as follows:

vec4 F(vec4 v) {
  v.xyz = clamp(v.xyz, -1.0,1.0)) * 2.0 - v.xyz;
  v *= max(0.25/ dot(v.xyz, v.xyz) ,0.25);
  return v;
}

or using recursion:
float DE(vec3 pos, float scale, vec3 c){
  vec4 v=vec4(pos,1.0);
  for(int i=0;i<15;i++){
    v=F(v);
    v = v*scale ;
    v.xyz+=c;
  }
  return length(v.xyz)/v.w;
}

In order to build an image, you need to use the ray tracing method, i.e. you must move along the ray until the value of the formula DE (current position) is less than a certain threshold value.

Physically, DE () can be interpreted as a value of "the density of space" (actually 1/density). To eliminate the instability of the image when the camera is moving, it is desirable not to move the ray by a constant step, but to move it using the current value of the "density" in other words p(1)=p(0)+ray*DE0. This way, when approaching the surface, the step will decrease and the picture will no longer "flicker".

The original formula F () can be improved, for example by using additional vector conversion, applying the rotation along different axes, etc. In this case, instead of a recursive cycle we obtain a sequence of transformations:

float DE(vec3 pos, float scale)
{
  vec4 v=vec4(pos,1.0);
  v=F1(v,scale);
  v=F1(v,scale);
  …
  v=FN(v,scale);

  return (some expression such as length(v.xyz)/v.w, abs(p.x-p.y)/p.w, etc.)
}

Thus it is possible to create extremely complex and diverse images, and what is no less interesting, they can be made to move in three-dimensional space. In fact, there is a whole world that is enclosed in a small formula. Here is an example of such a world: ^Invalid YouTube URL provided

I do not want to specifically deal with the philosophical aspects of this phenomenon, but in my opinion all of these "worlds" exist in reality, only in the mathematical space rather than the physical. They are created by the Creator in the very moment when he creates the math. In fact, the artist (or programmer) simply displays these mathematical worlds in human-readable form. However a traditional artist also does not create worlds. They show what they see, or create an image based on what they saw. In the case of 3D fractals the situation is somewhat different. When an artist is working with formulas he often does not know what a given set of parameters will create. This is reminiscent of the photographer who walks around the city looking for interesting scenery but the artist moves not only in space but also through billions of "parallel universes". The first task is to find a place (a set of formulas and parameters), and then select the position of the camera, set the lighting and choose the color scheme. After that you just click on the button and voila! your picture is ready. If you want to shoot video of the generative world, everything is a bit more complicated. The fact is that randomly moving the camera it often can end up inside a structure, so to speak, "buried in stone". To prevent this unpleasant effect you need to either perform collision control (this algorithm is very time consuming) or "destroy" objects near the camera. I went with the second approach and had my camera "melt" or “vaporize" the objects on its way around the mathematical world. A little more about the implementation of this approach: Despite the fact that the formula for calculating DE () is quite simple, with the ray tracing method the total volume of computations becomes gigantic. For instance for generating an image of 1920x1080 pixels, a depth of 1000 takes about 2 billion function calls to DE (), which in turn has to call F() ten to fifteen times. This value can be somewhat reduced by moving at variable speed (which as mentioned above also improves the stability of the image), but in any case it is still hundreds of millions of calls per frame. Modern personal computers are not able to handle such a volume of calculations in real time - to generate a single image would take a few minutes. Fortunately, there is another approach. Modern graphics cards are designed to perform parallel calculations with the vector format float, which is just what is required to implement this algorithm. In this way the number of processing channels reaches in the thousands (e.g. Titan Z has 5760 processors). Since all calculations are made on one and the same formula, it is ideally suited to the architecture of graphics cards and allows the generation of three-dimensional images of high definition in near real time. For example a typical rate of image generation on my card (GTX 780 with 2880 processors) is about 10-12 frames per second. It can be expected that the progress of technology will soon allow for the generation of real-time stereoscopic images in 4K.

You can see examples of three-dimensional worlds that are generated by the described algorithm on the site http://www.sanbasestudio.com A few weeks ago I finished 3D BluRay disk that contains a journey across dozens of generative worlds. If you have a 3D TV, you definitely need to have this disk, because then you will be able to see ALL the features of your TV. But even those who do not have a 3D will find it interesting to look at the fantastic worlds generated by simple formulas. The disc can be ordered from http://www.sanbase.org

And finally, a few pictures: http://www.sanbasestudio.com/art/img/x1656.jpg - 800x450 http://www.sanbasestudio.com/art/img/ex1656.jpg - HD version (1600x900)

http://www.sanbasestudio.com/art/img/x1653.jpg http://www.sanbasestudio.com/art/img/ex1653.jpg

http://www.sanbasestudio.com/art/img/x1642.jpg http://www.sanbasestudio.com/art/img/ex1642.jpg

Richmond Hill, Canada Email: info at sanbasestudio.com