3D Mandelbulb Ray Tracer

Published on 13 December 2009

There has been quite a stir in recent months with the discovery of the closest approach yet to generating a true 3D version of the Mandelbrot fractal, dubbed the Mandelbulb.

The search for a true 3D Mandelbrot has been sought unsuccessfully for a number of years. However, recently Daniel White, Paul Nylander and many others on FractalForums found that a slightly different approach yielded a true fractal structure in three dimensions; that is the images continue to reveal finer details the closer you look.

If you want to dive right in and give it a go then jump to the project page.

Power 8 Mandelbulb

How it works

The fractal calculation follows a similar process as a normal Mandelbrot set using the same formula,
w' = wn + c, but instead of using standard complex numbers w and c are hyper-complex 'triplex' numbers with three components corresponding to the Cartesian x, y, and z co-ordinates.

The triplex number w is raised to a power n using the following terms:

w = {x, y, z}n = rn { sin(θn) cos(φn), sin(θn) sin(φn), cos(θn) }

where:
r = sqrt( x2 + y2 + z2 )
θ = atan2( sqrt( x2 + y2 ), z )
φ = atan2( y, x )

The fractal is ray traced using basically the same process as the 4D Quarternion Julia set fractal; for each pixel a ray is stepped into the scene by a small amount. The x, y and z co-ordinates of the ray at this point provide the input triplex number for the fractal equation, which is then iterated until the magnitude of the triplex number exceeds a bailout value (usually 4.0), or the maximum iteration count is reached.

At the end of the iteration loop a distance estimation function is used to calculate the closest point in any direction to the fractal surface. It is defined as:

distance estimation = 0.5 * |w| * log(|w|) / |δw|

where |w| is the magnitude of the triplex number w and δw is the derivative.

The distance estimation value is crucial to the ray tracing process. It tells us the maximum step distance the ray can move before we need to recalculate the fractal at the new location, which is far more efficient than a fixed step ray marching approach.

When the distance estimation value drops below a defined threshold, epsilon, we are within intersection distance of the approximate fractal surface. If this happens we calculate the vector normal based on the fractal surface gradient, which defines the shading of that point.

Download and usage details

Head over to the project page to download the scripts and learn what each of the parameters can do.

Julia berryThe Juliaberry, juicy and yet somehow quite grotesque!

 

Tags: Fractals, Pixel Bender, Quartz Composer, Ray tracing, Rendering   Last updated: 15 December 2009

15 Comments

  • bec commented at 15 December 2009 at 03:59

    thanks for putting all this together!
    the results are amazing.

  • Frank commented at 15 December 2009 at 08:01

    simply wow Tom!

  • noj commented at 15 December 2009 at 10:35

    before I die, I need to meet you. Man you inspire me to learn maths :) great work mate

  • oppenheimer commented at 15 December 2009 at 16:33

    I followed the discussion over at fractalforums for quite a while and i am very impressed that you made a plugin out of it. really good work!

  • vade commented at 15 December 2009 at 18:46

    Nice !

  • alx commented at 15 December 2009 at 21:59

    I love the screenshots. This is amazing work. And the AO approximation effect works so well, too.

    Great work!

    a|x

  • Prack! commented at 23 December 2009 at 11:21

    great and amazing job! thanx for sharing! ;-))

  • Rich commented at 23 December 2009 at 16:44

    Your script and the results achieved are amazing! Congrats on this fantastic work and I hope you continue developing it!

    -Rich

  • Silicon Soul commented at 10 January 2010 at 04:58

    Spectacular!

  • Steve commented at 20 January 2010 at 18:58

    I'm sitting here with my jaw on the desk.. this is the holy grail, I've wanted to play with fractals in 3D since the days of Fractint for DOS.
    I've just played with this a bit in pixel bender, and I must be missing something- is it possible to render these out at a larger scale? I just got a computer with a GPU a month ago, I just bought Adobe CS, and this is the first time I've even loaded up Pixel Blender, so I'm entirely clueless. But I am SO digging what I'm seeing so far,

    Now, if you can figure out a way to export these things in a 3D mesh... then I can die a happy man.

  • Jonathan Wolfe commented at 28 January 2010 at 19:41

    Hi Tom - I LOVE your work, and really appreciate you sharing your GPU-driven rendering of the Mandelbulb. I'm totally hooked. (I'm glacially rendering animations in UltraFractal too, so I really love the speed of your implementation!) I'd like to see if Quartz Composer can help me animate, but before I download the ~1GB Xcode to play with it, I'm wondering if there's a way to have it export the frames of an animation instead of just a .mov file? Any idea? I render hires fractal videos for planetariums, but for that output I need a sequence of images, not a movie. Thanks!!!

  • Tom commented at 28 January 2010 at 22:22

    Steve: you can specify the output size, be careful though as it is possible to lock up your GPU if you push it too high, especially with anti-aliasing! Unfortunately it isn't possible to generate a 3D mesh from this implementation of the Mandebulb fractal. A completely different approach to render the shape using something like voxels would be required instead.

    Jonathan: The best way to render out QuartzComposer patches is to use this little 3rd party app: Quartz Crystal http://kineme.net/product/QuartzCrystal It has quite a few export options as well as supporting image sequences instead of movies.

  • wax78 commented at 16 February 2010 at 15:31

    "be careful though as it is possible to lock up your GPU if you push it too high, especially with anti-aliasing"
    Having same issue when using too 'expensive' shaders. The only solution i've found for now is not to draw a quad on the entire screen but i divide the huge square in little ones and i compute 1 little square by draw loop. It's of course more slow, but the GPU won't lock anymore you use use enough subdivision. (dunno if u understand my bad explanation). (I do it under JOGL not quartz).

  • clement commented at 21 February 2010 at 10:39

    Simply the most impressive 3d fractals i've seen.

    I don't know if you're into that type of designs,
    but would be awesome melted with H.r giger's Aliens designs

    Anyway its alrealdy beautiful on its own.
    Congrats !

    You should really send artworks for the Alien 0 movie they're preparing. Not kidding.

    Keep it up, see you !

  • e-berlin commented at 5 March 2010 at 13:37

    man, this is awesome! keep up the good work and continue creating miracles.

    greets,
    the whole amazed e-berlin team

Post a comment

  • Required
  • Required, but will stay hidden
  • Optional
  • HTML tags <strong> and <em> are allowed.
  • Submitting...