Daniel Gray

Thoughts, Notes, Ideas, Projects

Contact

GLSL 3D Fractals - Mandelbox

The Mandelbox is a fascinating 3D fractal discovered by Tom Lowe in 2010. It combines sphere inversion with box folding and scaling operations, creating intricate geometric patterns with both sharp edges and smooth curves. Unlike the Mandelbulb, the Mandelbox uses a different folding technique that produces more angular, architectural structures.

Interactive Demo

Move your mouse to rotate the camera and explore the Mandelbox. Scroll to adjust the scale parameter and see how it changes the fractal structure:

Mathematical Foundation

Box Folding

The Mandelbox uses a box folding operation that folds space around a cube:

vec3 boxFold(vec3 z) {
    for (int i = 0; i < 3; i++) {
        if (z[i] > 1.0) z[i] = 2.0 - z[i];
        else if (z[i] < -1.0) z[i] = -2.0 - z[i];
    }
    return z;
}

Sphere Inversion

After folding, the Mandelbox applies sphere inversion:

float sphereRadius = 1.0;
if (length(z) < sphereRadius) {
    z = z * (sphereRadius * sphereRadius) / dot(z, z);
}

Scaling and Iteration

The complete Mandelbox iteration combines folding, inversion, and scaling:

zn+1=scalesphereFold(boxFold(zn))+cz_{n+1} = \text{scale} \cdot \text{sphereFold}(\text{boxFold}(z_n)) + c

Where:

  • boxFold: Folds space around a cube
  • sphereFold: Inverts space inside a sphere
  • scale: Typically around 2.0, controls the fractal's detail level
  • c: The constant point being tested

Distance Estimation

The distance estimate for the Mandelbox uses the derivative of the iteration:

dznlog(zn)znd \approx \frac{|z_n| \cdot \log(|z_n|)}{|z'_n|}

Where znz'_n is the derivative accumulated during iteration.

Key Parameters

Scale Parameter

The scale parameter controls the fractal's detail:

  • scale < 2.0: Creates more compact, detailed structures
  • scale = 2.0: Classic Mandelbox
  • scale > 2.0: More open, less detailed structures

Fixed Radius

The fixed radius for sphere inversion affects the smoothness:

  • Smaller radius: More angular, box-like structures
  • Larger radius: Smoother, more organic curves

Min Radius

The minimum radius prevents division by zero and controls the inversion strength.

Visual Characteristics

The Mandelbox exhibits:

  • Geometric precision: Sharp edges and corners from box folding
  • Organic curves: Smooth transitions from sphere inversion
  • Infinite detail: Self-similar structures at all scales
  • Architectural beauty: Reminiscent of impossible geometry

Implementation Details

The GLSL implementation uses:

  • Ray marching with distance estimation
  • Efficient iteration with early termination
  • Normal calculation using finite differences
  • Adaptive step sizes for performance

References

Related Articles

Related Content

GLSL 3D Fractals - Mandelbulb

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 wi...

GLSL 3D Fractals Series

GLSL 3D Fractals Series 3D fractals represent some of the most visually stunning and mathematically fascinating objects in computer graphics. This series explores how to render these infinite structur...