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 * MsltoeToroidal
10 * @reference http://www.fractalforums.com/theory/toroidal-coordinates/msg9428/
11
12 * This file has been autogenerated by tools/populateUiInformation.php
13 * from the file "fractal_msltoe_toroidal.cpp" in the folder formula/definition
14 * D O    N O T    E D I T    T H I S    F I L E !
15 */
16
17REAL4 MsltoeToroidalIteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
18{
19	if (fractal->transformCommon.functionEnabledFalse
20			&& aux->i >= fractal->transformCommon.startIterationsD
21			&& aux->i < fractal->transformCommon.stopIterationsD1) // pre-scale
22	{
23		z *= fractal->transformCommon.scale3D111;
24		aux->DE *= length(z) / aux->r;
25	}
26
27	// Toroidal bulb
28	REAL r1 = fractal->transformCommon.minR05; // default 0.5f
29	REAL theta = atan2(z.y, z.x);
30	REAL x1 = r1 * native_cos(theta);
31	REAL y1 = r1 * native_sin(theta);
32	aux->r = (z.x - x1) * (z.x - x1) + (z.y - y1) * (z.y - y1) + z.z * z.z; //+ 1e-030f
33	REAL phi = asin(z.z / native_sqrt(aux->r));
34	REAL rp = native_powr(aux->r, fractal->transformCommon.pwr4); // default 4.0f
35
36	phi *= fractal->transformCommon.pwr8; // default 8
37	theta *= fractal->bulb.power;					// default 9 gives 8 symmetry
38
39	// convert back to cartesian coordinates
40	REAL r1RpCosPhi = r1 + rp * native_cos(phi);
41	z.x = r1RpCosPhi * native_cos(theta);
42	z.y = r1RpCosPhi * native_sin(theta);
43	z.z = -rp * native_sin(phi);
44
45	// DEcalc
46	if (!fractal->analyticDE.enabledFalse)
47	{
48		aux->DE = rp * aux->DE * (fractal->transformCommon.pwr4 + 1.0f) + 1.0f;
49	}
50	else
51	{
52		aux->DE = rp * aux->DE * (fractal->transformCommon.pwr4 + fractal->analyticDE.offset2)
53								* fractal->analyticDE.scale1
54							+ fractal->analyticDE.offset1;
55	}
56
57	if (fractal->transformCommon.functionEnabledAxFalse) // spherical offset
58	{
59		REAL lengthTempZ = -length(z);
60		// if (lengthTempZ > -1e-21f) lengthTempZ = -1e-21f;   //  z is neg.)
61		z *= 1.0f + fractal->transformCommon.offset / lengthTempZ;
62		z *= fractal->transformCommon.scale;
63		aux->DE = aux->DE * fabs(fractal->transformCommon.scale) + 1.0f;
64	}
65	// then add Cpixel constant vector
66	return z;
67}