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 * Blockify
10 * based on a block of Fragmentarium code, from Adam Nixon
11 * analytic aux.DE
12
13 * This file has been autogenerated by tools/populateUiInformation.php
14 * from the file "fractal_transf_blockify.cpp" in the folder formula/definition
15 * D O    N O T    E D I T    T H I S    F I L E !
16 */
17
18REAL4 TransfBlockifyIteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
19{
20	REAL master = fractal->transformCommon.scale / 100.0f;
21	REAL4 bSize = fractal->transformCommon.constantMultiplier111 * master;
22
23	if (!fractal->transformCommon.functionEnabledFalse)
24	{
25		if (!fractal->transformCommon.functionEnabledDFalse)
26		{
27			if (fractal->transformCommon.functionEnabledCx) z.x = (floor(z.x / bSize.x) + 0.5f) * bSize.x;
28			if (fractal->transformCommon.functionEnabledCy) z.y = (floor(z.y / bSize.y) + 0.5f) * bSize.y;
29			if (fractal->transformCommon.functionEnabledCz) z.z = (floor(z.z / bSize.z) + 0.5f) * bSize.z;
30		}
31		else // normalize
32		{
33			REAL rNorm = length(z); // dot(z, z);
34			z /= rNorm;
35			if (fractal->transformCommon.functionEnabledCx) z.x = (floor(z.x / bSize.x) + 0.5f) * bSize.x;
36			if (fractal->transformCommon.functionEnabledCy) z.y = (floor(z.y / bSize.y) + 0.5f) * bSize.y;
37			if (fractal->transformCommon.functionEnabledCz) z.z = (floor(z.z / bSize.z) + 0.5f) * bSize.z;
38			z *= rNorm;
39		}
40	}
41	else // radial
42	{
43		REAL rr = dot(z, z);
44		if (fractal->transformCommon.functionEnabledRFalse) rr = native_sqrt(rr); // length(z);
45		if (fractal->transformCommon.functionEnabledBxFalse) rr = z.x * z.x + z.y * z.y;
46		if (fractal->transformCommon.functionEnabledByFalse) rr = z.y * z.y + z.z * z.z;
47		if (fractal->transformCommon.functionEnabledBzFalse) rr = z.z * z.z + z.x * z.x;
48		z /= rr;
49		rr = floor(rr / master) * master;
50		z *= rr;
51	}
52
53	// post scale
54	z *= fractal->transformCommon.scale1;
55	aux->DE = aux->DE * fractal->transformCommon.scale1 * fractal->analyticDE.scale1
56						+ fractal->analyticDE.offset0;
57
58	return z;
59}