Fathauer Crystal
By: Gijs Bellaard

Description
The Fathauer Crystal is created by repeatedly placing half-sized cubes on the faces of all the cubes, starting with an unit cube.
GLSL Code
// the amount of iterations
const int ITERATIONS = 15;
// the scaling factor between iterations
const float SCALE = 2.0;
// fold normals
const vec3 N1 = normalize(vec3(1, -1, 0));
const vec3 N2 = normalize(vec3(1, 0, -1));
// distance to a unit cube
float distanceUnitCube(vec3 p)
{
vec3 d = abs(p) - 1.0;
return length(max(d, 0.0)) + min(max(d.x,max(d.y,d.z)), 0.0);
}
float distanceFathauerCrystal(vec3 p)
{
float dis = INFINITY;
float s = 1.0;
for(int i=0; i<ITERATIONS; i++)
{
// distance to a cube
dis = min(dis, distanceUnitCube(p) / s);
// fold everything to the positive x axis
p = abs(p);
p -= 2.0 * min(0.0, dot(p, N1)) * N1;
p -= 2.0 * min(0.0, dot(p ,N2)) * N2;
// scaling
p *= SCALE;
s *= SCALE;
// offset
p.x -= SCALE + 1.0;
}
return dis;
}