1/**
2 * Mandelbulber v2, a 3D fractal generator  _%}}i*<.        ____                _______
3 * Copyright (C) 2020 Mandelbulber Team   _>]|=||i=i<,     / __ \___  ___ ___  / ___/ /
4 *                                        \><||i|=>>%)    / /_/ / _ \/ -_) _ \/ /__/ /__
5 * This file is part of Mandelbulber.     )<=i=]=|=i<>    \____/ .__/\__/_//_/\___/____/
6 * The project is licensed under GPLv3,   -<>>=|><|||`        /_/
7 * see also COPYING file in this folder.    ~+{i%+++
8 *
9 * Msltoe Donut formula
10 * @reference
11 * http://www.fractalforums.com/new-theories-and-research/
12 * low-hanging-dessert-an-escape-time-donut-fractal/msg90171/#msg90171
13
14 * This file has been autogenerated by tools/populateUiInformation.php
15 * from the file "fractal_msltoe_donut.cpp" in the folder formula/definition
16 * D O    N O T    E D I T    T H I S    F I L E !
17 */
18
19REAL4 MsltoeDonutIteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
20{
21	REAL radius2 = fractal->donut.ringThickness;
22	REAL nSect = M_PI_2x_F / fractal->donut.number;
23	REAL fact = fractal->donut.factor;
24
25	REAL R = native_sqrt(z.x * z.x + z.y * z.y);
26	REAL R2 = fractal->donut.ringRadius - R;
27	REAL t = R2 * R2 + z.z * z.z - radius2 * radius2;
28
29	REAL theta = atan2(z.y, z.x);
30	REAL theta2 = nSect * round(theta / nSect);
31
32	if (t > 0.03f)
33	{
34		REAL c1 = native_cos(theta2);
35		REAL s1 = native_sin(theta2);
36
37		REAL x1 = c1 * z.x + s1 * z.y;
38		REAL y1 = -s1 * z.x + c1 * z.y;
39		REAL z1 = z.z;
40
41		x1 = x1 - fractal->donut.ringRadius;
42
43		z.x = fact * x1;
44		z.y = fact * z1;
45		z.z = fact * y1;
46	}
47	else
48	{
49		z /= t;
50	}
51	aux->color += theta2;
52	return z;
53}