1/**
2 * Mandelbulber v2, a 3D fractal generator  _%}}i*<.        ____                _______
3 * Copyright (C) 2021 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 * DIFSBoxV1Iteration  fragmentarium code, mdifs by knighty (jan 2012)
10 * DIFS = direct distance iterated function (primitives) system
11
12 * This file has been autogenerated by tools/populateUiInformation.php
13 * from the file "fractal_difs_box_v1.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 DIFSBoxV1Iteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
18{
19	REAL colorAdd = 0.0f;
20	REAL4 oldZ = z;
21	REAL4 boxFold = fractal->transformCommon.additionConstantA111;
22
23	// abs
24	if (fractal->transformCommon.functionEnabledAxFalse
25			&& aux->i >= fractal->transformCommon.startIterationsX
26			&& aux->i < fractal->transformCommon.stopIterationsX)
27		z.x = fabs(z.x);
28
29	if (fractal->transformCommon.functionEnabledAyFalse
30			&& aux->i >= fractal->transformCommon.startIterationsY
31			&& aux->i < fractal->transformCommon.stopIterationsY)
32		z.y = fabs(z.y);
33
34	if (fractal->transformCommon.functionEnabledAzFalse
35			&& aux->i >= fractal->transformCommon.startIterationsZ
36			&& aux->i < fractal->transformCommon.stopIterationsZ)
37		z.z = fabs(z.z);
38	// xy box fold
39	if (fractal->transformCommon.functionEnabledCx
40			&& aux->i >= fractal->transformCommon.startIterationsA
41			&& aux->i < fractal->transformCommon.stopIterationsA)
42	{
43		z.x = fabs(z.x + boxFold.x) - fabs(z.x - boxFold.x) - z.x;
44		z.y = fabs(z.y + boxFold.y) - fabs(z.y - boxFold.y) - z.y;
45	}
46	// xyz box fold
47	if (fractal->transformCommon.functionEnabledBFalse
48			&& aux->i >= fractal->transformCommon.startIterationsB
49			&& aux->i < fractal->transformCommon.stopIterationsB)
50		z -= boxFold;
51	// polyfold
52	if (fractal->transformCommon.functionEnabledPFalse
53			&& aux->i >= fractal->transformCommon.startIterationsP
54			&& aux->i < fractal->transformCommon.stopIterationsP)
55	{
56		z.x = fabs(z.x);
57		REAL psi = M_PI_F / fractal->transformCommon.int6;
58		psi = fabs(fmod(atan2(z.y, z.x) + psi, 2.0f * psi) - psi);
59		REAL len = native_sqrt(z.x * z.x + z.y * z.y);
60		z.x = native_cos(psi) * len;
61		z.y = native_sin(psi) * len;
62	}
63
64	// diag 1
65	if (fractal->transformCommon.functionEnabledCxFalse
66			&& aux->i >= fractal->transformCommon.startIterationsCx
67			&& aux->i < fractal->transformCommon.stopIterationsCx)
68		if (z.x > z.y)
69		{
70			REAL temp = z.x;
71			z.x = z.y;
72			z.y = temp;
73		}
74
75	// abs offsets
76	if (fractal->transformCommon.functionEnabledCFalse
77			&& aux->i >= fractal->transformCommon.startIterationsC
78			&& aux->i < fractal->transformCommon.stopIterationsC)
79	{
80		REAL xOffset = fractal->transformCommon.offsetC0;
81		if (z.x < xOffset) z.x = fabs(z.x - xOffset) + xOffset;
82	}
83	if (fractal->transformCommon.functionEnabledDFalse
84			&& aux->i >= fractal->transformCommon.startIterationsD
85			&& aux->i < fractal->transformCommon.stopIterationsD)
86	{
87		REAL yOffset = fractal->transformCommon.offsetD0;
88		if (z.y < yOffset) z.y = fabs(z.y - yOffset) + yOffset;
89	}
90
91	// diag 2
92	if (fractal->transformCommon.functionEnabledCyFalse
93			&& aux->i >= fractal->transformCommon.startIterationsCy
94			&& aux->i < fractal->transformCommon.stopIterationsCy)
95		if (z.x > z.y)
96		{
97			REAL temp = z.x;
98			z.x = z.y;
99			z.y = temp;
100		}
101
102	// reverse offset part 1
103	if (aux->i >= fractal->transformCommon.startIterationsE
104			&& aux->i < fractal->transformCommon.stopIterationsE)
105		z.x -= fractal->transformCommon.offsetE0;
106
107	if (aux->i >= fractal->transformCommon.startIterationsF
108			&& aux->i < fractal->transformCommon.stopIterationsF)
109		z.y -= fractal->transformCommon.offsetF0;
110
111	// scale
112	REAL useScale = 1.0f;
113	if (aux->i >= fractal->transformCommon.startIterationsS
114			&& aux->i < fractal->transformCommon.stopIterationsS)
115	{
116		useScale = aux->actualScaleA + fractal->transformCommon.scale2;
117		z *= useScale;
118		aux->DE = aux->DE * fabs(useScale) + 1.0f;
119
120		if (fractal->transformCommon.functionEnabledKFalse
121				&& aux->i >= fractal->transformCommon.startIterationsK
122				&& aux->i < fractal->transformCommon.stopIterationsK)
123		{
124			// update actualScaleA for next iteration
125			REAL vary = fractal->transformCommon.scaleVary0
126									* (fabs(aux->actualScaleA) - fractal->transformCommon.scaleC1);
127			aux->actualScaleA -= vary;
128		}
129	}
130
131	// reverse offset part 2
132	if (aux->i >= fractal->transformCommon.startIterationsE
133			&& aux->i < fractal->transformCommon.stopIterationsE)
134		z.x += fractal->transformCommon.offsetE0;
135
136	if (aux->i >= fractal->transformCommon.startIterationsF
137			&& aux->i < fractal->transformCommon.stopIterationsF)
138		z.y += fractal->transformCommon.offsetF0;
139
140	// offset2
141	z += fractal->transformCommon.offset001;
142
143	// rotation
144	if (fractal->transformCommon.functionEnabledRFalse
145			&& aux->i >= fractal->transformCommon.startIterationsR
146			&& aux->i < fractal->transformCommon.stopIterationsR)
147	{
148		z = Matrix33MulFloat4(fractal->transformCommon.rotationMatrix, z);
149	}
150	REAL colorDist = aux->dist;
151	// DE
152	REAL4 zc = z;
153	if (fractal->transformCommon.functionEnabledYFalse) zc = oldZ;
154
155	// box
156	if (aux->i >= fractal->transformCommon.startIterations
157			&& aux->i < fractal->transformCommon.stopIterations)
158	{
159		REAL4 boxSize = fractal->transformCommon.additionConstant111;
160		// curve
161		if (fractal->transformCommon.functionEnabledTFalse
162				&& aux->i >= fractal->transformCommon.startIterationsT
163				&& aux->i < fractal->transformCommon.stopIterationsT)
164		{
165			REAL absZZ = zc.z * zc.z * fractal->transformCommon.scale0;
166			boxSize.x += absZZ;
167			boxSize.y += absZZ;
168		}
169
170		// pyramid
171		if (fractal->transformCommon.functionEnabledMFalse
172				&& aux->i >= fractal->transformCommon.startIterationsM
173				&& aux->i < fractal->transformCommon.stopIterationsM)
174		{
175			REAL subZ = fractal->transformCommon.scaleA0 * zc.z;
176			boxSize.x -= subZ;
177			boxSize.y -= subZ;
178		}
179
180		zc = fabs(zc) - boxSize;
181		zc.x = max(zc.x, 0.0f);
182		zc.y = max(zc.y, 0.0f);
183		zc.z = max(zc.z, 0.0f);
184		REAL zcd = length(zc);
185
186		aux->dist = min(aux->dist, zcd / aux->DE);
187
188		if (!fractal->transformCommon.functionEnabledEFalse)
189			aux->dist = min(aux->dist, zcd / aux->DE);
190		else
191			aux->dist = min(aux->dist, zcd / aux->DE) - fractal->transformCommon.offsetB0;
192	}
193
194	// aux->color
195	if (fractal->foldColor.auxColorEnabled)
196	{
197		if (fractal->foldColor.auxColorEnabledFalse)
198		{
199			colorAdd += fractal->foldColor.difs0000.x * fabs(z.x * z.y);
200			colorAdd += fractal->foldColor.difs0000.y * max(z.x, z.y);
201		}
202		colorAdd += fractal->foldColor.difs1;
203		if (fractal->foldColor.auxColorEnabledA)
204		{
205			if (colorDist != aux->dist) aux->color += colorAdd;
206		}
207		else
208			aux->color += colorAdd;
209	}
210	return z;
211}