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:
- Starting with a regular tetrahedron
- Dividing it into 4 smaller tetrahedra
- Removing the central inverted tetrahedron
- 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:
Where:
- are the centers of the 4 sub-tetrahedra
- (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:
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
- "Fractals: Form, Chance, and Dimension" by Benoit Mandelbrot
- Inigo Quilez - Distance Functions
- Sierpinski Triangle - 2D precursor
Related Articles
- Menger Sponge - Another geometric fractal
- Distance Estimation Methods - Techniques for efficient rendering
- GLSL 3D Fractals Series