Updated FastNoise library

- Cubic noise is available
- Some enums have been replaced to reflect the new version
- Added getters
This commit is contained in:
Marc Gilleron 2018-02-25 19:55:04 +01:00
parent a6bd5df8e2
commit bb3f2aa7bb
5 changed files with 1706 additions and 1693 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
// //
// MIT License // MIT License
// //
// Copyright(c) 2016 Jordan Peck // Copyright(c) 2017 Jordan Peck
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal // of this software and associated documentation files(the "Software"), to deal
@ -26,167 +26,291 @@
// off every 'zix'.) // off every 'zix'.)
// //
#ifndef __FASTNOISE_H__ // VERSION: 0.4.1
#define __FASTNOISE_H__
// Added by Marc Gilleron for Godot integration (ability to put a namespace and free FastNoise name) #ifndef FASTNOISE_H
#define FASTNOISE_NAMESPACE fastnoise #define FASTNOISE_H
#ifdef FASTNOISE_NAMESPACE
#define FASTNOISE_NAMESPACE_BEGIN namespace FASTNOISE_NAMESPACE { // Uncomment the line below to use doubles throughout FastNoise instead of floats
#define FASTNOISE_NAMESPACE_END } //#define FN_USE_DOUBLES
#define FN_CELLULAR_INDEX_MAX 3
namespace fastnoise {
#ifdef FN_USE_DOUBLES
typedef double FN_DECIMAL;
#else #else
#define FASTNOISE_NAMESPACE_BEGIN typedef float FN_DECIMAL;
#define FASTNOISE_NAMESPACE_END
#endif #endif
FASTNOISE_NAMESPACE_BEGIN
class FastNoise class FastNoise
{ {
public: public:
FastNoise(int seed = 0) { m_seed = seed; } explicit FastNoise(int seed = 1337) { SetSeed(seed); CalculateFractalBounding(); }
~FastNoise() { delete m_cellularNoiseLookup; }
enum NoiseType { Value, ValueFractal, Gradient, GradientFractal, Simplex, SimplexFractal, Cellular, CellularHQ, WhiteNoise }; enum NoiseType { Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, Cellular, WhiteNoise, Cubic, CubicFractal };
enum Interp { InterpLinear = 0, InterpHermite = 1, InterpQuintic = 2 }; enum Interp { Linear, Hermite, Quintic };
enum FractalType { FBM, Billow, RigidMulti }; enum FractalType { FBM, Billow, RigidMulti };
enum CellularDistanceFunction { Euclidean, Manhattan, Natural }; enum CellularDistanceFunction { Euclidean, Manhattan, Natural };
enum CellularReturnType { CellValue, NoiseLookup, Distance2Center, Distance2CenterXValue, Distance2CenterSq, Distance2CenterSqXValue, Distance2Edge, Distance2EdgeXValue, Distance2EdgeSq, Distance2EdgeSqXValue }; enum CellularReturnType { CellValue, NoiseLookup, Distance, Distance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div };
void SetSeed(int seed) { m_seed = seed; } // Sets seed used for all noise types
int GetSeed(void) { return m_seed; } // Default: 1337
void SetFrequency(float frequency) { m_frequency = frequency; } void SetSeed(int seed);
// Returns seed used for all noise types
int GetSeed() const { return m_seed; }
// Sets frequency for all noise types
// Default: 0.01
void SetFrequency(FN_DECIMAL frequency) { m_frequency = frequency; }
// Returns frequency used for all noise types
FN_DECIMAL GetFrequency() const { return m_frequency; }
// Changes the interpolation method used to smooth between noise values
// Possible interpolation methods (lowest to highest quality) :
// - Linear
// - Hermite
// - Quintic
// Used in Value, Perlin Noise and Position Warping
// Default: Quintic
void SetInterp(Interp interp) { m_interp = interp; } void SetInterp(Interp interp) { m_interp = interp; }
// Returns interpolation method used for supported noise types
Interp GetInterp() const { return m_interp; }
// Sets noise return type of GetNoise(...)
// Default: Simplex
void SetNoiseType(NoiseType noiseType) { m_noiseType = noiseType; } void SetNoiseType(NoiseType noiseType) { m_noiseType = noiseType; }
void SetFractalOctaves(unsigned int octaves) { m_octaves = octaves; } // Returns the noise type used by GetNoise
void SetFractalLacunarity(float lacunarity) { m_lacunarity = lacunarity; } NoiseType GetNoiseType() const { return m_noiseType; }
void SetFractalGain(float gain) { m_gain = gain; }
// Sets octave count for all fractal noise types
// Default: 3
void SetFractalOctaves(int octaves) { m_octaves = octaves; CalculateFractalBounding(); }
// Returns octave count for all fractal noise types
int GetFractalOctaves() const { return m_octaves; }
// Sets octave lacunarity for all fractal noise types
// Default: 2.0
void SetFractalLacunarity(FN_DECIMAL lacunarity) { m_lacunarity = lacunarity; }
// Returns octave lacunarity for all fractal noise types
FN_DECIMAL GetFractalLacunarity() const { return m_lacunarity; }
// Sets octave gain for all fractal noise types
// Default: 0.5
void SetFractalGain(FN_DECIMAL gain) { m_gain = gain; CalculateFractalBounding(); }
// Returns octave gain for all fractal noise types
FN_DECIMAL GetFractalGain() const { return m_gain; }
// Sets method for combining octaves in all fractal noise types
// Default: FBM
void SetFractalType(FractalType fractalType) { m_fractalType = fractalType; } void SetFractalType(FractalType fractalType) { m_fractalType = fractalType; }
// Returns method for combining octaves in all fractal noise types
FractalType GetFractalType() const { return m_fractalType; }
// Sets distance function used in cellular noise calculations
// Default: Euclidean
void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { m_cellularDistanceFunction = cellularDistanceFunction; } void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { m_cellularDistanceFunction = cellularDistanceFunction; }
// Returns the distance function used in cellular noise calculations
CellularDistanceFunction GetCellularDistanceFunction() const { return m_cellularDistanceFunction; }
// Sets return type from cellular noise calculations
// Note: NoiseLookup requires another FastNoise object be set with SetCellularNoiseLookup() to function
// Default: CellValue
void SetCellularReturnType(CellularReturnType cellularReturnType) { m_cellularReturnType = cellularReturnType; } void SetCellularReturnType(CellularReturnType cellularReturnType) { m_cellularReturnType = cellularReturnType; }
// Returns the return type from cellular noise calculations
CellularReturnType GetCellularReturnType() const { return m_cellularReturnType; }
// Noise used to calculate a cell value if cellular return type is NoiseLookup
// The lookup value is acquired through GetNoise() so ensure you SetNoiseType() on the noise lookup, value, Perlin or simplex is recommended
void SetCellularNoiseLookup(FastNoise* noise) { m_cellularNoiseLookup = noise; } void SetCellularNoiseLookup(FastNoise* noise) { m_cellularNoiseLookup = noise; }
/* // Returns the noise used to calculate a cell value if the cellular return type is NoiseLookup
Timing below are averages of time taken for 1 million iterations on a single thread FastNoise* GetCellularNoiseLookup() const { return m_cellularNoiseLookup; }
Default noise settings
CPU: i7 4790k @ 4.0Ghz
VS 2013 - C++ Console Application
*/
//3D // Win32 x64 // Sets the 2 distance indices used for distance2 return types
float GetValue(float x, float y, float z); // 14 ms 14 ms // Default: 0, 1
float GetValueFractal(float x, float y, float z); // 48 ms 49 ms // Note: index0 should be lower than index1
// Both indices must be >= 0, index1 must be < 4
void SetCellularDistance2Indices(int cellularDistanceIndex0, int cellularDistanceIndex1);
float GetGradient(float x, float y, float z); // 23 ms 22 ms // Returns the 2 distance indices used for distance2 return types
float GetGradientFractal(float x, float y, float z);// 80 ms 73 ms void GetCellularDistance2Indices(int& cellularDistanceIndex0, int& cellularDistanceIndex1) const;
float GetSimplex(float x, float y, float z); // 30 ms 30 ms // Sets the maximum distance a cellular point can move from its grid position
float GetSimplexFractal(float x, float y, float z); // 98 ms 101 ms // Setting this high will make artifacts more common
// Default: 0.45
void SetCellularJitter(FN_DECIMAL cellularJitter) { m_cellularJitter = cellularJitter; }
float GetCellular(float x, float y, float z); // 123 ms 113 ms // Returns the maximum distance a cellular point can move from its grid position
float GetCellularHQ(float x, float y, float z); // 433 ms 449 ms FN_DECIMAL GetCellularJitter() const { return m_cellularJitter; }
float GetWhiteNoise(float x, float y, float z); // 1.5 ms 1.5 ms // Sets the maximum warp distance from original location when using GradientPerturb{Fractal}(...)
float GetWhiteNoiseInt(int x, int y, int z); // Default: 1.0
void SetGradientPerturbAmp(FN_DECIMAL gradientPerturbAmp) { m_gradientPerturbAmp = gradientPerturbAmp; }
float GetNoise(float x, float y, float z); // Returns the maximum warp distance from original location when using GradientPerturb{Fractal}(...)
FN_DECIMAL GetGradientPerturbAmp() const { return m_gradientPerturbAmp; }
//2D // Win32 x64 //2D
float GetValue(float x, float y); // 8 ms 8 ms FN_DECIMAL GetValue(FN_DECIMAL x, FN_DECIMAL y) const;
float GetValueFractal(float x, float y); // 29 ms 29 ms FN_DECIMAL GetValueFractal(FN_DECIMAL x, FN_DECIMAL y) const;
float GetGradient(float x, float y); // 12 ms 11 ms FN_DECIMAL GetPerlin(FN_DECIMAL x, FN_DECIMAL y) const;
float GetGradientFractal(float x, float y); // 43 ms 40 ms FN_DECIMAL GetPerlinFractal(FN_DECIMAL x, FN_DECIMAL y) const;
float GetSimplex(float x, float y); // 17 ms 17 ms FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y) const;
float GetSimplexFractal(float x, float y); // 55 ms 52 ms FN_DECIMAL GetSimplexFractal(FN_DECIMAL x, FN_DECIMAL y) const;
float GetCellular(float x, float y); // 35 ms 33 ms FN_DECIMAL GetCellular(FN_DECIMAL x, FN_DECIMAL y) const;
float GetCellularHQ(float x, float y); // 96 ms 90 ms
float GetWhiteNoise(float x, float y); // 1 ms 1 ms FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y) const;
float GetWhiteNoiseInt(int x, int y); // 1 ms 1 ms FN_DECIMAL GetWhiteNoiseInt(int x, int y) const;
float GetNoise(float x, float y); FN_DECIMAL GetCubic(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetCubicFractal(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetNoise(FN_DECIMAL x, FN_DECIMAL y) const;
void GradientPerturb(FN_DECIMAL& x, FN_DECIMAL& y) const;
void GradientPerturbFractal(FN_DECIMAL& x, FN_DECIMAL& y) const;
//3D
FN_DECIMAL GetValue(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetValueFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetPerlin(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetPerlinFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetSimplexFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetCellular(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetWhiteNoiseInt(int x, int y, int z) const;
FN_DECIMAL GetCubic(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetCubicFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
void GradientPerturb(FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
void GradientPerturbFractal(FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
//4D //4D
float GetSimplex(float x, float y, float z, float w); FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
float GetWhiteNoise(float x, float y, float z, float w); FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
float GetWhiteNoiseInt(int x, int y, int z, int w); FN_DECIMAL GetWhiteNoiseInt(int x, int y, int z, int w) const;
protected: private:
int m_seed = 0; unsigned char m_perm[512];
float m_frequency = 0.01f; unsigned char m_perm12[512];
Interp m_interp = InterpQuintic;
NoiseType m_noiseType = Value;
unsigned int m_octaves = 3; int m_seed = 1337;
float m_lacunarity = 2.0f; FN_DECIMAL m_frequency = FN_DECIMAL(0.01);
float m_gain = 0.5f; Interp m_interp = Quintic;
NoiseType m_noiseType = Simplex;
int m_octaves = 3;
FN_DECIMAL m_lacunarity = FN_DECIMAL(2);
FN_DECIMAL m_gain = FN_DECIMAL(0.5);
FractalType m_fractalType = FBM; FractalType m_fractalType = FBM;
FN_DECIMAL m_fractalBounding;
CellularDistanceFunction m_cellularDistanceFunction = Euclidean; CellularDistanceFunction m_cellularDistanceFunction = Euclidean;
CellularReturnType m_cellularReturnType = CellValue; CellularReturnType m_cellularReturnType = CellValue;
FastNoise* m_cellularNoiseLookup = nullptr; FastNoise* m_cellularNoiseLookup = nullptr;
int m_cellularDistanceIndex0 = 0;
int m_cellularDistanceIndex1 = 1;
FN_DECIMAL m_cellularJitter = FN_DECIMAL(0.45);
//3D FN_DECIMAL m_gradientPerturbAmp = FN_DECIMAL(1);
float _ValueFractalFBM(float x, float y, float z);
float _ValueFractalBillow(float x, float y, float z);
float _ValueFractalRigidMulti(float x, float y, float z);
float _Value(int seed, float x, float y, float z);
float _GradientFractalFBM(float x, float y, float z); void CalculateFractalBounding();
float _GradientFractalBillow(float x, float y, float z);
float _GradientFractalRigidMulti(float x, float y, float z);
float _Gradient(int seed, float x, float y, float z);
float _SimplexFractalFBM(float x, float y, float z);
float _SimplexFractalBillow(float x, float y, float z);
float _SimplexFractalRigidMulti(float x, float y, float z);
float _Simplex(int seed, float x, float y, float z);
float _Cellular(float x, float y, float z);
float _CellularHQ(float x, float y, float z);
float _Cellular2Edge(float x, float y, float z);
float _Cellular2EdgeHQ(float x, float y, float z);
inline static int CoordLUTIndex(int seed, int x, int y, int z);
inline float GetValCoord(int seed, int x, int y, int z);
inline float GetGradCoord(int seed, int xi, int yi, int zi, float x, float y, float z);
//2D //2D
float _ValueFractalFBM(float x, float y); FN_DECIMAL SingleValueFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
float _ValueFractalBillow(float x, float y); FN_DECIMAL SingleValueFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
float _ValueFractalRigidMulti(float x, float y); FN_DECIMAL SingleValueFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
float _Value(int seed, float x, float y); FN_DECIMAL SingleValue(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
float _GradientFractalFBM(float x, float y); FN_DECIMAL SinglePerlinFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
float _GradientFractalBillow(float x, float y); FN_DECIMAL SinglePerlinFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
float _GradientFractalRigidMulti(float x, float y); FN_DECIMAL SinglePerlinFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
float _Gradient(int seed, float x, float y); FN_DECIMAL SinglePerlin(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
float _SimplexFractalFBM(float x, float y); FN_DECIMAL SingleSimplexFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
float _SimplexFractalBillow(float x, float y); FN_DECIMAL SingleSimplexFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
float _SimplexFractalRigidMulti(float x, float y); FN_DECIMAL SingleSimplexFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
float _Simplex(int seed, float x, float y); FN_DECIMAL SingleSimplexFractalBlend(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
float _Cellular(float x, float y); FN_DECIMAL SingleCubicFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
float _CellularHQ(float x, float y); FN_DECIMAL SingleCubicFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
float _Cellular2Edge(float x, float y); FN_DECIMAL SingleCubicFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
float _Cellular2EdgeHQ(float x, float y); FN_DECIMAL SingleCubic(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
inline int CoordLUTIndex(int seed, int x, int y); FN_DECIMAL SingleCellular(FN_DECIMAL x, FN_DECIMAL y) const;
inline float GetValCoord(int seed, int x, int y); FN_DECIMAL SingleCellular2Edge(FN_DECIMAL x, FN_DECIMAL y) const;
inline float GetGradCoord(int seed, int xi, int yi, float x, float y);
void SingleGradientPerturb(unsigned char offset, FN_DECIMAL warpAmp, FN_DECIMAL frequency, FN_DECIMAL& x, FN_DECIMAL& y) const;
//3D
FN_DECIMAL SingleValueFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleValueFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleValueFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleValue(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlinFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlinFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlinFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlin(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplexFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplexFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplexFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubicFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubicFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubicFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubic(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCellular(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCellular2Edge(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
void SingleGradientPerturb(unsigned char offset, FN_DECIMAL warpAmp, FN_DECIMAL frequency, FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
//4D //4D
float _Simplex(float x, float y, float z, float w); FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
inline static int CoordLUTIndex(int seed, int x, int y, int z, int w);
inline unsigned char Index2D_12(unsigned char offset, int x, int y) const;
inline unsigned char Index3D_12(unsigned char offset, int x, int y, int z) const;
inline unsigned char Index4D_32(unsigned char offset, int x, int y, int z, int w) const;
inline unsigned char Index2D_256(unsigned char offset, int x, int y) const;
inline unsigned char Index3D_256(unsigned char offset, int x, int y, int z) const;
inline unsigned char Index4D_256(unsigned char offset, int x, int y, int z, int w) const;
inline FN_DECIMAL ValCoord2DFast(unsigned char offset, int x, int y) const;
inline FN_DECIMAL ValCoord3DFast(unsigned char offset, int x, int y, int z) const;
inline FN_DECIMAL GradCoord2D(unsigned char offset, int x, int y, FN_DECIMAL xd, FN_DECIMAL yd) const;
inline FN_DECIMAL GradCoord3D(unsigned char offset, int x, int y, int z, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd) const;
inline FN_DECIMAL GradCoord4D(unsigned char offset, int x, int y, int z, int w, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd, FN_DECIMAL wd) const;
}; };
FASTNOISE_NAMESPACE_END } // namespace fastnoise
#endif #endif

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2016 Jordan Peck Copyright (c) 2017 Jordan Peck
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -45,21 +45,62 @@ void FastNoise::set_cellular_noise_lookup(Ref<FastNoise> other_noise) {
_noise.SetCellularNoiseLookup(&_cellular_lookup_ref->_noise); _noise.SetCellularNoiseLookup(&_cellular_lookup_ref->_noise);
} }
void FastNoise::set_cellular_distance_2_indices(int index0, int index1) {
_noise.SetCellularDistance2Indices(index0, index1);
}
PoolIntArray FastNoise::get_cellular_distance_2_indices() const {
int i0, i1;
_noise.GetCellularDistance2Indices(i0, i1);
PoolIntArray a;
a.append(i0);
a.append(i1);
return a;
}
void FastNoise::_bind_methods() { void FastNoise::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &FastNoise::set_seed); ClassDB::bind_method(D_METHOD("set_seed", "seed"), &FastNoise::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &FastNoise::get_seed); ClassDB::bind_method(D_METHOD("get_seed"), &FastNoise::get_seed);
ClassDB::bind_method(D_METHOD("set_noise_type", "type"), &FastNoise::set_noise_type); ClassDB::bind_method(D_METHOD("set_noise_type", "type"), &FastNoise::set_noise_type);
ClassDB::bind_method(D_METHOD("get_noise_type"), &FastNoise::get_noise_type);
ClassDB::bind_method(D_METHOD("set_interpolation", "interp"), &FastNoise::set_interpolation); ClassDB::bind_method(D_METHOD("set_interpolation", "interp"), &FastNoise::set_interpolation);
ClassDB::bind_method(D_METHOD("get_interpolation"), &FastNoise::get_interpolation);
ClassDB::bind_method(D_METHOD("set_frequency", "freq"), &FastNoise::set_frequency); ClassDB::bind_method(D_METHOD("set_frequency", "freq"), &FastNoise::set_frequency);
ClassDB::bind_method(D_METHOD("get_frequency"), &FastNoise::get_frequency);
ClassDB::bind_method(D_METHOD("set_fractal_gain", "gain"), &FastNoise::set_fractal_gain); ClassDB::bind_method(D_METHOD("set_fractal_gain", "gain"), &FastNoise::set_fractal_gain);
ClassDB::bind_method(D_METHOD("get_fractal_gain"), &FastNoise::get_fractal_gain);
ClassDB::bind_method(D_METHOD("set_fractal_type", "type"), &FastNoise::set_fractal_type); ClassDB::bind_method(D_METHOD("set_fractal_type", "type"), &FastNoise::set_fractal_type);
ClassDB::bind_method(D_METHOD("get_fractal_type", "type"), &FastNoise::get_fractal_type);
ClassDB::bind_method(D_METHOD("set_fractal_octaves", "octave_count"), &FastNoise::set_fractal_octaves); ClassDB::bind_method(D_METHOD("set_fractal_octaves", "octave_count"), &FastNoise::set_fractal_octaves);
ClassDB::bind_method(D_METHOD("get_fractal_octaves"), &FastNoise::get_fractal_octaves);
ClassDB::bind_method(D_METHOD("set_fractal_lacunarity", "lacunarity"), &FastNoise::set_fractal_lacunarity); ClassDB::bind_method(D_METHOD("set_fractal_lacunarity", "lacunarity"), &FastNoise::set_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("get_fractal_lacunarity"), &FastNoise::get_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("set_cellular_distance_function", "func"), &FastNoise::set_cellular_distance_function); ClassDB::bind_method(D_METHOD("set_cellular_distance_function", "func"), &FastNoise::set_cellular_distance_function);
ClassDB::bind_method(D_METHOD("get_cellular_distance_function"), &FastNoise::get_cellular_distance_function);
ClassDB::bind_method(D_METHOD("set_cellular_return_type", "ret"), &FastNoise::set_cellular_return_type); ClassDB::bind_method(D_METHOD("set_cellular_return_type", "ret"), &FastNoise::set_cellular_return_type);
ClassDB::bind_method(D_METHOD("get_cellular_return_type"), &FastNoise::get_cellular_return_type);
ClassDB::bind_method(D_METHOD("set_cellular_noise_lookup", "other_noise"), &FastNoise::set_cellular_noise_lookup); ClassDB::bind_method(D_METHOD("set_cellular_noise_lookup", "other_noise"), &FastNoise::set_cellular_noise_lookup);
ClassDB::bind_method(D_METHOD("get_cellular_noise_lookup"), &FastNoise::get_cellular_noise_lookup);
ClassDB::bind_method(D_METHOD("set_cellular_distance_2_indices", "i0", "i1"), &FastNoise::set_cellular_distance_2_indices);
ClassDB::bind_method(D_METHOD("get_cellular_distance_2_indices"), &FastNoise::get_cellular_distance_2_indices);
ClassDB::bind_method(D_METHOD("set_cellular_jitter", "jitter"), &FastNoise::set_cellular_jitter);
ClassDB::bind_method(D_METHOD("get_cellular_jitter"), &FastNoise::get_cellular_jitter);
ClassDB::bind_method(D_METHOD("set_gradient_perturbation_amplitude", "amp"), &FastNoise::get_gradient_perturbation_amplitude);
ClassDB::bind_method(D_METHOD("get_gradient_perturbation_amplitude"), &FastNoise::get_gradient_perturbation_amplitude);
ClassDB::bind_method(D_METHOD("get_noise_2d", "x", "y"), &FastNoise::get_noise_2d); ClassDB::bind_method(D_METHOD("get_noise_2d", "x", "y"), &FastNoise::get_noise_2d);
ClassDB::bind_method(D_METHOD("get_noise_2dv", "pos"), &FastNoise::get_noise_2dv); ClassDB::bind_method(D_METHOD("get_noise_2dv", "pos"), &FastNoise::get_noise_2dv);
@ -69,38 +110,37 @@ void FastNoise::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_white_noise_4d", "x", "y", "z", "w"), &FastNoise::get_white_noise_4d); ClassDB::bind_method(D_METHOD("get_white_noise_4d", "x", "y", "z", "w"), &FastNoise::get_white_noise_4d);
// TODO Bind intermediary functions? // TODO Bind intermediary functions?
BIND_CONSTANT( TYPE_VALUE ); BIND_ENUM_CONSTANT( TYPE_VALUE );
BIND_CONSTANT( TYPE_VALUE_FRACTAL ); BIND_ENUM_CONSTANT( TYPE_VALUE_FRACTAL );
BIND_CONSTANT( TYPE_GRADIENT ); BIND_ENUM_CONSTANT( TYPE_PERLIN );
BIND_CONSTANT( TYPE_GRADIENT_FRACTAL ); BIND_ENUM_CONSTANT( TYPE_PERLIN_FRACTAL );
BIND_CONSTANT( TYPE_SIMPLEX ); BIND_ENUM_CONSTANT( TYPE_SIMPLEX );
BIND_CONSTANT( TYPE_SIMPLEX_FRACTAL ); BIND_ENUM_CONSTANT( TYPE_SIMPLEX_FRACTAL );
BIND_CONSTANT( TYPE_CELLULAR ); BIND_ENUM_CONSTANT( TYPE_CELLULAR );
BIND_CONSTANT( TYPE_CELLULAR_HQ ); BIND_ENUM_CONSTANT( TYPE_WHITE_NOISE );
BIND_CONSTANT( TYPE_WHITE_NOISE ); BIND_ENUM_CONSTANT( TYPE_CUBIC );
BIND_ENUM_CONSTANT( TYPE_CUBIC_FRACTAL );
BIND_CONSTANT( INTERP_LINEAR ); BIND_ENUM_CONSTANT( INTERP_LINEAR );
BIND_CONSTANT( INTERP_QUINTIC ); BIND_ENUM_CONSTANT( INTERP_QUINTIC );
BIND_CONSTANT( INTERP_HERMITE ); BIND_ENUM_CONSTANT( INTERP_HERMITE );
BIND_CONSTANT( FRACTAL_FBM ); BIND_ENUM_CONSTANT( FRACTAL_FBM );
BIND_CONSTANT( FRACTAL_BILLOW ); BIND_ENUM_CONSTANT( FRACTAL_BILLOW );
BIND_CONSTANT( FRACTAL_RIGID_MULTI ); BIND_ENUM_CONSTANT( FRACTAL_RIGID_MULTI );
BIND_CONSTANT( DISTANCE_EUCLIDEAN ); BIND_ENUM_CONSTANT( DISTANCE_EUCLIDEAN );
BIND_CONSTANT( DISTANCE_MANHATTAN ); BIND_ENUM_CONSTANT( DISTANCE_MANHATTAN );
BIND_CONSTANT( DISTANCE_NATURAL ); BIND_ENUM_CONSTANT( DISTANCE_NATURAL );
BIND_CONSTANT( RETURN_CELL_VALUE ); BIND_ENUM_CONSTANT( RETURN_CELL_VALUE );
BIND_CONSTANT( RETURN_NOISE_LOOKUP ); BIND_ENUM_CONSTANT( RETURN_NOISE_LOOKUP );
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER ); BIND_ENUM_CONSTANT( RETURN_DISTANCE );
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER_X_VALUE ); BIND_ENUM_CONSTANT( RETURN_DISTANCE_2 );
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER_SQ ); BIND_ENUM_CONSTANT( RETURN_DISTANCE_2_ADD );
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER_SQ_X_VALUE ); BIND_ENUM_CONSTANT( RETURN_DISTANCE_2_SUB );
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE ); BIND_ENUM_CONSTANT( RETURN_DISTANCE_2_MUL );
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE_X_VALUE ); BIND_ENUM_CONSTANT( RETURN_DISTANCE_2_DIV );
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE_SQ );
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE_SQ_X_VALUE );
} }

97
noise.h
View File

@ -7,28 +7,29 @@
typedef fastnoise::FastNoise _FastNoise; typedef fastnoise::FastNoise _FastNoise;
class FastNoise : public Reference { class FastNoise : public Reference {
GDCLASS(FastNoise, Reference); GDCLASS(FastNoise, Reference)
public: public:
// Enums Godot-style (same values) // Enums Godot-style (same values)
enum Type { enum Type {
TYPE_VALUE = _FastNoise::Value, TYPE_VALUE = _FastNoise::Value,
TYPE_VALUE_FRACTAL = _FastNoise::ValueFractal, TYPE_VALUE_FRACTAL = _FastNoise::ValueFractal,
TYPE_GRADIENT = _FastNoise::Gradient, TYPE_PERLIN = _FastNoise::Perlin,
TYPE_GRADIENT_FRACTAL = _FastNoise::GradientFractal, TYPE_PERLIN_FRACTAL = _FastNoise::PerlinFractal,
TYPE_SIMPLEX = _FastNoise::Simplex, TYPE_SIMPLEX = _FastNoise::Simplex,
TYPE_SIMPLEX_FRACTAL = _FastNoise::SimplexFractal, TYPE_SIMPLEX_FRACTAL = _FastNoise::SimplexFractal,
TYPE_CELLULAR = _FastNoise::Cellular, TYPE_CELLULAR = _FastNoise::Cellular,
TYPE_CELLULAR_HQ = _FastNoise::CellularHQ, TYPE_WHITE_NOISE = _FastNoise::WhiteNoise,
TYPE_WHITE_NOISE = _FastNoise::WhiteNoise TYPE_CUBIC = _FastNoise::Cubic,
TYPE_CUBIC_FRACTAL = _FastNoise::CubicFractal
}; };
enum Interpolation { enum Interpolation {
INTERP_LINEAR = _FastNoise::InterpLinear, INTERP_LINEAR = _FastNoise::Linear,
INTERP_QUINTIC = _FastNoise::InterpQuintic, INTERP_QUINTIC = _FastNoise::Quintic,
INTERP_HERMITE = _FastNoise::InterpHermite INTERP_HERMITE = _FastNoise::Hermite
}; };
enum FractalType { enum FractalType {
@ -46,35 +47,59 @@ public:
enum CellularReturnType { enum CellularReturnType {
RETURN_CELL_VALUE = _FastNoise::CellValue, RETURN_CELL_VALUE = _FastNoise::CellValue,
RETURN_NOISE_LOOKUP = _FastNoise::NoiseLookup, RETURN_NOISE_LOOKUP = _FastNoise::NoiseLookup,
RETURN_DISTANCE_2_CENTER = _FastNoise::Distance2Center, RETURN_DISTANCE = _FastNoise::Distance,
RETURN_DISTANCE_2_CENTER_X_VALUE = _FastNoise::Distance2CenterXValue, RETURN_DISTANCE_2 = _FastNoise::Distance2,
RETURN_DISTANCE_2_CENTER_SQ = _FastNoise::Distance2CenterSq, RETURN_DISTANCE_2_ADD = _FastNoise::Distance2Add,
RETURN_DISTANCE_2_CENTER_SQ_X_VALUE = _FastNoise::Distance2CenterSqXValue, RETURN_DISTANCE_2_SUB = _FastNoise::Distance2Sub,
RETURN_DISTANCE_2_EDGE = _FastNoise::Distance2Edge, RETURN_DISTANCE_2_MUL = _FastNoise::Distance2Mul,
RETURN_DISTANCE_2_EDGE_X_VALUE = _FastNoise::Distance2EdgeXValue, RETURN_DISTANCE_2_DIV = _FastNoise::Distance2Div
RETURN_DISTANCE_2_EDGE_SQ = _FastNoise::Distance2EdgeSq,
RETURN_DISTANCE_2_EDGE_SQ_X_VALUE = _FastNoise::Distance2EdgeSqXValue
}; };
FastNoise(); FastNoise();
// Methods (Godot-style mappings to FastNoise) // Methods (Godot-style mappings to FastNoise)
int get_seed() { return _noise.GetSeed(); } // TODO should be const int get_seed() const { return _noise.GetSeed(); }
void set_seed(int seed) { _noise.SetSeed(seed); } void set_seed(int seed) { _noise.SetSeed(seed); }
void set_noise_type(Type noise_type) { _noise.SetNoiseType((_FastNoise::NoiseType)noise_type); } void set_noise_type(Type noise_type) { _noise.SetNoiseType((_FastNoise::NoiseType)noise_type); }
void set_interpolation(Interpolation interp) { _noise.SetInterp((_FastNoise::Interp)interp); } Type get_noise_type() const { return (Type)_noise.GetNoiseType(); }
void set_frequency(float freq) { _noise.SetFrequency(freq); }
void set_fractal_gain(float gain) { _noise.SetFractalGain(gain); } void set_interpolation(Interpolation interp) { _noise.SetInterp((_FastNoise::Interp)interp); }
void set_fractal_type(FractalType type) { _noise.SetFractalType((_FastNoise::FractalType)type); } Interpolation get_interpolation() const { return (Interpolation)_noise.GetInterp(); }
void set_fractal_octaves(unsigned int octave_count) { _noise.SetFractalOctaves(octave_count); }
void set_fractal_lacunarity(float lacunarity) { _noise.SetFractalLacunarity(lacunarity); } void set_frequency(real_t freq) { _noise.SetFrequency(freq); }
void set_cellular_distance_function(CellularDistanceFunction func) { _noise.SetCellularDistanceFunction((_FastNoise::CellularDistanceFunction)func); } real_t get_frequency() const { return _noise.GetFrequency(); }
void set_cellular_return_type(CellularReturnType ret) { _noise.SetCellularReturnType((_FastNoise::CellularReturnType)ret); }
void set_fractal_octaves(unsigned int octave_count) { _noise.SetFractalOctaves(octave_count); }
int get_fractal_octaves() const { return _noise.GetFractalOctaves(); }
void set_fractal_lacunarity(real_t lacunarity) { _noise.SetFractalLacunarity(lacunarity); }
real_t get_fractal_lacunarity() const { return _noise.GetFractalLacunarity(); }
void set_fractal_gain(real_t gain) { _noise.SetFractalGain(gain); }
real_t get_fractal_gain() const { return _noise.GetFractalGain(); }
void set_fractal_type(FractalType type) { _noise.SetFractalType((_FastNoise::FractalType)type); }
FractalType get_fractal_type() const { return (FractalType)_noise.GetFractalType(); }
void set_cellular_distance_function(CellularDistanceFunction func) { _noise.SetCellularDistanceFunction((_FastNoise::CellularDistanceFunction)func); }
CellularDistanceFunction get_cellular_distance_function() const { return (CellularDistanceFunction)_noise.GetCellularDistanceFunction(); }
void set_cellular_return_type(CellularReturnType ret) { _noise.SetCellularReturnType((_FastNoise::CellularReturnType)ret); }
CellularReturnType get_cellular_return_type() const { return (CellularReturnType)_noise.GetCellularReturnType(); }
// TODO Q: how can I do that properly?
void set_cellular_noise_lookup(Ref<FastNoise> other_noise); void set_cellular_noise_lookup(Ref<FastNoise> other_noise);
Ref<FastNoise> get_cellular_noise_lookup() const { return _cellular_lookup_ref; }
void set_cellular_distance_2_indices(int index0, int index1);
PoolIntArray get_cellular_distance_2_indices() const;
void set_cellular_jitter(real_t jitter) { _noise.SetCellularJitter(jitter); }
real_t get_cellular_jitter() const { return _noise.GetCellularJitter(); }
void set_gradient_perturbation_amplitude(real_t amp) { _noise.SetGradientPerturbAmp(amp); }
real_t get_gradient_perturbation_amplitude() const { return _noise.GetGradientPerturbAmp(); }
// 2D // 2D
@ -119,11 +144,11 @@ private:
}; };
// Make Variant happy with custom enums // Make Variant happy with custom enums
VARIANT_ENUM_CAST(FastNoise::Type); VARIANT_ENUM_CAST(FastNoise::Type)
VARIANT_ENUM_CAST(FastNoise::FractalType); VARIANT_ENUM_CAST(FastNoise::FractalType)
VARIANT_ENUM_CAST(FastNoise::Interpolation); VARIANT_ENUM_CAST(FastNoise::Interpolation)
VARIANT_ENUM_CAST(FastNoise::CellularDistanceFunction); VARIANT_ENUM_CAST(FastNoise::CellularDistanceFunction)
VARIANT_ENUM_CAST(FastNoise::CellularReturnType); VARIANT_ENUM_CAST(FastNoise::CellularReturnType)
#endif // FASTNOISE_NOISE_H #endif // FASTNOISE_NOISE_H