GLSL 3D Fractals - Mandelbulb
The Mandelbulb is the 3D extension of the classic Mandelbrot set, discovered by Daniel White and Paul Nylander in 2009. It creates stunning organic, bulbous structures with infinite detail, rendered in real-time using ray marching and distance estimation.
Interactive Demo
Move your mouse to rotate the camera and explore the Mandelbulb. Scroll to adjust the power parameter and see how it changes the fractal structure:
Mathematical Foundation
The Mandelbulb extends the 2D Mandelbrot iteration to 3D using spherical coordinates.
2D Mandelbrot Set
The classic 2D Mandelbrot set uses complex numbers:
Where and are complex numbers.
3D Extension: Spherical Coordinates
For 3D, we use spherical coordinates to define a power operation:
vec3 powN(vec3 z, float n) {
float r = length(z);
float theta = acos(z.z / r); // Polar angle
float phi = atan(z.y, z.x); // Azimuthal angle
float rn = pow(r, n);
float ntheta = theta * n;
float nphi = phi * n;
return rn * vec3(
sin(ntheta) * cos(nphi),
sin(ntheta) * sin(nphi),
cos(ntheta)
);
}
Mandelbulb Iteration
Where is the initial position in 3D space, and is typically 8.
Distance Estimation
For efficient ray marching, we use distance estimation:
float mandelbulbDE(vec3 pos, float power) {
vec3 z = pos;
float dr = 1.0; // Derivative
for (int i = 0; i < iterations; i++) {
r = length(z);
if (r > 4.0) break;
// Update derivative
dr = pow(r, power - 1.0) * power * dr + 1.0;
// Iterate
z = powN(z, power) + pos;
}
// Distance estimate
return 0.5 * log(r) * r / dr;
}
The distance estimate formula:
Where $z'$ is the derivative of the iteration.
Ray Marching
We use the distance estimate to efficiently march rays:
float t = 0.0;
for (int i = 0; i < maxSteps; i++) {
vec3 p = ro + rd * t;
float d = mandelbulbDE(p, power);
if (d < epsilon) {
// Hit surface - calculate lighting
return shade(p);
}
t += d * 0.8; // Safety factor
}
Visual Characteristics
- Power = 2: Creates a sphere (degenerate case)
- Power = 8: Classic Mandelbulb with organic, bulbous forms
- Power > 8: More angular, geometric structures
- Power < 8: Softer, more rounded forms
Optimization Techniques
- Bounding sphere: Skip empty space quickly
- Early termination: Stop when
- Adaptive iterations: Fewer iterations for distant objects
- Safety factor: Use to avoid overshooting
Applications
- Digital art: Stunning visualizations for galleries
- Game environments: Procedural alien landscapes
- Scientific visualization: Exploring mathematical structures
- Educational: Teaching complex iteration and ray marching
References
- "The Mandelbulb: First 'True' 3D Image of the Mandelbrot Set?" by Daniel White and Paul Nylander
- Mandelbulb.com - Gallery and resources
- Inigo Quilez - Distance Estimation
Related Articles
- GLSL 3D Fractals - Quaternion Julia Sets - Related 4D fractals
- GLSL 3D Fractals Series Index - Return to series index