mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-06-30 21:36:33 -04:00
--User changes
-Add new variations: crackle, dc_perlin. -Make default palette interp mode be linear instead of step. -Make summary tab the selected one in the Info tab. -Allow for highlight power of up to 10. It was previously limited to 2. --Bug fixes -Direct color calculations were wrong. -Flattening was not applied to final xform. -Fix "pure virtual function call" error on shutdown. --Code changes -Allow for array precalc params in variations by adding a size member to the ParamWithName class. -In IterOpenCLKernelCreator, memcpy precalc params instead of a direct assign since they can now be of variable length. -Add new file VarFuncs to consolidate some functions that are common to multiple variations. This also contains texture data for crackle and dc_perlin. -Place OpenCL versions of these functions in the FunctionMapper class in the EmberCL project. -Add new Singleton class that uses CRTP, is thread safe, and deletes after the last reference goes away. This fixes the usual "delete after main()" problem with singletons that use the static local function variable pattern. -Began saving files with AStyle autoformatter turned on. This will eventually touch all files as they are worked on. -Add missing backslash to CUDA include and library paths for builds on Nvidia systems. -Add missing gl.h include for Windows. -Remove glew include paths from Fractorium, it's not used. -Remove any Nvidia specific #defines and build targets, they are no longer needed with OpenCL 1.2. -Fix bad paths on linux build. -General cleanup.
This commit is contained in:
@ -24,11 +24,9 @@ public:
|
||||
T r = helper.m_PrecalcSumSquares;
|
||||
T r4_1 = Zeps(r / 4 + 1);
|
||||
r4_1 = m_Weight / r4_1;
|
||||
|
||||
helper.Out.x = r4_1 * helper.In.x;
|
||||
helper.Out.y = r4_1 * helper.In.y;
|
||||
helper.Out.z = m_Weight * (2 / r4_1 - 1);
|
||||
|
||||
T sumX, sumY;
|
||||
|
||||
if (m_VarType == VARTYPE_PRE)
|
||||
@ -44,7 +42,6 @@ public:
|
||||
|
||||
T tempX = helper.Out.x + sumX;
|
||||
T tempY = helper.Out.y + sumY;
|
||||
|
||||
outPoint.m_ColorX = fmod(fabs(m_Bdcs * (Sqr<T>(tempX + m_CenterX) + Sqr<T>(tempY + m_CenterY))), T(1.0));
|
||||
}
|
||||
|
||||
@ -58,7 +55,6 @@ public:
|
||||
string centerX = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string centerY = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string bdcs = "parVars[" + ToUpper(m_Params[i++].Name()) + index;//Precalc.
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\treal_t r = precalcSumSquares;\n"
|
||||
<< "\t\treal_t r4_1 = Zeps(r / 4 + 1);\n"
|
||||
@ -73,23 +69,22 @@ public:
|
||||
if (m_VarType == VARTYPE_PRE)
|
||||
{
|
||||
ss
|
||||
<< "\t\tsumX = vIn.x;\n"
|
||||
<< "\t\tsumY = vIn.y;\n";
|
||||
<< "\t\tsumX = vIn.x;\n"
|
||||
<< "\t\tsumY = vIn.y;\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
ss
|
||||
<< "\t\tsumX = outPoint->m_X;\n"
|
||||
<< "\t\tsumY = outPoint->m_Y;\n";
|
||||
<< "\t\tsumX = outPoint->m_X;\n"
|
||||
<< "\t\tsumY = outPoint->m_Y;\n";
|
||||
}
|
||||
|
||||
ss
|
||||
<< "\t\treal_t tempX = vOut.x + sumX;\n"
|
||||
<< "\t\treal_t tempY = vOut.y + sumY;\n"
|
||||
<< "\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs(" << bdcs << " * (Sqr(tempX + " << centerX << ") + Sqr(tempY + " << centerY << "))), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
|
||||
<< "\t\treal_t tempX = vOut.x + sumX;\n"
|
||||
<< "\t\treal_t tempY = vOut.y + sumY;\n"
|
||||
<< "\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs(" << bdcs << " * (Sqr(tempX + " << centerX << ") + Sqr(tempY + " << centerY << "))), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -107,7 +102,6 @@ protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
|
||||
m_Params.clear();
|
||||
m_Params.push_back(ParamWithName<T>(&m_CenterX, prefix + "dc_bubble_centerx"));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(&m_CenterY, prefix + "dc_bubble_centery"));
|
||||
@ -144,7 +138,6 @@ public:
|
||||
T y = helper.In.y + y0;
|
||||
T x0_xor_y0 = T(x0 ^ y0);
|
||||
T h = -m_H + (1 - x0_xor_y0) * m_H;
|
||||
|
||||
helper.Out.x = m_Weight * (m_Xform->m_Affine.A() * x + m_Xform->m_Affine.B() * y + m_Xform->m_Affine.E());
|
||||
helper.Out.y = m_Weight * (m_Xform->m_Affine.C() * x + m_Xform->m_Affine.D() * y + m_Xform->m_Affine.F());
|
||||
helper.Out.z = (m_VarType == VARTYPE_REG) ? 0 : helper.In.z;
|
||||
@ -159,7 +152,6 @@ public:
|
||||
string index = ss2.str();
|
||||
string origin = "parVars[" + ToUpper(m_Params[i++].Name()) + index;//Params.
|
||||
string h = "parVars[" + ToUpper(m_Params[i++].Name()) + index;//Precalc.
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\tint x0 = (MwcNext(mwc) & 1) ? -1 : 1;\n"
|
||||
<< "\t\tint y0 = (MwcNext(mwc) & 1) ? -1 : 1;\n"
|
||||
@ -173,7 +165,6 @@ public:
|
||||
<< "\t\tvOut.z = " << ((m_VarType == VARTYPE_REG) ? "0" : "vIn.z") << ";\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs(outPoint->m_ColorX * (real_t)(0.5) * (1 + h) + x0_xor_y0 * (1 - h) * (real_t)(0.5)), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -186,7 +177,6 @@ protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
|
||||
m_Params.clear();
|
||||
m_Params.push_back(ParamWithName<T>(&m_Origin, prefix + "dc_carpet_origin"));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(true, &m_H, prefix + "dc_carpet_h"));//Precalc.
|
||||
@ -232,6 +222,7 @@ public:
|
||||
outPoint.m_ColorX = m_ClampC2;
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
x = m_Weight * p;
|
||||
y = m_Weight * (j ? -1 : 1);
|
||||
@ -243,6 +234,7 @@ public:
|
||||
outPoint.m_ColorX = m_ClampC4;
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
default:
|
||||
x = m_Weight * p;
|
||||
@ -283,7 +275,6 @@ public:
|
||||
string clampC4 = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string clampC5 = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string clampC6 = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\treal_t x, y, z;\n"
|
||||
<< "\t\treal_t p = 2 * MwcNext01(mwc) - 1;\n"
|
||||
@ -332,7 +323,6 @@ public:
|
||||
<< "\t\tvOut.y = y * " << cubeY << ";\n"
|
||||
<< "\t\tvOut.z = z * " << cubeZ << ";\n"
|
||||
<< "\t}\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -350,7 +340,6 @@ protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
|
||||
m_Params.clear();
|
||||
m_Params.push_back(ParamWithName<T>(&m_DcCubeC1, prefix + "dc_cube_c1"));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(&m_DcCubeC2, prefix + "dc_cube_c2"));
|
||||
@ -408,11 +397,9 @@ public:
|
||||
T sr = std::sin(temp);
|
||||
T cr = std::cos(temp);
|
||||
T r = m_Blur * (rand.Frand01<T>() + rand.Frand01<T>() + rand.Frand01<T>() + rand.Frand01<T>() - 2);
|
||||
|
||||
helper.Out.x = m_Weight * std::sin(helper.In.x + r * sr) * m_X;
|
||||
helper.Out.y = r + helper.In.y * m_Y;
|
||||
helper.Out.z = m_Weight * std::cos(helper.In.x + r * cr);
|
||||
|
||||
T sumX, sumY;
|
||||
|
||||
if (m_VarType == VARTYPE_PRE)
|
||||
@ -428,7 +415,6 @@ public:
|
||||
|
||||
T tempX = helper.Out.x + sumX;
|
||||
T tempY = helper.Out.y + sumY;
|
||||
|
||||
outPoint.m_ColorX = fmod(fabs(T(0.5) * (m_Ldcs * ((m_Cosa * tempX + m_Sina * tempY + m_Offset)) + 1)), T(1.0));
|
||||
}
|
||||
|
||||
@ -448,7 +434,6 @@ public:
|
||||
string cosa = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string ldcs = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string ldca = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\treal_t temp = MwcNext(mwc) * M_2PI;\n"
|
||||
<< "\t\treal_t sr = sin(temp);\n"
|
||||
@ -463,23 +448,22 @@ public:
|
||||
if (m_VarType == VARTYPE_PRE)
|
||||
{
|
||||
ss
|
||||
<< "\t\tsumX = vIn.x;\n"
|
||||
<< "\t\tsumY = vIn.y;\n";
|
||||
<< "\t\tsumX = vIn.x;\n"
|
||||
<< "\t\tsumY = vIn.y;\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
ss
|
||||
<< "\t\tsumX = outPoint->m_X;\n"
|
||||
<< "\t\tsumY = outPoint->m_Y;\n";
|
||||
<< "\t\tsumX = outPoint->m_X;\n"
|
||||
<< "\t\tsumY = outPoint->m_Y;\n";
|
||||
}
|
||||
|
||||
ss
|
||||
<< "\t\treal_t tempX = vOut.x + sumX;\n"
|
||||
<< "\t\treal_t tempY = vOut.y + sumY;\n"
|
||||
<< "\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs((real_t)(0.5) * (" << ldcs << " * ((" << cosa << " * tempX + " << sina << " * tempY + " << offset << ")) + (real_t)(1.0))), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
|
||||
<< "\t\treal_t tempX = vOut.x + sumX;\n"
|
||||
<< "\t\treal_t tempY = vOut.y + sumY;\n"
|
||||
<< "\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs((real_t)(0.5) * (" << ldcs << " * ((" << cosa << " * tempX + " << sina << " * tempY + " << offset << ")) + (real_t)(1.0))), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -494,7 +478,6 @@ protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
|
||||
m_Params.clear();
|
||||
m_Params.push_back(ParamWithName<T>(&m_Offset, prefix + "dc_cylinder_offset"));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(&m_Angle, prefix + "dc_cylinder_angle"));//Original used a prefix of dc_cyl_, which is incompatible with Ember's design.
|
||||
@ -613,7 +596,6 @@ public:
|
||||
{
|
||||
ostringstream ss;
|
||||
intmax_t varIndex = IndexInXform();
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\treal_t x = LRint(vIn.x);\n"
|
||||
<< "\t\treal_t y = LRint(vIn.y);\n"
|
||||
@ -689,7 +671,6 @@ public:
|
||||
<< "\t\tvOut.z = xform->m_VariationWeights[" << varIndex << "] * vIn.z;\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(c, (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -719,7 +700,6 @@ public:
|
||||
helper.Out.x = m_Weight * helper.In.x;
|
||||
helper.Out.y = m_Weight * helper.In.y;
|
||||
helper.Out.z = m_Weight * helper.In.z;
|
||||
|
||||
T sumX, sumY;
|
||||
|
||||
if (m_VarType == VARTYPE_PRE)
|
||||
@ -735,7 +715,6 @@ public:
|
||||
|
||||
T tempX = helper.Out.x + sumX;
|
||||
T tempY = helper.Out.y + sumY;
|
||||
|
||||
outPoint.m_ColorX = fmod(fabs(T(0.5) * (m_Ldcs * ((m_Cosa * tempX + m_Sina * tempY + m_Offset)) + T(1.0))), T(1.0));
|
||||
}
|
||||
|
||||
@ -752,7 +731,6 @@ public:
|
||||
string ldca = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string sina = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string cosa = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\tvOut.x = xform->m_VariationWeights[" << varIndex << "] * vIn.x;\n"
|
||||
<< "\t\tvOut.y = xform->m_VariationWeights[" << varIndex << "] * vIn.y;\n"
|
||||
@ -763,23 +741,22 @@ public:
|
||||
if (m_VarType == VARTYPE_PRE)
|
||||
{
|
||||
ss
|
||||
<< "\t\tsumX = vIn.x;\n"
|
||||
<< "\t\tsumY = vIn.y;\n";
|
||||
<< "\t\tsumX = vIn.x;\n"
|
||||
<< "\t\tsumY = vIn.y;\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
ss
|
||||
<< "\t\tsumX = outPoint->m_X;\n"
|
||||
<< "\t\tsumY = outPoint->m_Y;\n";
|
||||
<< "\t\tsumX = outPoint->m_X;\n"
|
||||
<< "\t\tsumY = outPoint->m_Y;\n";
|
||||
}
|
||||
|
||||
ss
|
||||
<< "\t\treal_t tempX = vOut.x + sumX;\n"
|
||||
<< "\t\treal_t tempY = vOut.y + sumY;\n"
|
||||
<< "\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs((real_t)(0.5) * (" << ldcs << " * ((" << cosa << " * tempX + " << sina << " * tempY + " << offset << ")) + (real_t)(1.0))), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
|
||||
<< "\t\treal_t tempX = vOut.x + sumX;\n"
|
||||
<< "\t\treal_t tempY = vOut.y + sumY;\n"
|
||||
<< "\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs((real_t)(0.5) * (" << ldcs << " * ((" << cosa << " * tempX + " << sina << " * tempY + " << offset << ")) + (real_t)(1.0))), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -794,7 +771,6 @@ protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
|
||||
m_Params.clear();
|
||||
m_Params.push_back(ParamWithName<T>(&m_Offset, prefix + "dc_linear_offset"));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(&m_Angle, prefix + "dc_linear_angle"));
|
||||
@ -837,19 +813,16 @@ public:
|
||||
yx = m_Xform->m_Affine.C() * -1, yy = m_Xform->m_Affine.D() * -1, // Y
|
||||
ox = m_Xform->m_Affine.E(), oy = m_Xform->m_Affine.F(), // O
|
||||
px = helper.In.x - ox, py = helper.In.y - oy; // P
|
||||
|
||||
// calculate dot products
|
||||
const T dot00 = xx * xx + xy * xy; // X * X
|
||||
const T dot01 = xx * yx + xy * yy; // X * Y
|
||||
const T dot02 = xx * px + xy * py; // X * P
|
||||
const T dot11 = yx * yx + yy * yy; // Y * Y
|
||||
const T dot12 = yx * px + yy * py; // Y * P
|
||||
|
||||
// calculate barycentric coordinates
|
||||
const T denom = (dot00 * dot11 - dot01 * dot01);
|
||||
const T num_u = (dot11 * dot02 - dot01 * dot12);
|
||||
const T num_v = (dot00 * dot12 - dot01 * dot02);
|
||||
|
||||
// u, v must not be constant
|
||||
T u = num_u / denom;
|
||||
T v = num_v / denom;
|
||||
@ -890,7 +863,6 @@ public:
|
||||
{
|
||||
u = (u + rand.Frand01<T>() * m_A * f);
|
||||
v = (v + rand.Frand01<T>() * m_A * f);
|
||||
|
||||
ClampRef<T>(u, -1, 1);
|
||||
ClampRef<T>(v, -1, 1);
|
||||
|
||||
@ -925,7 +897,6 @@ public:
|
||||
string scatterArea = "parVars[" + ToUpper(m_Params[i++].Name()) + index;//Params.
|
||||
string zeroEdges = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string a = "parVars[" + ToUpper(m_Params[i++].Name()) + index;//Precalc.
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\tconst real_t\n"
|
||||
<< "\t\txx = xform->m_A, xy = xform->m_B,\n"
|
||||
@ -1003,7 +974,6 @@ public:
|
||||
<< "\t\tvOut.z = xform->m_VariationWeights[" << varIndex << "] * vIn.z;\n"
|
||||
<< "\t\toutPoint->m_ColorX = fmod(fabs(u + v), (real_t)(1.0));\n"
|
||||
<< "\t}\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -1016,7 +986,6 @@ protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
|
||||
m_Params.clear();
|
||||
m_Params.push_back(ParamWithName<T>(&m_ScatterArea, prefix + "dc_triangle_scatter_area", 0, REAL, -1, 1));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(&m_ZeroEdges, prefix + "dc_triangle_zero_edges", 0, INTEGER, 0, 1));
|
||||
@ -1075,7 +1044,6 @@ public:
|
||||
string x0_ = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string x1_ = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string x1_m_x0 = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
|
||||
ss << "\t{\n"
|
||||
<< "\t\treal_t zf = " << factor << " * (outPoint->m_ColorX - " << x0_ << ") / " << x1_m_x0 << ";\n"
|
||||
<< "\n"
|
||||
@ -1090,7 +1058,6 @@ public:
|
||||
<< "\t\telse\n"
|
||||
<< "\t\t vOut.z = xform->m_VariationWeights[" << varIndex << "] * zf;\n"
|
||||
<< "\t}\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -1105,7 +1072,6 @@ protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
|
||||
m_Params.clear();
|
||||
m_Params.push_back(ParamWithName<T>(&m_X0, prefix + "dc_ztransl_x0", 0, REAL, 0, 1));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(&m_X1, prefix + "dc_ztransl_x1", 1, REAL, 0, 1));
|
||||
@ -1128,6 +1094,363 @@ private:
|
||||
T m_X1_m_x0;
|
||||
};
|
||||
|
||||
#define SHAPE_SQUARE 0
|
||||
#define SHAPE_DISC 1
|
||||
#define SHAPE_BLUR 2
|
||||
|
||||
#define MAP_FLAT 0
|
||||
#define MAP_SPHERICAL 1
|
||||
#define MAP_HSPHERE 2
|
||||
#define MAP_QSPHERE 3
|
||||
#define MAP_BUBBLE 4
|
||||
#define MAP_BUBBLE2 5
|
||||
|
||||
/// <summary>
|
||||
/// dc_perlin.
|
||||
/// </summary>
|
||||
template <typename T>
|
||||
class EMBER_API DCPerlinVariation : public ParametricVariation <T>
|
||||
{
|
||||
public:
|
||||
DCPerlinVariation(T weight = 1.0) : ParametricVariation<T>("dc_perlin", VAR_DC_PERLIN, weight)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
PARVARCOPY(DCPerlinVariation)
|
||||
|
||||
virtual void Func(IteratorHelper<T>& helper, Point<T>& outPoint, QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override
|
||||
{
|
||||
v3T v;
|
||||
T vx, vy, col, r, theta, s, c, p, e;
|
||||
int t = 0, iShape = int(m_Shape), iMap = int(m_Map), iOctaves = int(m_Octaves), iBailout = int(m_SelectBailout);
|
||||
|
||||
do
|
||||
{
|
||||
// Default edge value
|
||||
e = 0;
|
||||
|
||||
// Assign vx, vy according to shape
|
||||
switch (iShape)
|
||||
{
|
||||
case SHAPE_SQUARE:
|
||||
vx = (1 + m_Edge) * (rand.Frand01<T>() - T(0.5));
|
||||
vy = (1 + m_Edge) * (rand.Frand01<T>() - T(0.5));
|
||||
r = SQR(vx) > SQR(vy) ? std::sqrt(SQR(vx)) : std::sqrt(SQR(vy));
|
||||
|
||||
if (r > 1 - m_Edge)
|
||||
e = T(0.5) * (r - 1 + m_Edge) / m_Edge;
|
||||
|
||||
break;
|
||||
|
||||
case SHAPE_DISC:
|
||||
r = rand.Frand01<T>() + rand.Frand01<T>();
|
||||
r = (r > 1) ? 2 - r : r;
|
||||
r *= (1 + m_Edge);
|
||||
|
||||
if (r > 1 - m_Edge)
|
||||
e = T(0.5) * (r - 1 + m_Edge) / m_Edge;
|
||||
|
||||
theta = rand.Frand01<T>() * M_2PI;
|
||||
sincos(theta, &s, &c);
|
||||
vx = T(0.5) * r * s;
|
||||
vy = T(0.5) * r * c;
|
||||
break;
|
||||
|
||||
case SHAPE_BLUR:
|
||||
default:
|
||||
r = (1 + m_Edge) * rand.Frand01<T>();
|
||||
|
||||
if (r > 1 - m_Edge)
|
||||
e = T(0.5) * (r - 1 + m_Edge) / m_Edge;
|
||||
|
||||
theta = rand.Frand01<T>() * M_2PI;
|
||||
sincos(theta, &s, &c);
|
||||
vx = T(0.5) * r * s;
|
||||
vy = T(0.5) * r * c;
|
||||
break;
|
||||
}
|
||||
|
||||
// Assign V for noise vector position according to map
|
||||
switch (iMap)
|
||||
{
|
||||
case MAP_FLAT:
|
||||
v.x = m_Scale * vx;
|
||||
v.y = m_Scale * vy;
|
||||
v.z = m_Scale * m_Z;
|
||||
break;
|
||||
|
||||
case MAP_SPHERICAL:
|
||||
r = 1 / Zeps<T>(SQR(vx) + SQR(vy));
|
||||
v.x = m_Scale * vx * r;
|
||||
v.y = m_Scale * vy * r;
|
||||
v.z = m_Scale * m_Z;
|
||||
break;
|
||||
|
||||
case MAP_HSPHERE:
|
||||
r = 1 / (SQR(vx) + SQR(vy) + T(0.5));
|
||||
v.x = m_Scale * vx * r;
|
||||
v.y = m_Scale * vy * r;
|
||||
v.z = m_Scale * m_Z;
|
||||
break;
|
||||
|
||||
case MAP_QSPHERE:
|
||||
r = 1 / (SQR(vx) + SQR(vy) + T(0.25));
|
||||
v.x = m_Scale * vx * r;
|
||||
v.y = m_Scale * vy * r;
|
||||
v.z = m_Scale * m_Z;
|
||||
break;
|
||||
|
||||
case MAP_BUBBLE:
|
||||
r = T(0.25) - (SQR(vx) + SQR(vy));
|
||||
|
||||
if (r < 0)
|
||||
r = std::sqrt(-r);
|
||||
else
|
||||
r = std::sqrt(r);
|
||||
|
||||
v.x = m_Scale * vx;
|
||||
v.y = m_Scale * vy;
|
||||
v.z = m_Scale * (r + m_Z);
|
||||
break;
|
||||
|
||||
case MAP_BUBBLE2:
|
||||
default:
|
||||
r = T(0.25) - (SQR(vx) + SQR(vy));
|
||||
|
||||
if (r < 0)
|
||||
r = std::sqrt(-r);
|
||||
else
|
||||
r = std::sqrt(r);
|
||||
|
||||
v.x = m_Scale * vx;
|
||||
v.y = m_Scale * vy;
|
||||
v.z = m_Scale * (2 * r + m_Z);
|
||||
break;
|
||||
}
|
||||
|
||||
p = m_VarFuncs->PerlinNoise3D(v, m_Amps, m_Freqs, iOctaves);
|
||||
|
||||
// Add edge effects
|
||||
if (p > 0)
|
||||
e = p * (1 + e * e * 20) + 2 * e;
|
||||
else
|
||||
e = p * (1 + e * e * 20) - 2 * e;
|
||||
}
|
||||
while ((e < m_NotchBottom || e > m_NotchTop) && t++ < iBailout);
|
||||
|
||||
// Add blur effect to transform
|
||||
helper.Out.x = m_Weight * vx;
|
||||
helper.Out.y = m_Weight * vy;
|
||||
helper.Out.z = (m_VarType == VARTYPE_REG) ? 0 : helper.In.z;
|
||||
col = m_Centre + m_Range * p;
|
||||
outPoint.m_ColorX = col - Floor<T>(col);
|
||||
}
|
||||
|
||||
virtual vector<string> OpenCLGlobalFuncNames() const override
|
||||
{
|
||||
return vector<string> { "Zeps", "SimplexNoise3D", "PerlinNoise3D" };
|
||||
}
|
||||
|
||||
virtual vector<string> OpenCLGlobalDataNames() const override
|
||||
{
|
||||
return vector<string> { "NOISE_INDEX", "NOISE_POINTS" };
|
||||
}
|
||||
|
||||
virtual string OpenCLString() const override
|
||||
{
|
||||
ostringstream ss, ss2;
|
||||
intmax_t i = 0, varIndex = IndexInXform();
|
||||
ss2 << "_" << XformIndexInEmber();
|
||||
string index = ss2.str() + "]";
|
||||
string shape = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string map = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string selectCentre = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string selectRange = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string centre = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string range = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string edge = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string scale = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string octaves = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string amps = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string freqs = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string z = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string selectBailout = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string notchBottom = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
string notchTop = "parVars[" + ToUpper(m_Params[i++].Name()) + index;
|
||||
ss << "\t{\n"
|
||||
<< "\t\treal3 v;\n"
|
||||
<< "\t\treal_t vx, vy, col, r, theta, s, c, p, e;\n"
|
||||
<< "\t\tint t = 0, iShape = (int)" << shape << ", iMap = (int)" << map << ", iOctaves = (int)" << octaves << ", iBailout = (int)" << selectBailout << ";\n"
|
||||
<< "\n"
|
||||
<< "\t\tdo\n"
|
||||
<< "\t\t{\n"
|
||||
<< "\t\t e = 0;\n"
|
||||
<< "\n"
|
||||
<< "\t\t switch (iShape)\n"
|
||||
<< "\t\t {\n"
|
||||
<< "\t\t case " << SHAPE_SQUARE << ": \n"
|
||||
<< "\t\t vx = (1 + " << edge << ") * (MwcNext01(mwc) - 0.5); \n"
|
||||
<< "\t\t vy = (1 + " << edge << ") * (MwcNext01(mwc) - 0.5); \n"
|
||||
<< "\t\t r = SQR(vx) > SQR(vy) ? sqrt(SQR(vx)) : sqrt(SQR(vy)); \n"
|
||||
<< "\n"
|
||||
<< "\t\t if (r > 1 - " << edge << ")\n"
|
||||
<< "\t\t e = 0.5 * (r - 1 + " << edge << ") / " << edge << "; \n"
|
||||
<< "\n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\n"
|
||||
<< "\t\t case " << SHAPE_DISC << ": \n"
|
||||
<< "\t\t r = MwcNext01(mwc) + MwcNext01(mwc); \n"
|
||||
<< "\t\t r = (r > 1) ? 2 - r : r; \n"
|
||||
<< "\t\t r *= (1 + " << edge << "); \n"
|
||||
<< "\n"
|
||||
<< "\t\t if (r > 1 - " << edge << ")\n"
|
||||
<< "\t\t e = 0.5 * (r - 1 + " << edge << ") / " << edge << "; \n"
|
||||
<< "\n"
|
||||
<< "\t\t theta = MwcNext01(mwc) * M_2PI; \n"
|
||||
<< "\t\t s = sincos(theta, &c); \n"
|
||||
<< "\t\t vx = 0.5 * r * s; \n"
|
||||
<< "\t\t vy = 0.5 * r * c; \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\n"
|
||||
<< "\t\t case " << SHAPE_BLUR << ": \n"
|
||||
<< "\t\t r = (1 + " << edge << ") * MwcNext01(mwc); \n"
|
||||
<< "\n"
|
||||
<< "\t\t if (r > 1 - " << edge << ")\n"
|
||||
<< "\t\t e = 0.5 * (r - 1 + " << edge << ") / " << edge << "; \n"
|
||||
<< "\n"
|
||||
<< "\t\t theta = MwcNext01(mwc) * M_2PI; \n"
|
||||
<< "\t\t s = sincos(theta, &c); \n"
|
||||
<< "\t\t vx = 0.5 * r * s; \n"
|
||||
<< "\t\t vy = 0.5 * r * c; \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\t\t }\n"
|
||||
<< "\n"
|
||||
<< "\t\t switch (iMap)\n"
|
||||
<< "\t\t {\n"
|
||||
<< "\t\t case " << MAP_FLAT << ": \n"
|
||||
<< "\t\t v.x = " << scale << " * vx; \n"
|
||||
<< "\t\t v.y = " << scale << " * vy; \n"
|
||||
<< "\t\t v.z = " << scale << " * " << z << "; \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\n"
|
||||
<< "\t\t case " << MAP_SPHERICAL << ": \n"
|
||||
<< "\t\t r = 1 / Zeps(SQR(vx) + SQR(vy)); \n"
|
||||
<< "\t\t v.x = " << scale << " * vx * r; \n"
|
||||
<< "\t\t v.y = " << scale << " * vy * r; \n"
|
||||
<< "\t\t v.z = " << scale << " * " << z << "; \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\n"
|
||||
<< "\t\t case " << MAP_HSPHERE << ": \n"
|
||||
<< "\t\t r = 1 / (SQR(vx) + SQR(vy) + 0.5); \n"
|
||||
<< "\t\t v.x = " << scale << " * vx * r; \n"
|
||||
<< "\t\t v.y = " << scale << " * vy * r; \n"
|
||||
<< "\t\t v.z = " << scale << " * " << z << "; \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\n"
|
||||
<< "\t\t case " << MAP_QSPHERE << ": \n"
|
||||
<< "\t\t r = 1 / (SQR(vx) + SQR(vy) + 0.25); \n"
|
||||
<< "\t\t v.x = " << scale << " * vx * r; \n"
|
||||
<< "\t\t v.y = " << scale << " * vy * r; \n"
|
||||
<< "\t\t v.z = " << scale << " * " << z << "; \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\n"
|
||||
<< "\t\t case " << MAP_BUBBLE << ": \n"
|
||||
<< "\t\t r = 0.25 - (SQR(vx) + SQR(vy)); \n"
|
||||
<< "\n"
|
||||
<< "\t\t if (r < 0)\n"
|
||||
<< "\t\t r = sqrt(-r); \n"
|
||||
<< "\t\t else\n"
|
||||
<< "\t\t r = sqrt(r); \n"
|
||||
<< "\n"
|
||||
<< "\t\t v.x = " << scale << " * vx; \n"
|
||||
<< "\t\t v.y = " << scale << " * vy; \n"
|
||||
<< "\t\t v.z = " << scale << " * (r + " << z << "); \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\n"
|
||||
<< "\t\t case " << MAP_BUBBLE2 << ": \n"
|
||||
<< "\t\t r = 0.25 - (SQR(vx) + SQR(vy)); \n"
|
||||
<< "\n"
|
||||
<< "\t\t if (r < 0)\n"
|
||||
<< "\t\t r = sqrt(-r); \n"
|
||||
<< "\t\t else\n"
|
||||
<< "\t\t r = sqrt(r); \n"
|
||||
<< "\n"
|
||||
<< "\t\t v.x = " << scale << " * vx; \n"
|
||||
<< "\t\t v.y = " << scale << " * vy; \n"
|
||||
<< "\t\t v.z = " << scale << " * (2 * r + " << z << "); \n"
|
||||
<< "\t\t break; \n"
|
||||
<< "\t\t }\n"
|
||||
<< "\n"
|
||||
<< "\t\t p = PerlinNoise3D(&v, globalShared + NOISE_INDEX, (__global real3*)(globalShared + NOISE_POINTS), " << amps << ", " << freqs << ", iOctaves); \n"
|
||||
<< "\n"
|
||||
<< "\t\t if (p > 0)\n"
|
||||
<< "\t\t e = p * (1 + e * e * 20) + 2 * e; \n"
|
||||
<< "\t\t else\n"
|
||||
<< "\t\t e = p * (1 + e * e * 20) - 2 * e; \n"
|
||||
<< "}\n"
|
||||
<< "\t\twhile ((e < " << notchBottom << " || e > " << notchTop << ") && t++ < iBailout); \n"
|
||||
<< "\n"
|
||||
<< "\t\tvOut.x = xform->m_VariationWeights[" << varIndex << "] * vx; \n"
|
||||
<< "\t\tvOut.y = xform->m_VariationWeights[" << varIndex << "] * vy; \n"
|
||||
<< "\t\tvOut.z = " << ((m_VarType == VARTYPE_REG) ? "0" : "vIn.z") << ";\n"
|
||||
<< "\t\tcol = " << centre << " + " << range << " * p; \n"
|
||||
<< "\t\toutPoint->m_ColorX = col - floor(col); \n"
|
||||
<< "\t}\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
virtual void Precalc() override
|
||||
{
|
||||
m_NotchBottom = m_SelectCentre - m_SelectRange;
|
||||
m_NotchBottom = (m_NotchBottom > T(0.75)) ? T(0.75) : m_NotchBottom;
|
||||
m_NotchBottom = (m_NotchBottom < -2) ? -3 : m_NotchBottom;
|
||||
m_NotchTop = m_SelectCentre + m_SelectRange;
|
||||
m_NotchTop = (m_NotchTop < T(-0.75)) ? T(-0.75) : m_NotchTop;
|
||||
m_NotchTop = (m_NotchTop > 3) ? 3 : m_NotchTop;
|
||||
}
|
||||
protected:
|
||||
void Init()
|
||||
{
|
||||
string prefix = Prefix();
|
||||
m_VarFuncs = VarFuncs<T>::Instance();
|
||||
m_Params.clear();
|
||||
m_Params.reserve(15);
|
||||
m_Params.push_back(ParamWithName<T>(&m_Shape, prefix + "dc_perlin_shape", 0, INTEGER, 0, 2));//Params.
|
||||
m_Params.push_back(ParamWithName<T>(&m_Map, prefix + "dc_perlin_map", 0, INTEGER, 0, 5));
|
||||
m_Params.push_back(ParamWithName<T>(&m_SelectCentre, prefix + "dc_perlin_select_centre", 0, REAL, -1, 1));
|
||||
m_Params.push_back(ParamWithName<T>(&m_SelectRange, prefix + "dc_perlin_select_range", 1, REAL, T(0.1), 2));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Centre, prefix + "dc_perlin_centre", T(0.25)));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Range, prefix + "dc_perlin_range", T(0.25)));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Edge, prefix + "dc_perlin_edge"));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Scale, prefix + "dc_perlin_scale", 1));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Octaves, prefix + "dc_perlin_octaves", 2, INTEGER, 1, 5));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Amps, prefix + "dc_perlin_amps", 2));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Freqs, prefix + "dc_perlin_freqs", 2));
|
||||
m_Params.push_back(ParamWithName<T>(&m_Z, prefix + "dc_perlin_z"));
|
||||
m_Params.push_back(ParamWithName<T>(&m_SelectBailout, prefix + "dc_perlin_select_bailout", 10, INTEGER, 2, 1000));
|
||||
m_Params.push_back(ParamWithName<T>(true, &m_NotchBottom, prefix + "dc_perlin_notch_bottom"));
|
||||
m_Params.push_back(ParamWithName<T>(true, &m_NotchTop, prefix + "dc_perlin_notch_top"));
|
||||
}
|
||||
private:
|
||||
T m_Shape;//Params.
|
||||
T m_Map;
|
||||
T m_SelectCentre;
|
||||
T m_SelectRange;
|
||||
T m_Centre;
|
||||
T m_Range;
|
||||
T m_Edge;
|
||||
T m_Scale;
|
||||
T m_Octaves;
|
||||
T m_Amps;
|
||||
T m_Freqs;
|
||||
T m_Z;
|
||||
T m_SelectBailout;
|
||||
T m_NotchBottom;//Precalc.
|
||||
T m_NotchTop;
|
||||
shared_ptr<VarFuncs<T>> m_VarFuncs;
|
||||
};
|
||||
|
||||
MAKEPREPOSTPARVAR(DCBubble, dc_bubble, DC_BUBBLE)
|
||||
MAKEPREPOSTPARVAR(DCCarpet, dc_carpet, DC_CARPET)
|
||||
MAKEPREPOSTPARVARASSIGN(DCCube, dc_cube, DC_CUBE, ASSIGNTYPE_SUM)
|
||||
@ -1136,4 +1459,5 @@ MAKEPREPOSTVAR(DCGridOut, dc_gridout, DC_GRIDOUT)
|
||||
MAKEPREPOSTPARVAR(DCLinear, dc_linear, DC_LINEAR)
|
||||
MAKEPREPOSTPARVAR(DCTriangle, dc_triangle, DC_TRIANGLE)
|
||||
MAKEPREPOSTPARVAR(DCZTransl, dc_ztransl, DC_ZTRANSL)
|
||||
MAKEPREPOSTPARVAR(DCPerlin, dc_perlin, DC_PERLIN)
|
||||
}
|
||||
|
Reference in New Issue
Block a user