From 4bc428eee2ab3abe7a077f92c52580482f7883d8 Mon Sep 17 00:00:00 2001 From: Michel Mastriani Date: Wed, 29 May 2019 19:44:17 -0300 Subject: [PATCH] Fixed Hypertile, Hypertile1 and Hypertile2 --- Source/Ember/Variations02.h | 80 ++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/Source/Ember/Variations02.h b/Source/Ember/Variations02.h index 2ccf6cc..95ae9cb 100644 --- a/Source/Ember/Variations02.h +++ b/Source/Ember/Variations02.h @@ -3053,7 +3053,7 @@ public: T vr = m_Weight / (SQR(c) + SQR(d)); helper.Out.x = vr * (a * c + b * d); helper.Out.y = vr * (b * c - a * d); - helper.Out.z = DefaultZ(helper); + helper.Out.z = DefaultZ(helper); } virtual string OpenCLString() const override @@ -3084,15 +3084,11 @@ public: virtual void Precalc() override { - T pa = 2 * T(M_PI) / Zeps(m_P); - T qa = 2 * T(M_PI) / Zeps(m_Q); - T r = (1 - std::cos(pa)) / (std::cos(pa) + std::cos(qa)) + 1; - T a = m_N * pa; - - if (r > 0) - r = 1 / std::sqrt(r); - else - r = 1; + T pa = T(M_2PI) / Zeps(m_P); + T cs = std::cos(pa); + T r2 = (T(1) - cs) / (cs + cos(M_2PI / Zeps(m_Q))) + 1; + T r = (r2 > 0) ? T(1) / sqrt(r2) : T(1); + T a = m_N * pa; m_Real = r * std::cos(a); m_Imag = r * std::sin(a); @@ -3103,9 +3099,9 @@ protected: { string prefix = Prefix(); m_Params.clear(); - m_Params.push_back(ParamWithName(&m_P, prefix + "hypertile_p", 3, eParamType::INTEGER, 3, T(0x7fffffff))); - m_Params.push_back(ParamWithName(&m_Q, prefix + "hypertile_q", 7, eParamType::INTEGER, 3, T(0x7fffffff))); - m_Params.push_back(ParamWithName(&m_N, prefix + "hypertile_n", 0, eParamType::INTEGER)); + m_Params.push_back(ParamWithName(&m_P, prefix + "hypertile_p", T(3))); + m_Params.push_back(ParamWithName(&m_Q, prefix + "hypertile_q", T(7))); + m_Params.push_back(ParamWithName(&m_N, prefix + "hypertile_n", T(0))); m_Params.push_back(ParamWithName(true, &m_Real, prefix + "hypertile_real"));//Precalc. m_Params.push_back(ParamWithName(true, &m_Imag, prefix + "hypertile_imag")); } @@ -3133,8 +3129,8 @@ public: PARVARCOPY(Hypertile1Variation) virtual void Func(IteratorHelper& helper, Point& outPoint, QTIsaac& rand) override - { - T temp = rand.Rand() * m_Pa; + { + T temp = Floor(rand.Frand01() * m_IP) * m_Pa; T sina = std::sin(temp); T cosa = std::cos(temp); T re = m_R * cosa; @@ -3160,8 +3156,9 @@ public: string q = "parVars[" + ToUpper(m_Params[i++].Name()) + index; string pa = "parVars[" + ToUpper(m_Params[i++].Name()) + index; string r = "parVars[" + ToUpper(m_Params[i++].Name()) + index; + string ip = "parVars[" + ToUpper(m_Params[i++].Name()) + index; ss << "\t{\n" - << "\t\treal_t temp = MwcNext(mwc) * " << pa << ";\n" + << "\t\treal_t temp = floor(MwcNext01(mwc) * " << ip << ") * " << pa << ";\n" << "\t\treal_t sina = sin(temp);\n" << "\t\treal_t cosa = cos(temp);\n" << "\t\treal_t re = " << r << " * cosa;\n" @@ -3181,15 +3178,11 @@ public: virtual void Precalc() override { - T r2 = 1 - (std::cos(2 * T(M_PI) / Zeps(m_P)) - 1) / - (std::cos(2 * T(M_PI) / Zeps(m_P)) + std::cos(2 * T(M_PI) / Zeps(m_Q))); - - if (r2 > 0) - m_R = 1 / std::sqrt(r2); - else - m_R = 1; - - m_Pa = 2 * T(M_PI) / Zeps(m_P); + m_Pa = T(M_2PI) / Zeps(m_P); + T cs = cos(m_Pa); + T r2 = T(1) - (cs - 1) / (cs + cos(M_2PI / Zeps(m_Q))); + m_R = (r2 > 0) ? T(1) / sqrt(r2) : T(1); + m_IP = (int) m_P; } protected: @@ -3197,10 +3190,11 @@ protected: { string prefix = Prefix(); m_Params.clear(); - m_Params.push_back(ParamWithName(&m_P, prefix + "hypertile1_p", 3, eParamType::INTEGER, 3, T(0x7fffffff))); - m_Params.push_back(ParamWithName(&m_Q, prefix + "hypertile1_q", 7, eParamType::INTEGER, 3, T(0x7fffffff))); + m_Params.push_back(ParamWithName(&m_P, prefix + "hypertile1_p", T(3))); + m_Params.push_back(ParamWithName(&m_Q, prefix + "hypertile1_q", T(7))); m_Params.push_back(ParamWithName(true, &m_Pa, prefix + "hypertile1_pa"));//Precalc. m_Params.push_back(ParamWithName(true, &m_R, prefix + "hypertile1_r")); + m_Params.push_back(ParamWithName(true, &m_IP, prefix + "hypertile1_ip")); } private: @@ -3208,6 +3202,7 @@ private: T m_Q; T m_Pa;//Precalc. T m_R; + T m_IP; }; /// @@ -3232,11 +3227,11 @@ public: T d = m_R * helper.In.y; T x = (a * c + b * d); T y = (b * c - a * d); - T vr = m_Weight / (SQR(c) + SQR(d)); - T temp = rand.Rand() * m_Pa; + T vr = m_Weight / (SQR(c) + SQR(d)); + T temp = Floor(rand.Frand01() * 32767) * m_Pa; T sina = std::sin(temp); - T cosa = std::cos(temp); - helper.Out.x = vr * (x * cosa + y * sina); + T cosa = std::cos(temp); + helper.Out.x = vr * (x * cosa + y * sina); helper.Out.y = vr * (y * cosa - x * sina); helper.Out.z = DefaultZ(helper); } @@ -3260,7 +3255,7 @@ public: << "\t\treal_t x = fma(a, c, b * d);\n" << "\t\treal_t y = fma(b, c, -(a * d));\n" << "\t\treal_t vr = " << weight << " / fma(c, c, SQR(d));\n" - << "\t\treal_t temp = MwcNext(mwc) * " << pa << ";\n" + << "\t\treal_t temp = floor(MwcNext01(mwc) * 32767) * " << pa << ";\n" << "\t\treal_t sina = sin(temp);\n" << "\t\treal_t cosa = cos(temp);\n" << "\n" @@ -3272,25 +3267,20 @@ public: } virtual void Precalc() override - { - T r2 = 1 - (std::cos(2 * T(M_PI) / Zeps(m_P)) - 1) / - (std::cos(2 * T(M_PI) / Zeps(m_P)) + std::cos(2 * T(M_PI) / Zeps(m_Q))); - - if (r2 > 0) - m_R = 1 / std::sqrt(r2); - else - m_R = 1; - - m_Pa = 2 * T(M_PI) / Zeps(m_P); - } + { + m_Pa = T(M_2PI) / Zeps(m_P); + T cs = cos(m_Pa); + T r2 = T(1) - (cs - T(1)) / (cs + cos(T(M_2PI) / Zeps(m_Q))); + m_R = (r2 > 0) ? T(1) / sqrt(r2) : T(1); + } protected: void Init() { string prefix = Prefix(); m_Params.clear(); - m_Params.push_back(ParamWithName(&m_P, prefix + "hypertile2_p", 3, eParamType::INTEGER, 3, T(0x7fffffff))); - m_Params.push_back(ParamWithName(&m_Q, prefix + "hypertile2_q", 7, eParamType::INTEGER, 3, T(0x7fffffff))); + m_Params.push_back(ParamWithName(&m_P, prefix + "hypertile2_p", T(3))); + m_Params.push_back(ParamWithName(&m_Q, prefix + "hypertile2_q", T(7))); m_Params.push_back(ParamWithName(true, &m_Pa, prefix + "hypertile2_pa"));//Precalc. m_Params.push_back(ParamWithName(true, &m_R, prefix + "hypertile2_r")); }