Sorry for bumping this old thread. I'm working on aperiodic tilings thanks to
tomkh's thread and just think it's related to this dicussion. My objective is to find DE estimate for aperiodic 3D tilings. On the way I remembred this thread and am having answers to a some questions:
Here are the DE for twinbee's Menger sponge and Buddhi's sphere sponge:
//Derived from twinbee's algorithm
MengerSponge3(x, y, z) {//by recursively digging a box
x=x*0.5+0.5;y=y*0.5+0.5;z=z*0.5+0.5;//center it by changing position and scale
xx=abs(x-0.5)-0.5;yy=abs(y-0.5)-0.5;zz=abs(z-0.5)-0.5;
d1=max(xx,max(yy,zz));//distance to the box
d=d1;//current computed distance
p=1;
for(m=1; m<MI ; m++) {
xa = 3*x*p % 3;
ya = 3*y*p % 3;
za = 3*z*p % 3;
p*=3;
//we can also translate/rotate (xa,ya,za) without affecting the DE estimate
xx=0.5-abs(xa-1.5);yy=0.5-abs(ya-1.5);zz=0.5-abs(za-1.5);
d1=min(max(xx,zz),min(max(xx,yy),max(yy,zz)))/p;//distance inside the 3 axis aligned square tubes
d=max(d,d1);//intersection
}
return d*2; //the distance estimate. The "*2" is because of the scaling we did at the begining of the function
}
//derived from Buddhi's algorithm
SphereSponge3(x, y, z) {//by recursively digging space
//Same as for the Menger sponge but with spheres
x+=1;y+=1;z+=1;
intrad=param1;
scl=3;mod=4;
a=x;b=y;c=z;k=2;
d=-100;
for (L = 0; L < MI ; L++)
{
xx = a * k % mod - 0.5*mod;
yy = b * k % mod - 0.5*mod;
zz = c * k % mod - 0.5*mod;
r2=xx*xx + yy*yy + zz*zz;
d1=(intrad-sqrt(r2))/k;//distance to the edge of the sphere (positive inside)
d=max(d,d1);//intersect
k *= scl;
}
return d;// distance estimate
}
(needs some optimizations

but it is already quite fast

)
It's possible to use the same technique to other figures (fractals and tilings).
Fantastic idea and render!!! I think it is impossible to render this with DE :-)
It's actually possible (and well known): the intersection is obtained by taking the maximum DE of the two objects. That's what I am using in the codes above. union can also be obtained by taking the minimum DE instead.
BTW: There is another well known trick In distance fied rendering: Blending. Just take a linear (or higher order) interpolation of the DE of the two objects.