Took me a while to publish this one cause I didn't quite get round to rendering this until recently. The idea for this first came from Paul Nyander's site: bugman123.com. There are all sorts of cool math coding snippets that he makes into awesome renders with Mathematica code. From there I researched the Mandelbrot set and mandelbulbs(amongst other things) on Wikipedia and fractalforums. It seemed within the realm of possibility to create fractals inside of Houdini though I had trouble converting the math into code. Luckily, I found a blog called Syntopia which was incredibly helpful in that it had some helpful example code in C, as well as a very thorough explanation on the math: http://blog.hvidtfeldts.net/index.php/2011/09/distance-estimated-3d-fractals-v-the-mandelbulb-different-de-approximations/.
Once I had this reference it wasn't all that hard to recreate this in Houdini. I took a volume, piped it through a wrangle and wrote my code out with channels included so you can get variations in the power, iterations and bailout of the code. I also added in a phase variable so the fractal could be easily animated and then I expanded the whole system by creating variations on the basic formula with some inspiration from the fractalforums.
And now for some background on what a Mandelbulb is. The Mandelbulb is based on the Mandelbrot set. The Mandelbrot set equation is z^2 +z where z is a complex number. A complex number takes the form of a + bi, where a and b are real numbers and i is the 'imaginary' number which is the square root of -1. The square root of -1 is not imaginary, it's just a silly name. A complex number has two terms; a is referred to as the 'real' part and bi is referred to as the 'imaginary' part. A complex number of the form z = a + bi belongs to the Mandelbrot set if iterating through z^2 + z heads towards zero. An 'unbounded' number increases towards infinity and is not part of the Mandelbrot set. Every other value that does not tend towards infinity is considered to be 'bounded'.
A similar set is called the Julia set whose equation is z^2 + c, where z is a complex number of the form a + bi and c is some number. For example, when c = 1 the set is 0, 1, 2, 5, 26 . . . and so c = 1 does not belong to the Julia set. When c = -1 however, the set becomes 0, -1, 0, -1 . . . and so c = -1 does belong to the Julia set.
Now, the Mandelbrot set isn't 3D by nature. To make it so, Dan White and Paul Nylander (in 2009) came up with the idea to transform the Mandelbrot set into spherical coordinates. Where your normal cartesian system uses x, y and z, the spherical system uses:
- r = the distance from the origin(this behaves like a radius)
- theta = the up/down angle(pivoted from the origin)
- phi = the side/side horizontal angle(again, pivoted around the origin)
You can transform any cartesian co-ordinate into spherical co-ordinates using these general formulas for any given (x, y, z) values that you have:
- r = sqrt(x^2+y^2+z^2)
- theta = arccos(z/r)
- phi = arctan(y/x)
In order to construct a Mandelbulb you must also use this formula developed by White and Nylander to find the nth power of the vector: v^n = r^n(sin(nt)cos(np), sin(nt)sin(np), cos(nt)). Note, you can tweak this formula to get different shapes as I did in the variations below.
And that's the basics! You can read more background at these links: https://en.wikipedia.org/wiki/Mandelbrot_set, https://en.wikipedia.org/wiki/Complex_number, https://en.wikipedia.org/wiki/Spherical_coordinate_system, https://en.wikipedia.org/wiki/Mandelbulb.
On the Houdini side, all you need are three nodes: a volume, a volume wrangle and a convert volume(well, two if you're going to use Entagma's volume rendering trick). The only settings you need to worry about are the ones in the volume node. You want to fill the name field with something(I called my 'stuff'), I changed my size to (3, 3, 3), my div size to 0.005(you might want a higher value depending on how well your machine handles) and your Display Mode under Properties should be set to Isosurface.
Be warned, this thing runs slow. You can render the volumes straight out in Houdini (Entagma shows how to do this in their Mandelbulb tutorial) but I converted mine into polygons. I also added a switch and copied the wrangles so I could switch between the different formulas. I rendered this out in Mantra but you could just as easily use Renderman or Redshift or whatever else you have on hand.
Here is an example of the VEX code that I used:
For those of you who don't want to use Houdini but want to make cool fractals, Octane for Blender can be downloaded for free and their example file has a mandelbulb fractal preloaded in with code that you can play around with: https://www.machina-infinitum.com/vectron-formulas. This site has links and instructions for getting the demo file and Octane for Blender on your machine. I haven't played around with this tool too much but the little I've seen looks very promising.
Also, if you just like fractals and don't care too much about bringing them into 3D software, there are specially made tools for creating fractal images you can play with like Mandelbulber and Mandelbulb 3D and a ton of others. The site fractalforums.com is a great place to find variations on the fractal formulas we use to make these bulbs or you can just play around with the formulas yourself and see what happens. As always, I hope you enjoyed this tutorial and if you would like to send me an email shoot it to this address: steambeanblog@gmail.com.
Take care and stay safe,
- Kit