Inside the Mandelbulb…from outside !

 

Let’s flip a fractal inside-out like a sock - Octane render - osl by matteo scappin

If you're a fan of mind-bending, infinitely detailed mathematical shapes then you're probably familiar with this monster, the Mandelbulb.
This cool fractal is a three-dimensional version of the famous Mandelbrot set, and it's just as fascinating to explore even if it’s not as detailed as his father.
With its complex structure and mesmerizing patterns, the Mandelbulb is a must-see for anyone who loves math and art. So why not take a trip into this virtual world and see what treasures are hidden inside ?

We’re going to explore some of it’s features in Octane render 2021 and Vectron which is able to render OSL shaders:

...output _sdf c = _SDFDEF){
	vector pos = P;
	vector z = P;
	float dr, r = 1.0;
	for (int i = 0; i < Iterations ; i++) {
		r = length(z);
		if (r>Bailout) break;
		// convert to polar coordinates
		float theta = acos(z[2]/r);
		float phi = atan2(z[1],z[0]);
		dr =  pow( r, Power-1.0)*Power*dr + 1.0;
		// scale and rotate the point
		float zr = pow( r,Power);
		theta = theta*Power;
		phi = phi*Power;
		// convert back to cartesian coordinates
		z = zr*vector(sin(theta)*cos(phi),sin(phi)*sin(theta),cos(theta));
		z+=pos;
	}
	c.dist = 0.5*log(r)*r/dr;
}

Mandelbulb script from Octane Vectron OSL folder. Derivated from Daniel White’s original code I guess.

Mandelbulb render in Octane and it's OSL Vectron code

Mandelbulb power 8 render in Octane and it's OSL Vectron code

As a three-dimensional analogue of the famous Mandelbrot set, the Mandelbulb is a complex 3D mathematical object that is created using a combination of algebraic operations and recursive algorithms and it has an infinitely detailed structure that is constantly evolving and shifting.
The inside of a Mandelbulb is a fascinating and mysterious place, filled with intricate shapes and organic looking patterns.
By turning the Mandelbulb inside out (like a sock), you can see the fractal from a completely new perspective, uncovering hidden details and patterns that may not have been visible before. This process involves using mathematical techniques to manipulate the structure of the Mandelbulb and flip the space with a spherical inversion before calculating the Fractal.
The resulting shape may be unrecognizable at first, but with careful exploration and study, you may be able to uncover new features and insights about the Mandelbulb.
This process can be heavy to render and explore since the distance estimation is not designed for the inside out version of it, but with some tweaks of the code we are able to render it correctly.

Before flipping the Mandelbulb inside out with a sphere inversion transformation, we need to add the famous Julia mode to the code os we can have more control over the Bulb shape.
To do so we just need to replace the “pos” vector with “Julia“ and assign 3 declared float parameters to the vector(JuliaX,JuliaY,JuliaZ).

//Declare the Julia vector before entering the for loop
vector Julia = vector(JuliaX,JuliaY,JuliaZ);
//..vector z = P;..etc
//Add Julia to z vector (instead of vector pos) 
z+=Julia;

Mandelbulb animated with Mobius inversion pre-transformation (a lil different from Sphere Inversion)

With Julia mode now connected in the soul of the Mandelbulb, you can explore and experiment with different Julia parameters to find unique and interesting shapes. In my case, I'm on the hunt for holes or voids within the structure of the Mandelbulb, since once flipped inside out, holes will filled with surfaces.

Here you can see that my Octane license expires in 4 days.

Now that we have all the necessary tools in place, it's time to transform the Mandelbulb by flipping it inside out using a Sphere Inversion transformation. This pre-transformation will be applied before we calculate the fractaland we can now uncover hidden patterns and features that would not be visible using other methods. It's an exciting opportunity to explore the Mandelbulb in a whole new light.
To do that, we need to add the custom SphereInversion( ) function before the “shader OslGeometry()“ and then apply the transformation to our main Position vector Z just after the declaration of it.
Now that we have inverted the Fractal, we need to invert the normals to properly render the image. This can be done by replacing the RayStepMultiplier (0.5) value with a smaller negative number, -0.1 should work great . This will increase the render time and improve the precision of the algorithm, allowing us to see the Fractal in greater detail and accuracy.

Here’s the final code :

-
#include "octane-oslintrin.h"
void SphereInversion( output vector z )//---------------------------------Sphere inversion function
{
	float Reciprocal = 1 / (z.x * z.x + z.y * z.y + z.z * z.z);
	Reciprocal = 1 / (z.x*z.x + z.y*z.y + z.z*z.z);
	z.x = P[0] * Reciprocal;
	z.y = P[1] * Reciprocal;
	z.z = P[2] * Reciprocal;
}
shader OslGeometry(
	int Iterations = 10,
	float Power = 2.0,
	float Bailout = 20,
	float JuliaX = 0[[float min=-2, float max=2]],//-------------------Add Julia XYZ parameters as float
	float JuliaY = 0[[float min=-2, float max=2]],
	float JuliaZ = 0[[float min=-2, float max=2]],
    output _sdf c = _SDFDEF)
{
	vector z = P;
	SphereInversion(z);//----------------------------------------------Apply the inversion
	vector Julia = vector(JuliaX,JuliaY,JuliaZ);//---------------------Assign Julia parameters to vector
	float dr = 1.0;
	float r = 0.0;
	for (int i = 0; i < Iterations ; i++) {
		r = length(z);
		if (r>Bailout) break;
		float theta = acos(z[2]/r);
		float phi = atan2(z[1],z[0]);
		dr =  pow( r, Power-1.0)*Power*dr + 1.0;
		float zr = pow( r,Power);
		theta = theta*Power;
		phi = phi*Power;
		z = zr*vector(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta));
		z+=Julia;
	}
	c.dist = -0.1*(log(r)*r/dr);//-------------------------------------Negate and decrease Raystep Multipier
}

The final result

Rendered with octane using the code provided above.
The scene is pretty simple, just a camera and a Daylight environment. For the fractal PBR material I’m using a Subsurface Scattering Random walk node to get some nice colors based on the Bulb thickness.
Here I’ve looked for some nice spirals by tweaking the Julia XYZ with the following values : Julia X = 0.166791 Julia Y = 0.651987 Julia Z = 0.07568 (Could be from Bill Snowzell)

Few images of the Inverted Mandelbulb using different softwares like Mandelbulb 3D, Houdini and Octane render.

Explorations from other artists

Few images of the Inside/flipped Mandelbulb using Mandelbulb 3D by artists Bill Snowzell and Lee Oliver.
If you want to go even deeper on the subject, check out this post from Daniel White (2009) about the the first inside render of the fractal.
To explore the Bulb in Mandelbulb 3D, user Dark Beam did a really detailed guide on Deviantart.

Explore and create fractals can be incredibly rewarding, providing a unique and fascinating view of this complex mathematical object. It’s good fun!
If you want to explore them you can download Mandelbulb 3D software :)