From 2c4fb3b72d683d25fa69a39334cb981a87e439b1 Mon Sep 17 00:00:00 2001 From: Person Date: Tue, 11 Jun 2019 19:19:20 -0700 Subject: [PATCH] --User changes -Add inkdrop variation. --- Source/Ember/Ember.cpp | 1 + Source/Ember/Variation.h | 3 ++ Source/Ember/VariationList.cpp | 1 + Source/Ember/Variations07.h | 85 ++++++++++++++++++++++++++++++ Source/EmberCommon/EmberCommon.h | 5 +- Source/EmberTester/EmberTester.cpp | 23 ++++++++ 6 files changed, 116 insertions(+), 2 deletions(-) diff --git a/Source/Ember/Ember.cpp b/Source/Ember/Ember.cpp index f12c822..8acf510 100644 --- a/Source/Ember/Ember.cpp +++ b/Source/Ember/Ember.cpp @@ -490,6 +490,7 @@ uint Timing::m_ProcessorCount; EXPORTPREPOSTREGVAR(Waves3, T) \ EXPORTPREPOSTREGVAR(Waves4, T) \ EXPORTPREPOSTREGVAR(Gnarly, T) \ + EXPORTPREPOSTREGVAR(Inkdrop, T) \ template EMBER_API class VariationList; \ template EMBER_API class SpatialFilter; \ template EMBER_API class GaussianFilter; \ diff --git a/Source/Ember/Variation.h b/Source/Ember/Variation.h index 1ea0f88..d52d4ab 100644 --- a/Source/Ember/Variation.h +++ b/Source/Ember/Variation.h @@ -241,6 +241,7 @@ enum class eVariationId : et VAR_HYPERTILE3D1, VAR_HYPERTILE3D2, VAR_IDISC , + VAR_INKDROP, VAR_INTERFERENCE2, VAR_JAC_CN , VAR_JAC_DN , @@ -656,6 +657,7 @@ enum class eVariationId : et VAR_PRE_HYPERTILE3D1, VAR_PRE_HYPERTILE3D2, VAR_PRE_IDISC, + VAR_PRE_INKDROP, VAR_PRE_INTERFERENCE2, VAR_PRE_JAC_CN, VAR_PRE_JAC_DN, @@ -1070,6 +1072,7 @@ enum class eVariationId : et VAR_POST_HYPERTILE3D1, VAR_POST_HYPERTILE3D2, VAR_POST_IDISC, + VAR_POST_INKDROP, VAR_POST_INTERFERENCE2, VAR_POST_JAC_CN, VAR_POST_JAC_DN, diff --git a/Source/Ember/VariationList.cpp b/Source/Ember/VariationList.cpp index 1ef167a..5e10a63 100644 --- a/Source/Ember/VariationList.cpp +++ b/Source/Ember/VariationList.cpp @@ -430,6 +430,7 @@ VariationList::VariationList() ADDPREPOSTREGVAR(Waves4) ADDPREPOSTREGVAR(Waves42) ADDPREPOSTREGVAR(Gnarly) + ADDPREPOSTREGVAR(Inkdrop) //ADDPREPOSTREGVAR(LinearXZ) //ADDPREPOSTREGVAR(LinearYZ) //DC are special. diff --git a/Source/Ember/Variations07.h b/Source/Ember/Variations07.h index 45970df..a74839c 100644 --- a/Source/Ember/Variations07.h +++ b/Source/Ember/Variations07.h @@ -7187,6 +7187,90 @@ private: T m_R2;//Precalc. }; +/// +/// inkdrop by Jess. +/// +template +class InkdropVariation : public ParametricVariation +{ +public: + InkdropVariation(T weight = 1.0) : ParametricVariation("inkdrop", eVariationId::VAR_INKDROP, weight) + { + Init(); + } + + PARVARCOPY(InkdropVariation) + + virtual void Func(IteratorHelper& helper, Point& outPoint, QTIsaac& rand) override + { + T distx = helper.In.x - m_X; + T disty = helper.In.y - m_Y; + T dist2 = SQR(distx) + SQR(disty); + T adjust = std::sqrt(dist2 + m_Rad2) - std::sqrt(dist2); + T bearing = std::atan2(disty, distx); + T x = helper.In.x + (std::cos(bearing) * adjust); + T y = helper.In.y + (std::sin(bearing) * adjust); + helper.Out.x = m_Weight * x; + helper.Out.y = m_Weight * y; + helper.Out.z = DefaultZ(helper); + } + + virtual string OpenCLString() const override + { + ostringstream ss, ss2; + intmax_t i = 0, varIndex = IndexInXform(); + ss2 << "_" << XformIndexInEmber() << "]"; + string index = ss2.str(); + string weight = WeightDefineString(); + string r = "parVars[" + ToUpper(m_Params[i++].Name()) + index; + string x = "parVars[" + ToUpper(m_Params[i++].Name()) + index; + string y = "parVars[" + ToUpper(m_Params[i++].Name()) + index; + string rad2 = "parVars[" + ToUpper(m_Params[i++].Name()) + index; + ss << "\t{\n" + << "\t\treal_t distx = vIn.x - " << x << ";\n" + << "\t\treal_t disty = vIn.y - " << y << ";\n" + << "\t\treal_t dist2 = SQR(distx) + SQR(disty);\n" + << "\t\treal_t adjust = sqrt(dist2 + " << rad2 << ") - sqrt(dist2);\n" + << "\n" + << "\t\treal_t bearing = atan2(disty, distx);\n" + << "\t\treal_t x = fma(cos(bearing), adjust, vIn.x);\n" + << "\t\treal_t y = fma(sin(bearing), adjust, vIn.y);\n" + << "\n" + << "\t\tvOut.x = " << weight << " * x;\n" + << "\t\tvOut.y = " << weight << " * y;\n" + << "\t\tvOut.z = " << DefaultZCl() + << "\t}\n"; + return ss.str(); + } + + virtual void Precalc() override + { + m_Rad2 = SQR(m_R); + } + + virtual vector OpenCLGlobalFuncNames() const override + { + return vector { "Zeps" }; + } + +protected: + void Init() + { + string prefix = Prefix(); + m_Params.clear(); + m_Params.push_back(ParamWithName(&m_R, prefix + "inkdrop_r", T(0.5), eParamType::REAL, 0)); + m_Params.push_back(ParamWithName(&m_X, prefix + "inkdrop_x")); + m_Params.push_back(ParamWithName(&m_Y, prefix + "inkdrop_y")); + m_Params.push_back(ParamWithName(true, &m_Rad2, prefix + "inkdrop_rad2"));//Precalc. + } + +private: + T m_R; + T m_X; + T m_Y; + T m_Rad2;//Precalc. +}; + MAKEPREPOSTPARVAR(Splits3D, splits3D, SPLITS3D) MAKEPREPOSTPARVAR(Waves2B, waves2b, WAVES2B) MAKEPREPOSTPARVAR(JacCn, jac_cn, JAC_CN) @@ -7256,4 +7340,5 @@ MAKEPREPOSTPARVAR(Waves42, waves42, WAVES42) MAKEPREPOSTPARVAR(Waves3, waves3, WAVES3) MAKEPREPOSTPARVAR(Waves4, waves4, WAVES4) MAKEPREPOSTPARVAR(Gnarly, gnarly, GNARLY) +MAKEPREPOSTPARVAR(Inkdrop, inkdrop, INKDROP) } diff --git a/Source/EmberCommon/EmberCommon.h b/Source/EmberCommon/EmberCommon.h index 1005207..2eb6c1d 100644 --- a/Source/EmberCommon/EmberCommon.h +++ b/Source/EmberCommon/EmberCommon.h @@ -744,16 +744,17 @@ bool SearchVar(const Variation* var, const vector& stringVec, bool ma /// The vector of variation pointers to search /// The vector of strings to search for /// True to find all variations which match any strings, false to break after the first match is found. +/// True to find all variations which match all strings, false to stop searching a variation after the first match succeeds. /// A vector of pointers to variations whose OpenCL string matched at least one string in stringVec template -static vector*> FindVarsWith(const vector*>& vars, const vector& stringVec, bool findAll = true) +static vector*> FindVarsWith(const vector*>& vars, const vector& stringVec, bool findAll = true, bool matchAll = false) { vector*> vec; auto vl = VariationList::Instance(); for (auto& v : vars) { - if (SearchVar(v, stringVec, false)) + if (SearchVar(v, stringVec, matchAll)) { vec.push_back(v); diff --git a/Source/EmberTester/EmberTester.cpp b/Source/EmberTester/EmberTester.cpp index 40fc567..d60203a 100644 --- a/Source/EmberTester/EmberTester.cpp +++ b/Source/EmberTester/EmberTester.cpp @@ -1583,6 +1583,26 @@ void TestOperations() } } +void TestArbitrary() +{ + vector stringVec; + auto varList = VariationList::Instance(); + auto& vars = varList->AllVars(); + stringVec.push_back(" = vIn.x - "); + stringVec.push_back(" = vIn.y - "); + stringVec.push_back("sqrt("); + stringVec.push_back("atan2("); + stringVec.push_back("sin("); + stringVec.push_back("cos("); + //stringVec.push_back("sincos("); + auto varVec = FindVarsWith(vars, stringVec, true, true); + + for (auto& it : varVec) + { + cout << "Variation " << it->Name() << " contained the desired strings." << endl; + } +} + template void TestVarsSimilar() { @@ -2448,6 +2468,9 @@ int _tmain(int argc, _TCHAR* argv[]) t.Tic(); TestOperations(); t.Toc("TestOperations()"); + t.Tic(); + TestArbitrary(); + t.Toc("TestArbitrary()"); //t.Tic(); //TestVarsSimilar(); //t.Toc("TestVarsSimilar()");