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  * reference: eiifie paxis2 https://www.shadertoy.com/view/XlSGDc
10  * paxis idea from dila originally at https://www.shadertoy.com/view/Xlj3DK
11  */
12 
13 #include "all_fractal_definitions.h"
14 
cFractalOctahedron()15 cFractalOctahedron::cFractalOctahedron() : cAbstractFractal()
16 {
17 	nameInComboBox = "Octahedron";
18 	internalName = "octahedron";
19 	internalID = fractal::octahedron;
20 	DEType = analyticDEType;
21 	DEFunctionType = customDEFunction;
22 	cpixelAddition = cpixelDisabledByDefault;
23 	defaultBailout = 10.0;
24 	DEAnalyticFunction = analyticFunctionCustomDE;
25 	coloringFunction = coloringFunctionDefault;
26 }
27 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)28 void cFractalOctahedron::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
29 {
30 	if (aux.i >= fractal->transformCommon.startIterationsD
31 			&& aux.i < fractal->transformCommon.stopIterationsD1)
32 	{
33 		CVector4 a;
34 		double colorAdd = 0.0;
35 		double b = 1.0;
36 		double d;
37 		double limitA = fractal->transformCommon.offset0;
38 		double limitB = fractal->transformCommon.offsetA0;
39 
40 		for (int i = 0; i < fractal->transformCommon.int3X; i++)
41 		{
42 			double sizer1 = fractal->transformCommon.scale1 * b;
43 			a = fabs(z);
44 			z.x -= sign(z.x) * max(1.0 * sign(a.x - max(a.y, a.z)), limitA) * sizer1;
45 			z.y -= sign(z.y) * max(1.0 * sign(a.y - max(a.z, a.x)), limitA) * sizer1;
46 			z.z -= sign(z.z) * max(1.0 * sign(a.z - max(a.x, a.y)), limitA) * sizer1;
47 			b *= fractal->transformCommon.scale05;
48 		}
49 
50 		d = z.Length() - fractal->transformCommon.minR2p25;
51 		for (int i = 0; i < fractal->transformCommon.int3Y; i++)
52 		{
53 			double sizer2 = fractal->transformCommon.scaleA1 * b;
54 			a = fabs(z);
55 			z.x -= sign(z.x) * max(1.0 * sign(a.x - min(a.y, a.z)), limitB) * sizer2;
56 			z.y -= sign(z.y) * max(1.0 * sign(a.y - min(a.z, a.x)), limitB) * sizer2;
57 			z.z -= sign(z.z) * max(1.0 * sign(a.z - min(a.x, a.y)), limitB) * sizer2;
58 			b *= fractal->transformCommon.minR05;
59 			colorAdd += z.Dot(z);
60 		}
61 		z *= fractal->transformCommon.scaleC1;
62 		aux.DE *= fractal->transformCommon.scaleC1;
63 		a = fabs(z);
64 
65 		double d2;
66 
67 		if (!fractal->transformCommon.functionEnabledFalse)
68 			d2 = max(a.x, max(a.y, a.z)) - b * fractal->transformCommon.scaleD1;
69 		else
70 			d2 = a.Length() - b * fractal->transformCommon.scaleD1;
71 
72 		d2 = max(d2, -d) / fabs(aux.DE);
73 
74 		if (!fractal->transformCommon.functionEnabledAFalse)
75 			aux.dist = d2;
76 		else
77 			aux.dist = min(aux.dist, d2);
78 
79 		// aux.color
80 		if (fractal->foldColor.auxColorEnabledFalse)
81 		{
82 			colorAdd = fractal->foldColor.difs0000.x * colorAdd;
83 			colorAdd += fractal->foldColor.difs0000.y * max(a.x, max(a.y, a.z));
84 			colorAdd += fractal->foldColor.difs0000.z * a.Length();
85 			colorAdd += fractal->foldColor.difs0000.w * d;
86 			aux.color += colorAdd * 100.0;
87 		}
88 	}
89 }
90