Welcome to Fractal Forums

Fractal Software => Programming => Topic started by: tryptophan on April 12, 2013, 05:48:46 AM




Title: Repeat an object finitely
Post by: tryptophan on April 12, 2013, 05:48:46 AM
I'm trying to repeat an object just a certain number of times and transform it arbitrarily. I know of a simple way to do it by just repeating it's calculation and using the min function but then I would need to cycle through its loop every time it repeated the object. For example:

Quote
float DE(vec3 z)
{
   float r;
   z += Position;

   if (Tile.w == 1) z = abs(-Tile.zyx-mod(z,2.0* -Tile.zyx));
   else if (Tile.w == 2) z = abs(2.0*Tile.zyx-mod(z-Tile.zyx,Tile.zyx*4.0))-Tile.zyx;

   z = z * fullRotate;
         
   // Iterate to compute the distance estimator.
   int n = 0;
   while (n < Iterations) {
      z *= fracRotation1;
      
      if (z.x+z.y<0.0) z.xy = -z.yx;
      if (z.x-z.y<0.0) z.xy = z.yx;
      if (z.x-z.z<0.0) z.xz = z.zx;
      
      z = ((z+Julia*.25)*Scale - offset*(Scale-1.0)) * (Fold.xyz * .2 + 1);
      z *= fracRotation2;
      
      r = dot(z, z);
        if (n< ColorIterations)  orbitTrap = min(orbitTrap, abs(vec4(z,r)));
          n++;
   }
   orbitTrap*=ColorScale+ColorOffset;
   return length(z)  * pow(Scale, -float(n));
}

if I replace the return statement with : return min(length(z),length(z+offset) * pow(Scale, -float(n));
I do not get the desired result (a second pyramid offset from the first), in fact it seems to create a small offset within the iteration. But then I can't find a way to repeat the pyramid before the iteration, all the info I've found on mixing DEs works on the float output not on the position input. As I said earlier I'm sure if I pack the DE into a function and call it more than once then use the min operator it will work but I think this will increase the render time much more than finding a way to repeat its output?

Any suggestions or ideas?

Also if someone has a better method for a Sierpinski pyramid I'd be stoked to hear what you have to say. The above code is just the modified Octahedron code from Fragmentarium and I seem to have a problem with it not cutting holes out of the bottom. I've done some reading on folding on the Syntopia blog but I'm still not 100% there yet.

thanks
Keith


Title: Re: Repeat an object finitely
Post by: eiffie on April 12, 2013, 05:46:14 PM
You have to replicate z before the fractal iterations - as you found out.
You already have the tiling code to replicate infinitely - others are...
abs = 2 per dimension
clamp = 3 per dimension
If you want some multiple like 6 then do both.
For larger but finite numbers you can use tiling and then "throw out" tiles you don't want.
Check out how Inigo Quilez did the piano keys in one of his latest shadertoy scripts.


Title: Re: Repeat an object finitely
Post by: Syntopia on April 12, 2013, 07:09:24 PM
Also if someone has a better method for a Sierpinski pyramid I'd be stoked to hear what you have to say. The above code is just the modified Octahedron code from Fragmentarium and I seem to have a problem with it not cutting holes out of the bottom. I've done some reading on folding on the Syntopia blog but I'm still not 100% there yet.

Isn't a Sierpinski pyramid the same as the Tetrahedron KIFS? It should be included with Fragmentarium.


Title: Re: Repeat an object finitely
Post by: tryptophan on April 15, 2013, 01:57:11 AM
Thanks guys for the tips. I tried your suggestions Effie and they both worked.
Quote
Isn't a Sierpinski pyramid the same as the Tetrahedron KIFS? It should be included with Fragmentarium.

Thanks Syntopia actually they are different in the sense that the Tetrahedron has three sides while the pyramid I was thinking of has four sides and a square bottom (I guess I forgot to mention that). The version I'm using for now seems to be working alright.

Thanks for the help.