19#include "FastNoiseLite.h"
20#include "macrologger.h"
29#define HMAP_FCT_XY_TYPE std::function<float(float, float, float)>
31#define HMAP_GRADIENT_OFFSET 0.001f
51 const Vec4<float> &bbox = {0.f, 1.f, 0.f, 1.f});
94 Function() : delegate([](float, float, float) {
return 0.f; })
107 explicit Function(HMAP_FCT_XY_TYPE delegate) : delegate(std::move(delegate))
124 float get_value(
float x,
float y,
float ctrl_param)
const;
133 HMAP_FCT_XY_TYPE delegate;
165 this->array = new_array;
305 this->sigma = new_sigma;
306 this->inv_sigma2 = 1.f / (this->sigma * this->
sigma);
346 this->angle = new_angle;
347 this->ca = std::cos(
angle / 180.f * M_PI);
348 this->sa = std::sin(
angle / 180.f * M_PI);
394 this->angle = new_angle;
395 this->ca = std::cos(
angle / 180.f * M_PI);
396 this->sa = std::sin(
angle / 180.f * M_PI);
437 this->angle = new_angle;
438 this->ca = std::cos(
angle / 180.f * M_PI);
439 this->sa = std::sin(
angle / 180.f * M_PI);
478 this->angle = new_angle;
479 this->ca = std::cos(
angle / 180.f * M_PI);
480 this->sa = std::sin(
angle / 180.f * M_PI);
529 this->angle = new_angle;
530 this->ca = std::cos(
angle / 180.f * M_PI);
531 this->sa = std::sin(
angle / 180.f * M_PI);
574 this->angle = new_angle;
575 this->ca = std::cos(
angle / 180.f * M_PI);
576 this->sa = std::sin(
angle / 180.f * M_PI);
616 this->angle = new_angle;
617 this->ca = std::cos(
angle / 180.f * M_PI);
618 this->sa = std::sin(
angle / 180.f * M_PI);
663 this->angle = new_angle;
664 this->ca = std::cos(
angle / 180.f * M_PI);
665 this->sa = std::sin(
angle / 180.f * M_PI);
744 this->
seed = new_seed;
805 int perlin_b = 0X100;
810 int perlin_bm = 0xff;
815 int perlin_n = 0x100;
825 std::vector<std::vector<float>> g2;
830 std::vector<float> m;
856 this->noise.SetSeed(new_seed);
889 this->noise.SetSeed(new_seed);
925 this->noise.SetSeed(new_seed);
958 this->noise.SetSeed(new_seed);
991 this->noise.SetSeed(new_seed);
1024 this->noise.SetSeed(new_seed);
1031 FastNoiseLite noise;
1057 this->noise.SetSeed(new_seed);
1064 FastNoiseLite noise;
1090 this->noise.SetSeed(new_seed);
1097 FastNoiseLite noise;
1207 this->noise.SetSeed(new_seed);
1214 FastNoiseLite noise;
1252 this->noise1.SetSeed(new_seed);
1253 this->noise2.SetSeed(new_seed + 1);
1260 FastNoiseLite noise1, noise2;
1302 this->p_base->set_kw(new_kw);
1312 this->lacunarity = new_lacunarity;
1322 this->octaves = new_octaves;
1333 this->persistence = new_persistence;
1345 this->p_base->set_seed(new_seed);
1355 this->
amp0 *= scale;
1406 std::unique_ptr<NoiseFunction>
1468 this->gradient_scale = new_gradient_scale;
1512 this->warp0 = new_warp0;
1522 this->damp0 = new_damp0;
1532 this->warp_scale = new_warp_scale;
1542 this->damp_scale = new_damp_scale;
1619 this->k_smoothing = new_k_smoothing;
1657 this->warp_scale = new_warp_scale;
1696 std::vector<float>
xr,
1697 std::vector<float>
yr,
1698 std::vector<float>
zr);
1741 std::unique_ptr<Function> p_base;
1746 void setup_delegate();
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
unsigned int uint
Definition array.hpp:14
Array (x, y) function class.
Definition functions.hpp:146
bool periodic
Flag indicating whether the domain is periodic or not.
Definition functions.hpp:170
Vec2< float > kw
Frequency scaling vector.
Definition functions.hpp:169
void set_array(Array new_array)
Set the array object.
Definition functions.hpp:163
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
Biquad (x, y) function class.
Definition functions.hpp:184
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:195
Vec2< float > center
Primitive reference center.
Definition functions.hpp:196
Bump (x, y) function class.
Definition functions.hpp:207
Vec2< float > center
Primitive reference center.
Definition functions.hpp:219
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:218
Crater (x, y) function class.
Definition functions.hpp:230
float depth
Depth of the crater.
Definition functions.hpp:252
Vec2< float > center
Primitive reference center.
Definition functions.hpp:255
float lip_decay
Decay rate of the crater's lip.
Definition functions.hpp:253
float radius
Radius of the crater.
Definition functions.hpp:251
float lip_height_ratio
Height ratio of the crater's lip.
Definition functions.hpp:254
DiskFunction (x, y) function class.
Definition functions.hpp:263
float radius
Radius of the disk.
Definition functions.hpp:275
Vec2< float > center
Primitive reference center.
Definition functions.hpp:277
float slope
Slope of the disk.
Definition functions.hpp:276
Fractional Brownian Motion (FBM) function class.
Definition functions.hpp:1420
IQ layering function class.
Definition functions.hpp:1442
float gradient_scale
Gradient scale influence.
Definition functions.hpp:1472
void set_gradient_scale(float new_gradient_scale)
Set the gradient scale.
Definition functions.hpp:1466
Jordan layering function class.
Definition functions.hpp:1480
void set_damp0(float new_damp0)
Set the initial damp.
Definition functions.hpp:1520
float warp0
Initial warp.
Definition functions.hpp:1546
void set_warp0(float new_warp0)
Set the initial warp.
Definition functions.hpp:1510
float damp_scale
Damp scale.
Definition functions.hpp:1549
float damp0
Initial damp.
Definition functions.hpp:1547
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1530
float warp_scale
Warp scale.
Definition functions.hpp:1548
void set_damp_scale(float new_damp_scale)
Set the damp scale.
Definition functions.hpp:1540
Pingpong layering function class.
Definition functions.hpp:1557
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1579
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1585
Ridged layering function class.
Definition functions.hpp:1593
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1623
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1617
Swiss layering function class.
Definition functions.hpp:1631
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1655
float warp_scale
Warping scale.
Definition functions.hpp:1662
float warp_scale_normalized
Normalized warping scale.
Definition functions.hpp:1663
Field function class.
Definition functions.hpp:1675
std::vector< float > yr
Definition functions.hpp:1734
void set_xr(std::vector< float > new_xr)
Set the x coordinates representing the centers of the primitive.
Definition functions.hpp:1705
void set_yr(std::vector< float > new_yr)
Set the y coordinates representing the centers of the primitive.
Definition functions.hpp:1715
std::vector< float > xr
Definition functions.hpp:1732
void set_zr(std::vector< float > new_zr)
Set the z coordinates used to scale the primitive in x and y directions, and also to scale the primit...
Definition functions.hpp:1726
std::vector< float > zr
Definition functions.hpp:1737
A class that wraps a callable entity taking three floats and returning a float.
Definition functions.hpp:88
Function()
Default constructor. Initializes the delegate function to a default that returns 0.
Definition functions.hpp:94
HMAP_FCT_XY_TYPE get_delegate() const
Get the current delegate function.
Definition functions.cpp:38
void set_delegate(HMAP_FCT_XY_TYPE new_delegate)
Set a new delegate function.
Definition functions.cpp:48
float get_value(float x, float y, float ctrl_param) const
Call the delegate function with given arguments.
Definition functions.cpp:43
virtual ~Function()=default
Virtual destructor to ensure proper cleanup in derived classes.
Function(HMAP_FCT_XY_TYPE delegate)
Constructor to initialize with a specific delegate function.
Definition functions.hpp:107
GaussianPulse (x, y) function class.
Definition functions.hpp:288
Vec2< float > center
Primitive reference center.
Definition functions.hpp:311
float sigma
Pulse half-width.
Definition functions.hpp:310
void set_sigma(float new_sigma)
Set the half-width.
Definition functions.hpp:303
A class for generating fractal noise functions based on an underlying noise function.
Definition functions.hpp:1277
void set_kw(Vec2< float > new_kw) override
Set the frequency scaling vector.
Definition functions.hpp:1299
float get_weight() const
Get the weight of the fractal noise.
Definition functions.hpp:1393
void set_octaves(int new_octaves)
Set the number of octaves in the fractal noise.
Definition functions.hpp:1320
void set_seed(uint new_seed) override
Set a new random seed for the noise generation.
Definition functions.hpp:1342
void set_persistence(float new_persistence)
Set the persistence of the fractal noise.
Definition functions.hpp:1331
void scale_amp0(float scale)
Scale the initial amplitude of the fractal noise.
Definition functions.hpp:1353
int octaves
Number of octaves in the fractal noise.
Definition functions.hpp:1408
float get_lacunarity() const
Get the lacunarity of the fractal noise.
Definition functions.hpp:1363
float weight
Weight of the base noise function.
Definition functions.hpp:1409
int get_octaves() const
Get the number of octaves in the fractal noise.
Definition functions.hpp:1373
float amp0
Initial amplitude of the fractal noise.
Definition functions.hpp:1412
std::unique_ptr< NoiseFunction > p_base
Unique pointer to the base noise function.
Definition functions.hpp:1407
float lacunarity
Lacunarity of the fractal noise.
Definition functions.hpp:1411
float get_persistence() const
Get the persistence of the fractal noise.
Definition functions.hpp:1383
float persistence
Persistence of the fractal noise.
Definition functions.hpp:1410
void set_lacunarity(float new_lacunarity)
Set the lacunarity of the fractal noise.
Definition functions.hpp:1310
void update_amp0()
Update the initial amplitude (amp0) based on the current octaves and persistence.
Definition fbm_functions.cpp:391
A class for generating noise functions.
Definition functions.hpp:693
virtual void set_kw(Vec2< float > new_kw)
Set a new frequency scaling vector.
Definition functions.hpp:751
uint get_seed() const
Get the random seed.
Definition functions.hpp:733
Vec2< float > kw
Frequency scaling vector.
Definition functions.hpp:757
virtual void set_seed(uint new_seed)
Set a new random seed for noise generation.
Definition functions.hpp:742
NoiseFunction()
Default constructor. Initializes with default frequency scaling and seed.
Definition functions.hpp:699
uint seed
Random seed for noise generation.
Definition functions.hpp:758
NoiseFunction(Vec2< float > kw)
Constructor to initialize with specific frequency scaling.
Definition functions.hpp:707
NoiseFunction(Vec2< float > kw, uint seed)
Constructor to initialize with specific frequency scaling and seed.
Definition functions.hpp:716
Vec2< float > get_kw() const
Get the frequency scaling vector.
Definition functions.hpp:724
Parberry (x, y) function class.
Definition functions.hpp:769
void initialize()
Initialize generator.
Definition parberry_function.cpp:25
float mu
Gradient magnitude exponent.
Definition functions.hpp:774
void set_seed(uint)
Set the seed attribute.
Definition functions.hpp:796
Perlin 'billow' (x, y) function class.
Definition functions.hpp:870
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:886
Perlin (x, y) function class.
Definition functions.hpp:837
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:853
Perlin 'half' (x, y) function class.
Definition functions.hpp:903
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:922
float k
Definition functions.hpp:905
Perlin 'mix' (x, y) function class.
Definition functions.hpp:939
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:955
RectangleFunction (x, y) function class.
Definition functions.hpp:322
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:344
float rx
Definition functions.hpp:352
float ry
Radius of the rectangle.
Definition functions.hpp:352
Vec2< float > center
Primitive reference center.
Definition functions.hpp:355
float slope
Slope of the rectangle.
Definition functions.hpp:354
float angle
Angle of the rectangle.
Definition functions.hpp:353
Rift (x, y) function class.
Definition functions.hpp:370
bool sharp_bottom
Rift bottom sharpness.
Definition functions.hpp:403
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:400
float width
Rift width.
Definition functions.hpp:402
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:392
float slope
Rift slope.
Definition functions.hpp:401
Vec2< float > center
Primitive reference center.
Definition functions.hpp:404
OpenSimplex2 (x, y) function class.
Definition functions.hpp:972
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:988
OpenSimplex2S (x, y) function class.
Definition functions.hpp:1005
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:1021
Slope (x, y) function class.
Definition functions.hpp:419
float slope
Step slope.
Definition functions.hpp:444
Vec2< float > center
Primitive reference center.
Definition functions.hpp:445
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:435
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:443
Step (x, y) function class.
Definition functions.hpp:460
Vec2< float > center
Primitive reference center.
Definition functions.hpp:486
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:484
float slope
Step slope.
Definition functions.hpp:485
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:476
Value Cubic noise (x, y) function class.
Definition functions.hpp:1071
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:1087
ValueDelaunayNoise (x, y) function class.
Definition functions.hpp:1104
void update_interpolation_function()
Update base interpolation.
Definition noise_functions.cpp:138
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:1130
void set_kw(Vec2< float > new_kw)
Set the wavenumber attribute.
Definition functions.hpp:1119
ValueLinearNoiseFunction (x, y) function class.
Definition functions.hpp:1146
void set_kw(Vec2< float > new_kw)
Set the wavenumber attribute.
Definition functions.hpp:1161
void update_interpolation_function()
Update base interpolation.
Definition noise_functions.cpp:223
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:1172
Value noise (x, y) function class.
Definition functions.hpp:1038
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:1054
Wave dune (x, y) function class.
Definition functions.hpp:502
Vec2< float > kw
Frequency scaling vector.
Definition functions.hpp:535
float xbottom
1]).
Definition functions.hpp:538
float xtop
Relative location of the top of the dune profile (in [0, 1]).
Definition functions.hpp:537
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:536
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:527
float phase_shift
Phase shift (in radians).
Definition functions.hpp:540
Wave sine (x, y) function class.
Definition functions.hpp:555
Vec2< float > kw
Frequency scaling vector.
Definition functions.hpp:580
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:572
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:581
float phase_shift
Phase shift (in radians).
Definition functions.hpp:582
Wave square (x, y) function class.
Definition functions.hpp:597
Vec2< float > kw
Frequency scaling vector.
Definition functions.hpp:622
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:614
float phase_shift
Phase shift (in radians).
Definition functions.hpp:624
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:623
Wave triangular (x, y) function class.
Definition functions.hpp:640
float slant_ratio
Relative location of the triangle apex, in [0, 1].
Definition functions.hpp:671
Vec2< float > kw
Frequency scaling vector.
Definition functions.hpp:669
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:670
float phase_shift
Phase shift (in radians).
Definition functions.hpp:672
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:661
Worley (x, y) function class.
Definition functions.hpp:1221
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:1249
float ratio
Amplitude ratio between each Worley noise.
Definition functions.hpp:1226
float k
Transition smoothing parameter.
Definition functions.hpp:1231
Worley (x, y) function class.
Definition functions.hpp:1188
void set_seed(uint new_seed)
Set the seed attribute.
Definition functions.hpp:1204
Provides core mathematical utilities for procedural generation, including trigonometry,...
Definition algebra.hpp:28
std::unique_ptr< hmap::NoiseFunction > create_noise_function_from_type(NoiseType noise_type, Vec2< float > kw, uint seed)
Create a noise function based on the specified noise type.
Definition noise_functions.cpp:334
std::function< float(float, float)> make_xy_function_from_array(const Array &array, const Vec4< float > &bbox={0.f, 1.f, 0.f, 1.f})
Create a continuous 2D function from a sampled array.
Definition functions.cpp:10
NoiseType
Enumeration of various noise types used for procedural generation.
Definition functions.hpp:62
@ WORLEY
Worley.
Definition functions.hpp:73
@ SIMPLEX2S
OpenSimplex2S.
Definition functions.hpp:68
@ WORLEY_DOUBLE
Worley double.
Definition functions.hpp:74
@ VALUE_DELAUNAY
Value (delaunay)
Definition functions.hpp:71
@ PERLIN_BILLOW
Perlin billow.
Definition functions.hpp:65
@ PARBERRY
Parberry (Perlin variant)
Definition functions.hpp:63
@ WORLEY_VALUE
Worley (cell value return)
Definition functions.hpp:75
@ PERLIN
Perlin.
Definition functions.hpp:64
@ SIMPLEX2
OpenSimplex2.
Definition functions.hpp:67
@ PERLIN_HALF
Perlin half.
Definition functions.hpp:66
@ VALUE_LINEAR
Value (linear)
Definition functions.hpp:72
@ VALUE_CUBIC
Value (cubic)
Definition functions.hpp:70
@ VALUE
Value.
Definition functions.hpp:69
Vec2 class for basic manipulation of 2D vectors.
Definition algebra.hpp:40
T x
Definition algebra.hpp:41