Implementing Menger Sponge - 45 degree rot of xyplane.
So no cos sin trig
based on code by Trafassel// Gestaltlupe 3.4
http://www.fractalforums.com/ifs-iterated-function-systems/menger-sponge-45-rotation/msg97840/#new// Menger Sponge Tree
public override bool GetBool(double x,double y,double z)
{
double sin45 = Math.Sqrt(0.5);
double scale = 1.81;
double offsetX = 1.15;
double offsetY = 0.932;
double offsetZ = 1.01;
for (int n=1;n<100;n++)
{
x = Math.Abs(x);
y = Math.Abs(y);
z = Math.Abs(z);
// Bailout Condition:
if (x>2) return false;
if (y>2) return false;
if (z>2) return false;
if (x<y) { double a=x; x=y; y=a; }
if (x<z) { double a=x; x=z; z=a; }
if (y<z) { double a=y; y=z; z=a; }
x = scale*x - offsetX*(scale-1);
y = scale*y - offsetY*(scale-1);
z = scale*z - offsetZ*(scale-1);
// Rotate x,y plane by 45 degree:
double xtemp = sin45 * ( x - y );
y = sin45 * ( y + x );
x = xtemp;
}
return true;
}
//......................................
What is interesting us that Trafassel produces non-DE rendered fractals.
They are not a distance estimation approximation of a fractal?
But I will need DE to render with Mandlebulber.
45 degree rotation is the only rotation that "works" with some linear fractals,
so it is a useful transform to include in an exploring frag.
I will need this constant:
const float sin45 = 0.707106781186547524; // not sure on decimal places
A standard menger sponge is made up of four parts
a) The abs(), I will include a pre-add as well:
z = abs(z + PreAddM);
b) Conditional swizzle
// Conditional swizzle
if (z.x < z.y ) z.xy = z.yx;
if (z.x < z.z ) z.xz = z.zx;
if (z.y < z.z ) z.yz = z.zy;
c) Scale
z *= ScaleM;
Dd *= ScaleM; // * Tweak
d) Offset
z.x -= OffsetM.x;
z.y -= OffsetM.y;
// "true" reverts to standard Menger Sponge
if (EnableConditionalZ)
{
if (z.z > 1.0) z.z -= OffsetM.z;
}
else
{
z.z -= OffsetM.z;
}
"If EnableConditionalZ" is just a check box to make a standard menger with conditional offset,
so I can check that the code is correct. So 'else" is non-conditional offset mode.
(this can be replicated in MandelbuberV2.07 Menger_Middle_Mod UI)
I have modified "offsetX*(scale-1) to OffsetM.x
Then I added // Rotate x,y plane by 45 degree:
if ( i >= StartR45 && i < StopR45)
{
float xtemp = sin45 * ( z.x - z.y );
z.y = sin45 * ( z.y + z.x );
z.x = xtemp;
}
I include start & stop parameters to control the complexity of the rotations.
Later I will add some other transforms to the mix.
BTW still have an old rot left in my .frag code because if I delete it, I crash???