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  * amazing surf Mod4 based on Mandelbulber3D. Formula proposed by Kali, with features added by
10  * DarkBeam
11  * This formula has a c.x c.y SWAP
12  * @reference
13  * http://www.fractalforums.com/mandelbulb-3d/custom-formulas-and-transforms-release-t17106/
14  */
15 
16 #include "all_fractal_definitions.h"
17 
cFractalAmazingSurfMod4()18 cFractalAmazingSurfMod4::cFractalAmazingSurfMod4() : cAbstractFractal()
19 {
20 	nameInComboBox = "Amazing Surf - Mod 4";
21 	internalName = "amazing_surf_mod4";
22 	internalID = fractal::amazingSurfMod4;
23 	DEType = analyticDEType;
24 	DEFunctionType = linearDEFunction;
25 	cpixelAddition = cpixelEnabledByDefault;
26 	defaultBailout = 100.0;
27 	DEAnalyticFunction = analyticFunctionLinear;
28 	coloringFunction = coloringFunctionDefault;
29 }
30 
FormulaCode(CVector4 & z,const sFractal * fractal,sExtendedAux & aux)31 void cFractalAmazingSurfMod4::FormulaCode(CVector4 &z, const sFractal *fractal, sExtendedAux &aux)
32 {
33 	CVector4 c = aux.const_c;
34 	double colorAdd = 0.0;
35 
36 	// sphere inversion
37 	if (fractal->transformCommon.sphereInversionEnabledFalse
38 			&& aux.i >= fractal->transformCommon.startIterationsX
39 			&& aux.i < fractal->transformCommon.stopIterations1)
40 	{
41 		z += fractal->transformCommon.offset000;
42 		double rr = z.Dot(z);
43 		z *= fractal->transformCommon.scaleG1 / rr;
44 		aux.DE *= (fractal->transformCommon.scaleG1 / rr);
45 		z += fractal->transformCommon.additionConstant000 - fractal->transformCommon.offset000;
46 		z *= fractal->transformCommon.scaleA1;
47 		aux.DE *= fractal->transformCommon.scaleA1;
48 	}
49 	CVector4 oldZ = z;
50 	z.x = fabs(z.x + fractal->transformCommon.additionConstant111.x)
51 				- fabs(z.x - fractal->transformCommon.additionConstant111.x) - z.x;
52 	z.y = fabs(z.y + fractal->transformCommon.additionConstant111.y)
53 				- fabs(z.y - fractal->transformCommon.additionConstant111.y) - z.y;
54 	if (fractal->transformCommon.functionEnabledJFalse)
55 		z.z = fabs(z.z + fractal->transformCommon.additionConstant111.z)
56 				- fabs(z.z - fractal->transformCommon.additionConstant111.z) - z.z;
57 	CVector4 zCol = z;
58 
59 	z += fractal->transformCommon.offsetA000;
60 	double rr = z.Dot(z);
61 	double rrCol = rr;
62 	double MinRR = fractal->transformCommon.minR2p25;
63 	double dividend = rr < MinRR ? MinRR : min(rr, 1.0);
64 
65 	// scale
66 	double useScale = 1.0;
67 
68 	useScale = (aux.actualScaleA + fractal->transformCommon.scale2) / dividend;
69 	z *= useScale;
70 	aux.DE = aux.DE * fabs(useScale) + fractal->analyticDE.offset1;
71 	if (fractal->transformCommon.functionEnabledKFalse)
72 	{
73 		// update actualScaleA for next iteration
74 		double vary = fractal->transformCommon.scaleVary0
75 									* (fabs(aux.actualScaleA) - fractal->transformCommon.scaleC1);
76 		aux.actualScaleA -= vary;
77 	}
78 
79 	if (fractal->transformCommon.rotation2EnabledFalse)
80 	{
81 		z = fractal->transformCommon.rotationMatrix.RotateVector(z);
82 	}
83 
84 	if (fractal->transformCommon.addCpixelEnabledFalse)
85 		z += CVector4(c.y, c.x, c.z, c.w) * fractal->transformCommon.constantMultiplier111;
86 
87 	z += fractal->transformCommon.additionConstantA000;
88 
89 	z = fractal->transformCommon.rotationMatrix2.RotateVector(z);
90 
91 	if (fractal->foldColor.auxColorEnabledFalse)
92 	{
93 		if (zCol.x != oldZ.x)
94 			colorAdd += fractal->mandelbox.color.factor.x
95 									* (fabs(zCol.x) - fractal->transformCommon.additionConstant111.x);
96 		if (zCol.y != oldZ.y)
97 			colorAdd += fractal->mandelbox.color.factor.y
98 									* (fabs(zCol.y) - fractal->transformCommon.additionConstant111.y);
99 		if (zCol.z != oldZ.z)
100 			colorAdd += fractal->mandelbox.color.factor.z
101 									* (fabs(zCol.z) - fractal->transformCommon.additionConstant111.z);
102 		if (rrCol > fractal->transformCommon.minR2p25)
103 			colorAdd +=
104 				fractal->mandelbox.color.factorSp2 * (rrCol - fractal->transformCommon.minR2p25) / 100.0;
105 		aux.color += colorAdd;
106 	}
107 }
108