# Recreating Mandelbulbs with math nodes

I'm trying to recreate a Mandelbulb using Volume and math nodes in blender. I have been able to create a Mandelbrot with math nodes but I am having problems making it 3d.

I tried translating this formula to math nodes:

$$\mathbf v^n := r^n \langle \sin(n\theta)\cos(n\phi), \sin(n\theta)\sin(n\phi),\cos(n\theta) \rangle$$

where

$r = \sqrt{x^2 + y^2 + z^2}$,
$\phi = \arctan(y/x) = \arg(x + yi)$, and
$\theta = \arctan\left(\sqrt{x^2 + y^2}/z\right) = \arccos(z/r)$.

https://en.wikipedia.org/wiki/Mandelbulb the results should look something like this: but it ends up looking like this: I hope someone knows what I'm doing wrong.

• Can you share your Blend file (upload it to blend-exchange.giantcowfilms.com and paste the link into your question). Most of the content of your screenshot is hidden (as the nodes are collapsed) so it's tricky to spot anything that might be amiss (eg, a node could be set to 'Clamp' when it shouldn't, duplicate nodes could appear to be connected correctly but actually it's the node underneath that's connection, etc.). Also, it would take someone a lot of effort to try and build that node tree from scratch - better to be able to pick up yours as a start point. – Rich Sedman May 10 '18 at 12:03
• I see that you may be using tan instead of sin. Try changing that maybe? – abandoned account May 14 '18 at 23:52
• Your shape actually looks quite similiar to this, from this dorky site. – Leander Jun 4 '18 at 13:07

It's impossible to tell what's going wrong in your particular case as there just isn't enough information in your question - you've only partially shown the 'internal' node tree (many of the nodes are hidden, meaning it's impossible to verify that they aren't marked as 'Clamped' and left assuming that, say, 'Root' is raising to the power of 0.5) and you don't show any detail of how the group is actually being used (it's hinted at behind your 'group' nodes but nothing explicit) - which is quite critical.

However, it is possible to produce such a result as shown below (assuming I've got my maths correct). The example image you provided must have been produced with a large number of iterations of the calculation - which would take a considerable amount of time to render. For my example I have limited it to a relatively small number of iterations to demonstrate the concept.

With the new Dynamic Maths Expression node you can create the node trees for each of the functions by simply entering the relevant expression. For example,

'r' : (x**2+y**2+z**2)**0.5 This automatically creates the following nodes behind the scenes : Similarly, 'theta' :atan(((x**2+y**2)**0.5)/z) And 'phi':atan(y/x) We can then use a similar technique to create expressions for 'newx', 'newy', and 'newz' :

newx = (r**n)*sin(n*theta)*cos(n*phi)
newy = (r**n)*sin(n*theta)*sin(n*phi)
newz = (r**n)*cos(n*theta)


These can then be linked together to form the following node group for the calculation of one 'iteration' : Note that some of the inputs are fed directly out to the outputs - this is to assist with linking mulitple iterations together. Also the 'Valid' input/output is modified based on the condition that the result of this node is detected as 'outside range'. This is to detect the termination of the series at the specific iteration - if any iteration is out of range then we need to detect it rather than taking acount of any subsequent iteration. Only those 'points' in the volume that successfully pass through all stages of the iteration are rendered as 'solid' (ie, part of the 'bulb'). The more iterations applied the more complicated the final surface (but the more complicated the calculation - so considerably longer render times).

The individual stages are linked together as follows : Note that one group node is required for each iteration of the calculation (the more iterations, the more complicated the resultant surface). The 'n' setting dictates the 'order' of the mandelbulb (in this case '3').

In order to render as a well defined volume you will need to multiply-up the result to generate a reasonable Density (eg, 100) and use this in a Volume material similar to how you would for smoke. You will also need to significantly decrease the Volume Sampling Step Size parameter in the Render properties from it's default of 0.1 to, say, 0.005 or lower (this defines the resolution of the volumetric) - this will produce a more detailed result but will significantly affect render times.

This can produce the following results : Blend file included (you'll need to install the add-on to activate the Dynamic Maths Nodes) Here is a further example - this time an 8th order mandelbulb (by setting 'n' to 8) with additional Iteration nodes in the chain to add detail (I used 16 iterations for this - ideally you'd use many more). This took approximately 3 hours to render on my system - it would fare a lot better on a system with GPU support (which I don't have). • Consider using atan2(y, x) – batFINGER Jun 5 '18 at 12:39
• @batFINGER I did try atan2 originally and the add-on does support it (and implements it using a series of maths nodes) but got different results. It takes so long to render that I just stuck with the formula from the original question but since the expressions can now be simply re-typed (in the dynamic maths node) it’s easy to try different calculations. Thanks for the edit. – Rich Sedman Jun 5 '18 at 13:13
• In same boat re no GPU. Did you check out link posted by Leander? very cool. Sug-Edit came up while I was posting comment, hope original editor got some rep for it, never too sure how all that works. – batFINGER Jun 5 '18 at 13:24
• @batFINGER Yes - I saw that - looks interesting. I think I might try tweaking tthe equations and running some long overnight renders! – Rich Sedman Jun 5 '18 at 17:15
• I followed your process, and it worked so well! Thank you so eternally for this; the only question I have left is how to colour it in different colours? – user62338 Sep 13 '18 at 19:08