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 * TransfDifsCylinderV2Iteration  fragmentarium code, mdifs by knighty (jan 2012)
10 * and http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
11
12 * This file has been autogenerated by tools/populateUiInformation.php
13 * from the file "fractal_transf_difs_cylinder_v2.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 TransfDIFSCylinderV2Iteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
18{
19	if (fractal->transformCommon.functionEnabledAFalse)
20	{
21		if (fractal->transformCommon.functionEnabledAxFalse) z.x = fabs(z.x);
22		if (fractal->transformCommon.functionEnabledAyFalse) z.y = fabs(z.y);
23		if (fractal->transformCommon.functionEnabledAzFalse) z.z = fabs(z.z);
24	}
25	z += fractal->transformCommon.offset000;
26
27	if (fractal->transformCommon.rotationEnabledFalse
28			&& aux->i >= fractal->transformCommon.startIterationsR
29			&& aux->i < fractal->transformCommon.stopIterationsR1)
30	{
31		z = Matrix33MulFloat4(fractal->transformCommon.rotationMatrix, z);
32	}
33
34	REAL4 zc = z;
35
36	REAL temp;
37	// swap axis
38	if (fractal->transformCommon.functionEnabledSwFalse)
39	{
40		REAL temp = zc.x;
41		zc.x = zc.z;
42		zc.z = temp;
43	}
44
45	REAL cylR = zc.x * zc.x;
46	REAL absH = fabs(zc.z);
47	REAL lengthCyl = zc.z;
48
49	cylR = native_sqrt(cylR + zc.y * zc.y);
50	REAL cylH = absH - fractal->transformCommon.offsetA1;
51
52	// no absz
53	if (fractal->transformCommon.functionEnabledMFalse
54			&& aux->i >= fractal->transformCommon.startIterationsM
55			&& aux->i < fractal->transformCommon.stopIterationsM)
56	{
57		absH = lengthCyl;
58	}
59
60	// abs sqrd
61	if (fractal->transformCommon.functionEnabledTFalse
62			&& aux->i >= fractal->transformCommon.startIterationsT
63			&& aux->i < fractal->transformCommon.stopIterationsT)
64	{
65		absH *= absH;
66	}
67
68	REAL cylRm = cylR - fractal->transformCommon.radius1;
69	if (fractal->transformCommon.functionEnabledFalse)
70		cylRm = fabs(cylRm) - fractal->transformCommon.offset0;
71
72	cylRm += fractal->transformCommon.scale0 * absH;
73	zc.z = absH;
74
75	// tops
76	if (fractal->transformCommon.functionEnabledNFalse
77			&& aux->i >= fractal->transformCommon.startIterationsN
78			&& aux->i < fractal->transformCommon.stopIterationsN)
79	{
80		temp = cylR;
81	}
82	else
83	{
84		temp = cylRm;
85	}
86	temp = max(temp, 0.0f);
87	REAL cylHm = max(cylH, 0.0f);
88	REAL cylD = native_sqrt(temp * temp + cylHm * cylHm);
89
90	// rings
91	if (fractal->transformCommon.functionEnabledOFalse
92			&& aux->i >= fractal->transformCommon.startIterationsO
93			&& aux->i < fractal->transformCommon.stopIterationsO)
94	{
95		cylD = native_sqrt(cylRm * cylRm + cylH * cylH);
96	}
97	cylD = min(max(cylRm, cylH) - fractal->transformCommon.offsetR0, 0.0f) + cylD;
98
99	aux->dist = min(aux->dist, cylD / (aux->DE + 1.0f));
100
101	if (fractal->transformCommon.functionEnabledZcFalse
102			&& aux->i >= fractal->transformCommon.startIterationsZc
103			&& aux->i < fractal->transformCommon.stopIterationsZc)
104		z = zc;
105	return z;
106}