As 3D fractals are more computation heavy in Houdini, most of my experiments are done in low-mid resolution, due to hardware limitations.
The function for the Mandelbulb iterations is structured very similar to the Mandelbrot function. Only that we here set the density of the volume instead of a color and we have to do a few more lines of calculations for the additional dimension.
Mandelbulb Code
//--- Functions ---
function int Mandelbulb(float x1, y1, z1; int maxIter)
{
float n=maxIter;
float x0 = x1;
float y0 = y1;
float z0 = z1;
for(int i=0; i<maxIter; i++)
{
float r = sqrt(x0*x0 + y0*y0 + z0*z0);
float theta = atan2(sqrt(x0*x0 + y0*y0), z0);
float phi = atan2(y0,x0);
float x2 = pow(r,n) * sin(theta*n) * cos(phi*n) + x1;
float y2 = pow(r,n) * sin(theta*n) * sin(phi*n) + y1;
float z2 = pow(r,n) * cos(theta*n) + z1;
if(x2*x2 + y2*y2 + z2*z2 > maxIter) return(i);
x0 = x2;
y0 = y2;
z0 = z2;
}
return(maxIter);
}
//--- Main ---
int maxiter = 8;
@density = 1.0;
int result = Mandelbulb(@P.x, @P.y, @P.z, maxiter);
if(result < maxiter)
{
@density = 0.0;
}
Mandelbulb variants