I've been by using some of the tools on the Iñigo Quílez's site incorportating them into some of the fractal formulas. I've successfully been able to replicate a Kaleidoscopic IFS octahedral to infinti along all three axis using a simple modulus equation. I'm having a problem though when I tried to do rotation or transformations within the iteration where the field no longer seems to be a real Distance Field (I think I am using the right terminology). Is there a way to keep the distance function true with this approach? Below is my code and some images if anyone would like to take a look. Please don't mind some of the variable names I'm using a bank of predefined sliders/uniforms for some of the variables.
float octahedron( vec3 z,mat3 rot1, vec3 offset, mat3 rot2, float scale, int iter, int colIter, float cScale, float cOffset)
{
float r;
// Iterate to compute the distance estimator.
int n = 0;
while (n < iter) {
//z *= rot1;
if (z.x+z.y<0.0) z.xy = -z.yx;
if (z.x+z.z<0.0) z.xz = -z.zx;
if (z.x-z.y<0.0) z.xy = z.yx;
if (z.x-z.z<0.0) z.xz = z.zx;
z = (z*scale - offset*(scale-1.0));
//z *= rot2;
r = dot(z, z);
if (n< colIter) orbitTrap = min(orbitTrap, abs(vec4(z,r)));
n++;
}
orbitTrap*= cScale+ cOffset;
return (length(z) ) * pow(scale, -float(n));
}
void init()
{
rot2 = rotationMatrix3(normalize(Rotate2.xyz),Rotate2.w);
rot1 = rotationMatrix3(normalize(Rotate1.xyz),Rotate1.w);
fullRotate = rotationMatrixXYZ(Rotate);
}
float shape(vec3 p)
{
if (object1 == 0) return sdSphere(p,Offset.x*.05);
else if (object1 == 1) return sdBox(p,Offset*.05);
else if (object1 == 2) return udRoundBox( p, Offset*.05, Scale*.01);
else if (object1 == 4) return octahedron( p, rot1, Offset , rot2, Scale, Iterations,
ColorIterations, ColorScale, ColorOffset);
else if (object1 == 5) return sdCross(p, Offset.xyz*.05);
else if (object1 == 6) return sdCross2(p, Offset.xyz*.05, Scale*.01);
else if (object1 == 7) return sdCross3(p, Offset.xyz*.05);
else return sdSphere(p,Offset.x*.1);
}
float opRep( vec3 p, vec3 c)
{
vec3 p2 = p;
if (Fold.w == 0) p2 =p;
else if (Fold.w == 1)
{
p2.x = mod(p2.x,c.x)-.5*c.x;
}
else if (Fold.w == 2)
{
p2.xz = mod(p2.xz,c.xz)-.5*c.xz;
}
else if (Fold.w == 3)
{
p2.xy = mod(p2.xy,c.xy)-.5*c.xy;
}
else if (Fold.w == 4)
{
p2.zy = mod(p2.zy,c.zy)-.5*c.zy;
}
else if (Fold.w == 5)
{
p2 = mod(p2,c)-.5*c;
}
else p2 = p;
return shape(p2);
}
float DE(vec3 p)
{
p += Position;
p *= fullRotate;
return opRep(p,Fold.xyz*.1);
}