Skip to content

Commit

Permalink
Changing random generator to speedup stochastic IIM
Browse files Browse the repository at this point in the history
  • Loading branch information
BrutPitt committed Dec 28, 2018
1 parent e42dbb5 commit 335f063
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 1,234 deletions.
Binary file modified Particles.exe
Binary file not shown.
Binary file modified Particles32.exe
Binary file not shown.
Binary file modified ParticlesLinux
Binary file not shown.
Binary file modified ParticlesOSX
Binary file not shown.
Binary file modified ParticlesViewports.exe
Binary file not shown.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -103,10 +103,11 @@ add_executable(${PROJECT_NAME}
src/libs/ImGui/imstb_truetype.h
src/libs/lodePNG/lodepng.cpp
src/libs/lodePNG/lodepng.h
src/libs/Random/random.hpp
src/libs/tinyFileDialog/tinyfiledialogs.c
src/libs/tinyFileDialog/tinyfiledialogs.h
src/libs/configuru/configuru.hpp
src/tools/fastRandom.cpp
src/tools/fastRandom.h
src/tools/imGuIZMO.cpp
src/tools/imGuIZMO.h
src/tools/imguiControls.cpp
Expand Down
Binary file modified src/msBuilds/vs2017.sln/.vs/Particles/v15/.suo
Binary file not shown.
2 changes: 2 additions & 0 deletions src/msBuilds/vs2017.sln/Particles.vcxproj
Expand Up @@ -366,6 +366,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\libs\lodePNG\lodepng.cpp" />
<ClCompile Include="..\..\src\tools\fastRandom.cpp" />
<ClCompile Include="..\..\src\tools\glslProgramObject.cpp" />
<ClCompile Include="..\..\src\tools\glslShaderObject.cpp" />
<ClCompile Include="..\..\src\attractorsBase.cpp" />
Expand Down Expand Up @@ -396,6 +397,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\libs\lodePNG\lodepng.h" />
<ClInclude Include="..\..\src\tools\fastRandom.h" />
<ClInclude Include="..\..\src\tools\glslProgramObject.h" />
<ClInclude Include="..\..\src\tools\glslShaderObject.h" />
<ClInclude Include="..\..\src\tools\imguiControls.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/msBuilds/vs2017.sln/Particles.vcxproj.filters
Expand Up @@ -128,6 +128,9 @@
<ClCompile Include="..\..\src\tools\imGuIZMO.cpp">
<Filter>Tools\imguiTools</Filter>
</ClCompile>
<ClCompile Include="..\..\src\tools\fastRandom.cpp">
<Filter>Tools</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\glApp.h">
Expand Down Expand Up @@ -235,6 +238,9 @@
<ClInclude Include="..\..\src\tools\imGuIZMO.h">
<Filter>Tools\imguiTools</Filter>
</ClInclude>
<ClInclude Include="..\..\src\tools\fastRandom.h">
<Filter>Tools</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Shaders\BillboardFrag.glsl">
Expand Down
42 changes: 34 additions & 8 deletions src/src/attractorsBase.cpp
Expand Up @@ -42,6 +42,8 @@
AttractorsClass attractorsList; // need to resolve inlines
//deque<glm::vec3> AttractorBase::stepQueue;



// Attractor base class
////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -671,7 +673,7 @@ inline void juliaBulb_IIM::Step(vec3 &v, vec3 &vp)
};

preStep(v,vp);
const int rnd = Random::get<int>(0,INT_MAX);
const int rnd = xorshift64();
radiciEq(v-((vec3 &)*kVal.data()+vec3(kRnd)), (rnd&1) ? 1.f : -1.f, (rnd&2) ? 1.f : -1.f);

}
Expand All @@ -693,7 +695,7 @@ inline void juliaBulb4th_IIM::Step(vec3 &v, vec3 &vp)
};

preStep(v,vp);
radiciEq(v-((vec3 &)*kVal.data()+vec3(kRnd)), Random::get<int>(0, INT_MAX) % degreeN, Random::get<int>(0, INT_MAX) % degreeN);
radiciEq(v-((vec3 &)*kVal.data()+vec3(kRnd)), xorshift64() % degreeN, xorshift64() % degreeN);

}

Expand All @@ -711,7 +713,7 @@ inline void BicomplexJ_IIM::Step(vec3 &v, vec3 &vp)
};

preStep(v,vp);
const int rnd = Random::get<int>(int(0),int(INT_MAX));
const int rnd = xorshift64();
radiciBicomplex(vec4(v, last4D)-((vec4 &)*kVal.data()+kRnd), (rnd&1) ? 1.f : -1.f, (rnd&2) ? 1.f : -1.f);

}
Expand All @@ -729,7 +731,7 @@ inline void BicomplexJMod0_IIM::Step(vec3 &v, vec3 &vp)
};

preStep(v,vp);
const int rnd = Random::get<int>(int(0),int(INT_MAX));
const int rnd = xorshift64();
radiciBicomplex(vec4(v, dim4D)-((vec4 &)*kVal.data()+kRnd), (rnd&1) ? 1.f : -1.f, (rnd&2) ? 1.f : -1.f);

}
Expand All @@ -748,7 +750,7 @@ inline void BicomplexJMod1_IIM::Step(vec3 &v, vec3 &vp)
};

preStep(v,vp);
const int rnd = Random::get<int>(int(0),int(INT_MAX));
const int rnd = xorshift64();
radiciBicomplex(vec4(v, last4D)-((vec4 &)*kVal.data()+kRnd), (rnd&1) ? 1.f : -1.f, (rnd&2) ? 1.f : -1.f);

}
Expand All @@ -765,17 +767,41 @@ inline void quatJulia_IIM::Step(vec3 &v, vec3 &vp)
const float r = sqrtf(xQ + yQ + zQ + wQ);
const float a = sqrtf((p.x+r)*.5);
const float b = (r-p.x) * a / (yQ + zQ + wQ);
vp = sign * vec3(a, b*p.y, b*p.z /*, b*dim4D */);
vp = sign * vec3(a, b*p.y, b*p.z );
last4D = sign * b*p.w;
};

preStep(v,vp);
const int rnd = Random::get<int>(int(0),int(INT_MAX));
const int rnd = xorshift64();
radiciEq(vec4(v, last4D)-((vec4 &)*kVal.data()+kRnd), (rnd&1) ? 1.f : -1.f);

}

/*
inline void quatJulia_IIM::Step(vec3 &v, vec3 &vp)
{ // kVal[] -> a, k
auto radiciEq = [&](const vec4 &p, float sign)
{
const float xQ = p.x * p.x, yQ = p.y * p.y, zQ = p.z * p.z, wQ = p.w * p.w;
const float r = sqrtf(xQ + yQ + zQ + wQ);
const float a = sqrtf((p.x+r)*.5);
const float b = (r-p.x) * a / (yQ + zQ + wQ);
vIter = sign * vec4(a, b*p.y, b*p.z, b*p.w);
};
preStep(v,vp);
vIter = vec4(v, last4D);
while(depth++<maxDepth) {
const int rnd = Random::get<int>(int(0),int(INT_MAX));
radiciEq(vIter-((vec4 &)*kVal.data()+kRnd), (rnd&1) ? 1.f : -1.f);
};
vp = vec3(vIter); last4D = vIter.w;
}
*/
inline void glynnJB_IIM::Step(vec3 &v, vec3 &vp)
{
//Glynn roots: {x,y,z}^(1/1.5) = {x,y,z}^(2/3)
Expand Down Expand Up @@ -850,7 +876,7 @@ inline void glynnJB_IIM::Step(vec3 &v, vec3 &vp)

preStep(v,vp);
int nRad = numRadici();
int rnd = Random::get<int>(0, INT_MAX);
int rnd = fastRandom.rnd64();
radiciEq(rnd % nRad);

}
Expand Down
44 changes: 27 additions & 17 deletions src/src/attractorsBase.h
Expand Up @@ -56,25 +56,24 @@
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>

#include "libs/configuru/configuru.hpp"

#include "libs/Random/random.hpp"
#include <configuru/configuru.hpp>

#include <fastRandom.h>
#include "attractorsStartVals.h"


//void resetVBOindexes();


using namespace glm;
using namespace std;
using namespace configuru;

using Random = effolkronium::random_static;

#define BUFFER_DIM 100

//#define RANDOM(MIN, MAX) ((MIN)+((float)rand()/(float)RAND_MAX)*((MAX)-(MIN)))
#define RANDOM(MIN, MAX) (Random::get<float>(float(MIN),float(MAX)))


class attractorDlgClass;
class AttractorsClass;
Expand Down Expand Up @@ -354,17 +353,27 @@ class fractalIIMBase : public attractorScalarK
virtual void preStep(vec3 &v, vec3 &vp) {
if(depth++>maxDepth) {
depth = 0;

last4D = dim4D + RANDOM(vMin, vMax);
v = vVal[0] + vec3(RANDOM(vMin, vMax),
RANDOM(vMin, vMax),
RANDOM(vMin, vMax));
/*
last4D = dim4D + FLOAT_RANDOM(vMin, vMax, fastRandom.SWB());
v = vVal[0] + vec3(FLOAT_RANDOM(vMin, vMax, fastRandom.SWB()),
FLOAT_RANDOM(vMin, vMax, fastRandom.SWB()),
FLOAT_RANDOM(vMin, vMax, fastRandom.SWB()));
kRnd = vec4(RANDOM(kMin, kMax),
RANDOM(kMin, kMax),
RANDOM(kMin, kMax),
RANDOM(kMin, kMax));
}
kRnd = vec4(FLOAT_RANDOM(kMin, kMax, fastRandom.SWB()),
FLOAT_RANDOM(kMin, kMax, fastRandom.SWB()),
FLOAT_RANDOM(kMin, kMax, fastRandom.SWB()),
FLOAT_RANDOM(kMin, kMax, fastRandom.SWB()));
*/
last4D = dim4D + fastRandom.floatRnd(vMin, vMax);
v = vVal[0] + vec3(fastRandom.floatRnd(vMin, vMax),
fastRandom.floatRnd(vMin, vMax),
fastRandom.floatRnd(vMin, vMax));

kRnd = vec4(fastRandom.floatRnd(kMin, kMax),
fastRandom.floatRnd(kMin, kMax),
fastRandom.floatRnd(kMin, kMax),
fastRandom.floatRnd(kMin, kMax));
}
}

// Personal vals
Expand All @@ -375,14 +384,15 @@ class fractalIIMBase : public attractorScalarK
virtual void additionalDataCtrls();

vec4 kRnd = vec4(0.f);
vec4 vIter;
std::vector<vec3> eqRoots;

int maxDepth = 50;
int degreeN = 2;
float last4D = 1;

private:
int depth = 0;
private:
};

class fractalIIM_4D : public fractalIIMBase
Expand All @@ -392,7 +402,7 @@ class fractalIIM_4D : public fractalIIMBase
int getPtSize() { return attPt4D; }

virtual void initStep() {
last4D = 0;
last4D = dim4D;
attractorScalarK::initStep();
}

Expand Down

0 comments on commit 335f063

Please sign in to comment.