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 * Adds Cpixel constant to z vector, scator algebra
10 * based on Manuel's math
11 * @reference
12 * https://luz.izt.uam.mx/drupal/en/fractals/hun
13 * @author Manuel Fernandez-Guasti
14
15 * This file has been autogenerated by tools/populateUiInformation.php
16 * from the file "fractal_transf_add_cpixel_scator.cpp" in the folder formula/definition
17 * D O    N O T    E D I T    T H I S    F I L E !
18 */
19
20REAL4 TransfAddCpixelScatorIteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
21{
22	REAL4 oldZ = z;
23	REAL4 tempC = aux->const_c;
24	if (fractal->transformCommon.functionEnabledSwFalse)
25	{
26		REAL temp = tempC.x;
27		tempC.x = tempC.z;
28		tempC.z = temp;
29	}
30
31	REAL4 cc = tempC * tempC;
32	REAL4 newC = tempC;
33	REAL limitA = fractal->transformCommon.scale0;
34
35	if (fractal->transformCommon.functionEnabledRFalse)
36	{
37		cc = fabs(tempC);
38	}
39
40	// scator algebra
41	if (cc.x < limitA)
42	{
43		REAL temp = 1.0f / cc.x - 1.0f;
44		cc.x = temp;
45	}
46
47	if (!fractal->transformCommon.functionEnabledFalse)
48	{																	// real
49		newC.x += (cc.y * cc.z) / cc.x; // all pos
50		newC.y *= (1.0f + cc.z / cc.x);
51		newC.z *= (1.0f + cc.y / cc.x);
52		newC *= fractal->transformCommon.constantMultiplier111;
53		if (fractal->transformCommon.functionEnabledSwFalse)
54		{
55			REAL temp = newC.x;
56			newC.x = newC.z;
57			newC.z = temp;
58		}
59
60		if (!fractal->transformCommon.functionEnabledSFalse)
61		{
62			z += newC;
63		}
64		else
65		{
66			z.x += sign(z.x) * newC.x;
67			z.y += sign(z.y) * newC.y;
68			z.z += sign(z.z) * newC.z;
69		}
70	}
71	else
72	{																	// imaginary
73		newC.x += (cc.y * cc.z) / cc.x; // pos
74		newC.y *= (1.0f - cc.z / cc.x); // pos  neg
75		newC.z *= (1.0f - cc.y / cc.x); // pos  neg
76		newC *= fractal->transformCommon.constantMultiplier111;
77		if (fractal->transformCommon.functionEnabledy) newC.y = fabs(newC.y);
78		if (fractal->transformCommon.functionEnabledz) newC.z = fabs(newC.z);
79
80		if (fractal->transformCommon.functionEnabledSwFalse)
81		{
82			REAL temp = newC.x;
83			newC.x = newC.z;
84			newC.z = temp;
85		}
86
87		// add Cpixel
88		if (!fractal->transformCommon.functionEnabledSFalse)
89		{
90			z += newC;
91		}
92		else
93		{
94			z.x += sign(z.x) * newC.x;
95			z.y += sign(z.y) * newC.y;
96			z.z += sign(z.z) * newC.z;
97		}
98	}
99	// DE calculations
100	if (fractal->analyticDE.enabledFalse)
101	{
102		REAL vecDE = length(z) / length(oldZ);
103		aux->DE = aux->DE * vecDE * fractal->analyticDE.scale1 + fractal->analyticDE.offset1;
104	}
105	return z;
106}