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 * Hybrid of Mandelbox and Mandelbulb power 2 with scaling of z axis
10
11 * This file has been autogenerated by tools/populateUiInformation.php
12 * from the file "fractal_box_fold_bulb_pow2.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 BoxFoldBulbPow2Iteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
17{
18	(void)aux;
19	if (fabs(z.x) > fractal->foldingIntPow.foldFactor)
20		z.x = sign(z.x) * fractal->foldingIntPow.foldFactor * 2.0f - z.x;
21	if (fabs(z.y) > fractal->foldingIntPow.foldFactor)
22		z.y = sign(z.y) * fractal->foldingIntPow.foldFactor * 2.0f - z.y;
23	if (fabs(z.z) > fractal->foldingIntPow.foldFactor)
24		z.z = sign(z.z) * fractal->foldingIntPow.foldFactor * 2.0f - z.z;
25
26	REAL fR2_2 = 1.0f;
27	REAL mR2_2 = 0.25f;
28	REAL r2_2 = dot(z, z);
29	REAL tglad_factor1_2 = fR2_2 / mR2_2;
30
31	if (r2_2 < mR2_2)
32	{
33		z = z * tglad_factor1_2;
34		aux->DE *= tglad_factor1_2;
35	}
36	else if (r2_2 < fR2_2)
37	{
38		REAL tglad_factor2_2 = fR2_2 / r2_2;
39		z = z * tglad_factor2_2;
40		aux->DE *= tglad_factor2_2;
41	}
42
43	z = z * 2.0f;
44	REAL x2 = z.x * z.x;
45	REAL y2 = z.y * z.y;
46	REAL z2 = z.z * z.z;
47	REAL temp = 1.0f - z2 / (x2 + y2);
48	REAL4 zTemp;
49	zTemp.x = (x2 - y2) * temp;
50	zTemp.y = 2.0f * z.x * z.y * temp;
51	zTemp.z = -2.0f * z.z * native_sqrt(x2 + y2);
52	zTemp.w = z.w;
53	z = zTemp;
54	z.z *= fractal->foldingIntPow.zFactor;
55	// analyticDE controls
56	if (fractal->analyticDE.enabledFalse)
57	{
58		aux->DE = (aux->DE + 1.0f) * 5.0f * aux->r * fractal->analyticDE.scale1
59								* native_sqrt(fractal->foldingIntPow.zFactor * fractal->foldingIntPow.zFactor + 2.0f
60															+ fractal->analyticDE.offset2)
61							+ fractal->analyticDE.offset1;
62	}
63	// INFO remark: changed sequence of operation.
64	// adding of C constant was before multiplying by z-factor
65	return z;
66}