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 * transfDIFSHextgrid2Iteration  fragmentarium code, mdifs by knighty (jan 2012)
10 * and  darkbeams optimized verion @reference
11 * http://www.fractalforums.com/mandelbulb-3d/custom-formulas-and-transforms-release-t17106/
12 * "Beautiful iso-surface made of a hexagonal grid of tubes.
13 * Taken from K3DSurf forum, posted by user abdelhamid belaid."
14
15 * This file has been autogenerated by tools/populateUiInformation.php
16 * from the file "fractal_transf_difs_hextgrid2.cpp" in the folder formula/definition
17 * D O    N O T    E D I T    T H I S    F I L E !
18 */
19
20REAL4 TransfDIFSHextgrid2Iteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
21{
22	REAL4 zc = z;
23
24	REAL size = fractal->transformCommon.scale1;
25	REAL hexD = 0.0f;
26
27	if (fractal->transformCommon.rotationEnabled)
28	{
29		zc = Matrix33MulFloat4(fractal->transformCommon.rotationMatrix, zc);
30	}
31
32	zc.z /= fractal->transformCommon.scaleF1;
33
34	REAL cosPi6 = native_cos(M_PI_F / 6.0f);
35	REAL yFloor = fabs(zc.y - size * floor(zc.y / size + 0.5f));
36	REAL xFloor = fabs(zc.x - size * 1.5f / cosPi6 * floor(zc.x / size / 1.5f * cosPi6 + 0.5f));
37	REAL gridMax = max(yFloor, xFloor * cosPi6 + yFloor * native_sin(M_PI_F / 6.0f));
38	REAL gridMin = min(gridMax - size * 0.5f, yFloor);
39	if (!fractal->transformCommon.functionEnabledJFalse)
40		hexD = native_sqrt(gridMin * gridMin + zc.z * zc.z);
41	else
42		hexD = max(fabs(gridMin), fabs(zc.z));
43
44	aux->dist = min(aux->dist, (hexD - fractal->transformCommon.offset0005) / (aux->DE + 1.0f));
45	return z;
46}