Skip to content

Commit c482a11

Browse files
committed
SeNoise: implement voronoi noise, with a workaround for wdas/SeExpr#32
1 parent d20b57e commit c482a11

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

SeExpr/SeNoise.cpp

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
* OFX SeNoise plugin.
2121
*/
2222

23+
//#define SENOISE_PERLIN // perlin() is not in the open source version of SeExpr, although it is mentionned in the SeExpr doc
24+
#define SENOISE_VORONOI
25+
2326
#include "SeNoisePlugin.h"
2427

2528
#include <cmath>
@@ -42,6 +45,24 @@
4245

4346
#include <SeNoise.h>
4447
#include <SeExprBuiltins.h>
48+
49+
#ifdef SENOISE_VORONOI
50+
// SeExprBuiltins.cpp doesn't export Voronoi functions and data structures, see https://github.com/wdas/SeExpr/issues/32
51+
#include <SeExprNode.h>
52+
namespace SeExpr {
53+
struct VoronoiPointData : public SeExprFuncNode::Data
54+
{
55+
SeVec3d points[27];
56+
SeVec3d cell;
57+
double jitter;
58+
VoronoiPointData() : jitter(-1) {}
59+
};
60+
SeVec3d voronoiFn(VoronoiPointData& data, int n, const SeVec3d* args);
61+
SeVec3d cvoronoiFn(VoronoiPointData& data, int n, const SeVec3d* args);
62+
SeVec3d pvoronoiFn(VoronoiPointData& data, int n, const SeVec3d* args);
63+
}
64+
#endif
65+
4566
#ifdef _WINDOWS
4667
// fix SePlatform.h's bad behavior
4768
#undef snprintf
@@ -62,8 +83,6 @@
6283
#include "ofxsTransformInteract.h"
6384
#include "ofxsMatrix2D.h"
6485

65-
//#define SENOISE_VORONOI
66-
6786
#define kPluginName "SeNoise"
6887
#define kPluginGrouping "Draw"
6988
#define kPluginDescription "Generate noise."
@@ -97,7 +116,7 @@
97116
#define kParamNoiseTypeTurbulenceHint "turbulence is a variant of fbm where the absolute value of each noise term is taken. This gives a more billowy appearance."
98117
#ifdef SENOISE_VORONOI
99118
#define kParamNoiseTypeVoronoi "Voronoi"
100-
#define kParamNoiseTypeVoronoiHint "Voronoi is a cellular noise pattern. It is a jittered variant of cellnoise. cvoronoi returns a random color for each cell and pvoronoi returns the point location of the center of the cell. The type parameter describes different variants of the noise function. The jitter param controls how irregular the pattern is (jitter = 0 is like ordinary cellnoise). The fbm* params can be used to distort the noise field. When fbmScale is zero (the default), there is no distortion. The remaining params are the same as for the fbm function."
119+
#define kParamNoiseTypeVoronoiHint "Voronoi is a cellular noise pattern. It is a jittered variant of cellnoise. The type parameter describes different variants of the noise function. The jitter param controls how irregular the pattern is (jitter = 0 is like ordinary cellnoise). The fbm* params can be used to distort the noise field. When fbmScale is zero (the default), there is no distortion. The remaining params are the same as for the fbm function. NOTE: This does not necessarily return [0,1] value, because it can return arbitrary distance."
101120
#endif
102121
enum NoiseTypeEnum {
103122
eNoiseTypeCellNoise,
@@ -413,6 +432,7 @@ class SeNoiseProcessor : public SeNoiseProcessorBase
413432
assert(nComponents == 3 || nComponents == 4);
414433
float unpPix[4];
415434
float tmpPix[4];
435+
SeExpr::VoronoiPointData voronoiPointData;
416436

417437
const double norm2 = (_point1.x - _point0.x)*(_point1.x - _point0.x) + (_point1.y - _point0.y)*(_point1.y - _point0.y);
418438
const double nx = norm2 == 0. ? 0. : (_point1.x - _point0.x)/ norm2;
@@ -451,7 +471,7 @@ class SeNoiseProcessor : public SeNoiseProcessorBase
451471
}
452472
#ifdef SENOISE_PERLIN
453473
case eNoiseTypePerlin: {
454-
n = SeExpr::noise(1, &p);
474+
n = SeExpr::perlin(1, &p);
455475
break;
456476
}
457477
#endif
@@ -469,15 +489,16 @@ class SeNoiseProcessor : public SeNoiseProcessorBase
469489
}
470490
#ifdef SENOISE_VORONOI
471491
case eNoiseTypeVoronoi: {
472-
SeVec3d p[7];
473-
p[0].setValue(p.x, p.y, p.z);
474-
p[1][0] = (int)_voronoiType + 1;
475-
p[2][0] = _jitter;
476-
p[3][0] = _fbmScale;
477-
p[4][0] = _octaves;
478-
p[5][0] = _lacunarity;
479-
p[6][0] = _gain;
480-
????
492+
SeVec3d args[7];
493+
args[0].setValue(p.x, p.y, p.z);
494+
args[1][0] = (int)_voronoiType + 1;
495+
args[2][0] = _jitter;
496+
args[3][0] = _fbmScale;
497+
args[4][0] = _octaves;
498+
args[5][0] = _lacunarity;
499+
args[6][0] = _gain;
500+
result = SeExpr::voronoiFn(voronoiPointData, 7, args)[0];
501+
481502
} break;
482503
#endif
483504
}

0 commit comments

Comments
 (0)