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 * TransfDifsTorusV3Iteration  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_torus_v3.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 TransfDIFSTorusV3Iteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
18{
19	z += fractal->transformCommon.offset000;
20
21	if (fractal->transformCommon.functionEnabledxFalse) z.x = -fabs(z.x);
22	if (fractal->transformCommon.functionEnabledyFalse) z.y = -fabs(z.y);
23	if (fractal->transformCommon.functionEnabledzFalse) z.z = -fabs(z.z);
24
25	if (fractal->transformCommon.rotationEnabledFalse
26			&& aux->i >= fractal->transformCommon.startIterationsR
27			&& aux->i < fractal->transformCommon.stopIterationsR1)
28	{
29		z = Matrix33MulFloat4(fractal->transformCommon.rotationMatrix, z);
30	}
31	REAL4 zc = z;
32
33	// swap axis
34	if (fractal->transformCommon.functionEnabledSwFalse)
35	{
36		REAL temp = zc.x;
37		zc.x = zc.z;
38		zc.z = temp;
39	}
40
41	REAL lenX = fractal->transformCommon.offset1;
42	REAL lenY = fractal->transformCommon.offsetA0;
43	REAL4 absZ = fabs(zc);
44
45	if (fractal->transformCommon.functionEnabledMFalse)
46		lenX += absZ.z * fractal->transformCommon.scale0;
47	if (fractal->transformCommon.functionEnabledNFalse)
48		lenY += absZ.z * fractal->transformCommon.scaleA0;
49	if (fractal->transformCommon.functionEnabledOFalse)
50		lenX += absZ.y * fractal->transformCommon.scaleB0;
51	if (fractal->transformCommon.functionEnabledPFalse)
52		lenY += absZ.x * fractal->transformCommon.scaleC0;
53
54	REAL3 q = (REAL3){max(absZ.y - lenY, 0.0f), max(absZ.x - lenX, 0.0f), zc.z};
55	q *= q;
56
57	REAL streD = native_sqrt(q.x + q.y) - fractal->transformCommon.offsetR1;
58
59	if (!fractal->transformCommon.functionEnabledJFalse)
60		streD = native_sqrt(streD * streD + q.z);
61	else
62		streD = max(fabs(streD), fabs(zc.z));
63
64	aux->dist = min(aux->dist, (streD - fractal->transformCommon.offsetA05) / (aux->DE + 1.0f));
65	return z;
66}