Daniel Gray

Thoughts, Notes, Ideas, Projects

Contact

GLSL 3D Fractals - Sierpinski Tetrahedron

The Sierpinski Tetrahedron is the 3D generalization of the classic Sierpinski triangle. It's created by recursively subdividing a regular tetrahedron, removing the central inverted tetrahedron at each iteration. The result is a fractal with fascinating self-similarity and a Hausdorff dimension of approximately 2.0.

Interactive Demo

Move your mouse to rotate the camera and explore the infinite detail. Scroll to adjust the iteration count and see how the structure becomes more complex:

Mathematical Foundation

Tetrahedral Subdivision

The Sierpinski Tetrahedron is constructed by:

  1. Starting with a regular tetrahedron
  2. Dividing it into 4 smaller tetrahedra
  3. Removing the central inverted tetrahedron
  4. Repeating the process for each remaining tetrahedron

Distance Function

The distance to a tetrahedron can be computed using the distance to its four faces:

float sdTetrahedron(vec3 p, vec3 a, vec3 b, vec3 c, vec3 d) {
    vec3 ba = b - a;
    vec3 ca = c - a;
    vec3 da = d - a;
    vec3 pa = p - a;
    
    float dotba = dot(ba, ba);
    float dotca = dot(ca, ca);
    float dotda = dot(da, da);
    float dotpa = dot(pa, pa);
    
    // Compute distances to faces
    vec3 n1 = cross(ba, ca);
    vec3 n2 = cross(ca, da);
    vec3 n3 = cross(da, ba);
    vec3 n4 = cross(ba - da, ca - da);
    
    float d1 = abs(dot(n1, pa)) / length(n1);
    float d2 = abs(dot(n2, pa)) / length(n2);
    float d3 = abs(dot(n3, pa)) / length(n3);
    float d4 = abs(dot(n4, p - d)) / length(n4);
    
    return max(max(d1, d2), max(d3, d4));
}

Recursive Construction

For the Sierpinski Tetrahedron, we use an iterative approach:

d(p)=mini{d(scale(pci))scale}d(\mathbf{p}) = \min_i \left\{ d(\text{scale}(\mathbf{p} - \mathbf{c}_i)) \cdot \text{scale} \right\}

Where:

  • ci\mathbf{c}_i are the centers of the 4 sub-tetrahedra
  • scale=2.0\text{scale} = 2.0 (each iteration halves the size)
  • The minimum finds the closest sub-tetrahedron

Iterative Distance Estimation

The GLSL implementation uses an iterative approach:

float sierpinskiTetrahedronDE(vec3 pos, int iterations) {
    vec3 p = pos;
    float scale = 1.0;
    
    for (int i = 0; i < iterations; i++) {
        // Fold into first octant
        p = abs(p);
        
        // Scale and translate
        p *= 2.0;
        scale *= 2.0;
        
        // Remove central tetrahedron
        if (p.x + p.y + p.z > 2.0) {
            p.xy = vec2(2.0) - p.xy;
            p.xz = vec2(2.0) - p.xz;
        }
        
        p -= 1.0;
    }
    
    // Distance to final tetrahedron
    return sdTetrahedron(p, ...) / scale;
}

Key Properties

Hausdorff Dimension

The Sierpinski Tetrahedron has a Hausdorff dimension of:

D=log(4)log(2)=2.0D = \frac{\log(4)}{\log(2)} = 2.0

This means it's a 2D surface embedded in 3D space, similar to the Sierpinski triangle.

Self-Similarity

At every scale, the fractal contains 4 copies of itself, each half the size. This creates infinite detail and perfect self-similarity.

Volume

As iterations approach infinity, the volume approaches zero, while the surface area approaches infinity.

Visual Characteristics

The Sierpinski Tetrahedron exhibits:

  • Geometric precision: Sharp edges and triangular faces
  • Infinite detail: Self-similar structures at all scales
  • Symmetrical beauty: Perfect tetrahedral symmetry
  • Architectural elegance: Reminiscent of impossible geometry

Implementation Details

The GLSL implementation uses:

  • Ray marching with distance estimation
  • Iterative folding for efficient computation
  • Normal calculation using finite differences
  • Adaptive step sizes for performance

References

Related Articles

Related Content

GLSL 3D Fractals - Menger Sponge

GLSL 3D Fractals - Menger Sponge The Menger Sponge is the 3D generalization of the Sierpinski carpet, discovered by Karl Menger in 1926. It's a fascinating geometric fractal with paradoxical propertie...

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