Fractalforums

Fractal Software => Programming => Topic started by: kosalos on June 28, 2020, 08:48:18 AM

Title: Add radial symmetry to your 2D fractal
Post by: kosalos on June 28, 2020, 08:48:18 AM
alter the source coordinate according to a radial angle (0.01 ... Pi) for radial symmetry

Here's the entry point to an Apple Metal shader
--------------------------------------------------------

kernel void fractalShader
(
 texture2d<float, access::write> outTexture [[texture(0)]],
 constant Control &control  [[ buffer(0) ]],
 uint2 srcP [[thread_position_in_grid]])
{
    uint2 p = srcP;                                         // copy of pixel coordinate, altered during radial symmetry
   
    // apply radial symmetry? ---------
    if(control.radialAngle > 0.01) {                 // 0 = don't apply
        float centerX = control.xSize/2;            // size of texture in pixels
        float centerY = control.ySize/2;
        float dx = float(srcP.x - centerX);
        float dy = float(srcP.y - centerY);

        float angle = fabs(atan2(dy,dx));

        float dRatio = 0.01 + control.radialAngle;
        while(angle > dRatio) angle -= dRatio;
        if(angle > dRatio/2) angle = dRatio - angle;

        float dist = sqrt(dx * dx + dy * dy);

        p.x = uint(centerX + cos(angle) * dist);
        p.y = uint(centerY + sin(angle) * dist);
    }
   
    ....  rest of shader proceeds as usual
   
Title: Re: Add radial symmetry to your 2D fractal
Post by: Sabine62 on June 28, 2020, 09:15:17 AM
Very cool, Kosalos, symmetric polyfolding for 2D! :thumbs:

For Fragmentarium there's a 3D version in the code-snippets (one by Eiffie (ported by me) and a very elaborate one with lots of tweakability by mclarekin), if you're interested
Title: Re: Add radial symmetry to your 2D fractal
Post by: Sabine62 on June 28, 2020, 10:06:54 AM
Hm, I have just this minute got this if you just want it as pre-transform (Eiffie's code jumbled into something that seems to do the trick for 2D, not sure if it's correct, of course! ;) )

Code: [Select]
//based on Eiffie's _polyfoldsym 3D-transform

uniform bool PolyFold;checkbox[false]
uniform float PolyFoldOrder;slider[0,4,100]
uniform vec2 shiftXY;slider[(-2,-2),(0,0),(2,2)]
#define pi 3.14159

//before iteration:
        float poly=PolyFoldOrder;
poly+=0.000001; //no division by 0
if (PolyFold) {float psi = abs(mod(atan(z.x,z.y)+pi/poly,pi/(0.5*poly))-pi/poly);
z.xy=vec2(cos(psi),sin(psi))*length(z.xy);z.xy+=shiftXY;};

Edit: have tested some more and until now works well for julias