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 * Menger Middle Mod
10
11 * This file has been autogenerated by tools/populateUiInformation.php
12 * from the file "fractal_menger_middle_mod.cpp" in the folder formula/definition
13 * D O    N O T    E D I T    T H I S    F I L E !
14 */
15
16REAL4 MengerMiddleModIteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
17{
18	// sphere inversion
19	if (fractal->transformCommon.sphereInversionEnabledFalse
20			&& aux->i >= fractal->transformCommon.startIterationsD
21			&& aux->i < fractal->transformCommon.stopIterationsD1)
22	{
23		REAL rr = 1.0f;
24		z += fractal->transformCommon.offset000;
25		rr = dot(z, z);
26		z *= fractal->transformCommon.maxR2d1 / rr;
27		z += fractal->transformCommon.additionConstant000 - fractal->transformCommon.offset000;
28		z *= fractal->transformCommon.scaleB1;
29		// REAL r = native_sqrt(rr);
30		aux->DE *= (fractal->transformCommon.maxR2d1 / rr) * fractal->analyticDE.scale1
31							 * fractal->transformCommon.scaleB1;
32	}
33
34	// fabs() and menger fold
35	z = fabs(z + fractal->transformCommon.additionConstantA000);
36	if (z.x - z.y < 0.0f)
37	{
38		REAL temp = z.y;
39		z.y = z.x;
40		z.x = temp;
41	}
42	if (z.x - z.z < 0.0f)
43	{
44		REAL temp = z.z;
45		z.z = z.x;
46		z.x = temp;
47	}
48	if (z.y - z.z < 0.0f)
49	{
50		REAL temp = z.z;
51		z.z = z.y;
52		z.y = temp;
53	}
54
55	if (fractal->mandelbox.mainRotationEnabled && aux->i >= fractal->transformCommon.startIterationsC
56			&& aux->i < fractal->transformCommon.stopIterationsC) // rotation
57	{
58		z = Matrix33MulFloat4(fractal->mandelbox.mainRot, z);
59	}
60
61	if (fractal->transformCommon.functionEnabledBxFalse
62			&& aux->i >= fractal->transformCommon.startIterationsA
63			&& aux->i < fractal->transformCommon.stopIterationsA) // box fold
64	{
65		if (fabs(z.x) > fractal->mandelbox.foldingLimit)
66		{
67			z.x = sign(z.x) * fractal->mandelbox.foldingValue - z.x;
68			aux->color += fractal->mandelbox.color.factor.x;
69		}
70		if (fabs(z.y) > fractal->mandelbox.foldingLimit)
71		{
72			z.y = sign(z.y) * fractal->mandelbox.foldingValue - z.y;
73			aux->color += fractal->mandelbox.color.factor.y;
74		}
75		REAL zLimit = fractal->mandelbox.foldingLimit * fractal->transformCommon.scale1;
76		REAL zValue = fractal->mandelbox.foldingValue * fractal->transformCommon.scale1;
77		if (fabs(z.z) > zLimit)
78		{
79			z.z = sign(z.z) * zValue - z.z;
80			aux->color += fractal->mandelbox.color.factor.z;
81		}
82	}
83	if (fractal->transformCommon.functionEnabledByFalse
84			&& aux->i >= fractal->transformCommon.startIterations
85			&& aux->i < fractal->transformCommon.stopIterations)
86	{ // fabsBoxFold
87		REAL4 tempA = (REAL4){0.0f, 0.0f, 0.0f, 0.0f};
88		REAL4 tempB = (REAL4){0.0f, 0.0f, 0.0f, 0.0f};
89
90		if (fractal->transformCommon.functionEnabledx)
91			tempA.x = fabs(z.x + fractal->transformCommon.additionConstant111.x);
92		if (fractal->transformCommon.functionEnabledAx)
93			tempB.x = fabs(z.x - fractal->transformCommon.additionConstantA111.x);
94		z.x = tempA.x - tempB.x - (z.x * fractal->transformCommon.scale3D111.x);
95
96		if (fractal->transformCommon.functionEnabledy)
97			tempA.y = fabs(z.y + fractal->transformCommon.additionConstant111.y);
98		if (fractal->transformCommon.functionEnabledAy)
99			tempB.y = fabs(z.y - fractal->transformCommon.additionConstantA111.y);
100		z.y = tempA.y - tempB.y - (z.y * fractal->transformCommon.scale3D111.y);
101
102		if (fractal->transformCommon.functionEnabledz)
103			tempA.z = fabs(z.z + fractal->transformCommon.additionConstant111.z);
104		if (fractal->transformCommon.functionEnabledAz)
105			tempB.z = fabs(z.z - fractal->transformCommon.additionConstantA111.z);
106		z.z = tempA.z - tempB.z - (z.z * fractal->transformCommon.scale3D111.z);
107
108		if (aux->i >= fractal->transformCommon.startIterationsB
109				&& aux->i < fractal->transformCommon.stopIterationsB)
110		{
111			z *= fractal->transformCommon.scaleA1;
112			aux->DE *= fabs(fractal->transformCommon.scaleA1);
113		}
114	}
115	// menger scale
116	REAL useScale = 1.0f;
117	if (aux->i >= fractal->transformCommon.startIterationsS
118			&& aux->i < fractal->transformCommon.stopIterationsS)
119	{
120		useScale = aux->actualScaleA + fractal->transformCommon.scale3;
121
122		z *= useScale;
123
124		if (!fractal->analyticDE.enabledFalse)
125			aux->DE = aux->DE * fabs(useScale) + 1.0f;
126		else // testing for log
127			aux->DE = aux->DE * fabs(useScale) * fractal->analyticDE.scale1 + fractal->analyticDE.offset1;
128
129		if (fractal->transformCommon.functionEnabledFFalse
130				&& aux->i >= fractal->transformCommon.startIterationsY
131				&& aux->i < fractal->transformCommon.stopIterationsY)
132		{
133			// update actualScaleA for next iteration
134			REAL vary = fractal->transformCommon.scaleVary0
135									* (fabs(aux->actualScaleA) - fractal->transformCommon.scaleC1);
136			if (fractal->transformCommon.functionEnabledMFalse)
137				aux->actualScaleA = -vary;
138			else
139				aux->actualScaleA = aux->actualScaleA - vary;
140		}
141	}
142
143	// menger offsets
144	z.x -= 2.0f * fractal->transformCommon.constantMultiplier111.x;
145	z.y -= 2.0f * fractal->transformCommon.constantMultiplier111.y;
146	if (fractal->transformCommon.functionEnabled)
147	{
148		if (z.z > 1.0f) z.z -= 2.0f * fractal->transformCommon.constantMultiplier111.z;
149	}
150	else
151	{
152		z.z -= 2.0f * fractal->transformCommon.constantMultiplier111.z;
153	}
154
155	if (fractal->transformCommon.addCpixelEnabledFalse) // addCpixel options
156	{
157		switch (fractal->mandelbulbMulti.orderOfXYZC)
158		{
159			case multi_OrderOfXYZCl_xyz:
160			default: aux->c = (REAL4){aux->c.x, aux->c.y, aux->c.z, aux->c.w}; break;
161			case multi_OrderOfXYZCl_xzy: aux->c = (REAL4){aux->c.x, aux->c.z, aux->c.y, aux->c.w}; break;
162			case multi_OrderOfXYZCl_yxz: aux->c = (REAL4){aux->c.y, aux->c.x, aux->c.z, aux->c.w}; break;
163			case multi_OrderOfXYZCl_yzx: aux->c = (REAL4){aux->c.y, aux->c.z, aux->c.x, aux->c.w}; break;
164			case multi_OrderOfXYZCl_zxy: aux->c = (REAL4){aux->c.z, aux->c.x, aux->c.y, aux->c.w}; break;
165			case multi_OrderOfXYZCl_zyx: aux->c = (REAL4){aux->c.z, aux->c.y, aux->c.x, aux->c.w}; break;
166		}
167		z += aux->c * fractal->transformCommon.constantMultiplierC111;
168	}
169	return z;
170}