Fractalforums

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

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
--------------------------------------------------------

(
texture2d<float, access::write> outTexture [[texture(0)]],
constant Control &control  [[ buffer(0) ]],
{
uint2 p = srcP;                                         // copy of pixel coordinate, altered during 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

//based on Eiffie's _polyfoldsym 3D-transformuniform 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;};