24#include "FastNoiseLite.h"
25#include "macrologger.h"
34#define HMAP_FCT_XY_TYPE std::function<float(float, float, float)>
36#define HMAP_GRADIENT_OFFSET 0.001f
56 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
99 Function() : delegate([](float, float, float) {
return 0.f; })
112 explicit Function(HMAP_FCT_XY_TYPE delegate) : delegate(std::move(delegate))
129 float get_value(
float x,
float y,
float ctrl_param)
const;
138 HMAP_FCT_XY_TYPE delegate;
170 this->array = new_array;
310 this->sigma = new_sigma;
311 this->inv_sigma2 = 1.f / (this->sigma * this->
sigma);
351 this->angle = new_angle;
352 this->ca = std::cos(
angle / 180.f * M_PI);
353 this->sa = std::sin(
angle / 180.f * M_PI);
399 this->angle = new_angle;
400 this->ca = std::cos(
angle / 180.f * M_PI);
401 this->sa = std::sin(
angle / 180.f * M_PI);
442 this->angle = new_angle;
443 this->ca = std::cos(
angle / 180.f * M_PI);
444 this->sa = std::sin(
angle / 180.f * M_PI);
483 this->angle = new_angle;
484 this->ca = std::cos(
angle / 180.f * M_PI);
485 this->sa = std::sin(
angle / 180.f * M_PI);
527 glm::vec2
center = {0.5f, 0.5f});
536 this->angle = new_angle;
537 this->ca = std::cos(
angle / 180.f * M_PI);
538 this->sa = std::sin(
angle / 180.f * M_PI);
577 glm::vec2
center = {0.5f, 0.5f});
586 this->angle = new_angle;
587 this->ca = std::cos(
angle / 180.f * M_PI);
588 this->sa = std::sin(
angle / 180.f * M_PI);
624 glm::vec2
center = {0.5f, 0.5f});
633 this->angle = new_angle;
634 this->ca = std::cos(
angle / 180.f * M_PI);
635 this->sa = std::sin(
angle / 180.f * M_PI);
674 glm::vec2
center = {0.5f, 0.5f});
683 this->angle = new_angle;
684 this->ca = std::cos(
angle / 180.f * M_PI);
685 this->sa = std::sin(
angle / 180.f * M_PI);
766 this->
seed = new_seed;
827 int perlin_b = 0X100;
832 int perlin_bm = 0xff;
837 int perlin_n = 0x100;
847 std::vector<std::vector<float>> g2;
852 std::vector<float> m;
878 this->noise.SetSeed(new_seed);
911 this->noise.SetSeed(new_seed);
947 this->noise.SetSeed(new_seed);
980 this->noise.SetSeed(new_seed);
1013 this->noise.SetSeed(new_seed);
1020 FastNoiseLite noise;
1046 this->noise.SetSeed(new_seed);
1053 FastNoiseLite noise;
1079 this->noise.SetSeed(new_seed);
1086 FastNoiseLite noise;
1112 this->noise.SetSeed(new_seed);
1119 FastNoiseLite noise;
1221 bool return_cell_value =
false);
1231 this->noise.SetSeed(new_seed);
1238 FastNoiseLite noise;
1276 this->noise1.SetSeed(new_seed);
1277 this->noise2.SetSeed(new_seed + 1);
1284 FastNoiseLite noise1, noise2;
1326 this->p_base->set_kw(new_kw);
1336 this->lacunarity = new_lacunarity;
1346 this->octaves = new_octaves;
1357 this->persistence = new_persistence;
1369 this->p_base->set_seed(new_seed);
1379 this->
amp0 *= scale;
1430 std::unique_ptr<NoiseFunction>
1492 this->gradient_scale = new_gradient_scale;
1536 this->warp0 = new_warp0;
1546 this->damp0 = new_damp0;
1556 this->warp_scale = new_warp_scale;
1566 this->damp_scale = new_damp_scale;
1643 this->k_smoothing = new_k_smoothing;
1681 this->warp_scale = new_warp_scale;
1720 std::vector<float>
xr,
1721 std::vector<float>
yr,
1722 std::vector<float>
zr);
1765 std::unique_ptr<Function> p_base;
1770 void setup_delegate();
1794 std::uint32_t seed);
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Array (x, y) function class.
Definition functions.hpp:151
bool periodic
Flag indicating whether the domain is periodic or not.
Definition functions.hpp:175
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:174
void set_array(Array new_array)
Set the array object.
Definition functions.hpp:168
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
Biquad (x, y) function class.
Definition functions.hpp:189
glm::vec2 center
Primitive reference center.
Definition functions.hpp:201
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:200
Bump (x, y) function class.
Definition functions.hpp:212
glm::vec2 center
Primitive reference center.
Definition functions.hpp:224
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:223
Crater (x, y) function class.
Definition functions.hpp:235
float depth
Depth of the crater.
Definition functions.hpp:257
float lip_decay
Decay rate of the crater's lip.
Definition functions.hpp:258
glm::vec2 center
Primitive reference center.
Definition functions.hpp:260
float radius
Radius of the crater.
Definition functions.hpp:256
float lip_height_ratio
Height ratio of the crater's lip.
Definition functions.hpp:259
DiskFunction (x, y) function class.
Definition functions.hpp:268
glm::vec2 center
Primitive reference center.
Definition functions.hpp:282
float radius
Radius of the disk.
Definition functions.hpp:280
float slope
Slope of the disk.
Definition functions.hpp:281
Fractional Brownian Motion (FBM) function class.
Definition functions.hpp:1444
IQ layering function class.
Definition functions.hpp:1466
float gradient_scale
Gradient scale influence.
Definition functions.hpp:1496
void set_gradient_scale(float new_gradient_scale)
Set the gradient scale.
Definition functions.hpp:1490
Jordan layering function class.
Definition functions.hpp:1504
void set_damp0(float new_damp0)
Set the initial damp.
Definition functions.hpp:1544
float warp0
Initial warp.
Definition functions.hpp:1570
void set_warp0(float new_warp0)
Set the initial warp.
Definition functions.hpp:1534
float damp_scale
Damp scale.
Definition functions.hpp:1573
float damp0
Initial damp.
Definition functions.hpp:1571
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1554
float warp_scale
Warp scale.
Definition functions.hpp:1572
void set_damp_scale(float new_damp_scale)
Set the damp scale.
Definition functions.hpp:1564
Pingpong layering function class.
Definition functions.hpp:1581
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1603
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1609
Ridged layering function class.
Definition functions.hpp:1617
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1647
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1641
Swiss layering function class.
Definition functions.hpp:1655
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1679
float warp_scale
Warping scale.
Definition functions.hpp:1686
float warp_scale_normalized
Normalized warping scale.
Definition functions.hpp:1687
Field function class.
Definition functions.hpp:1699
std::vector< float > yr
Definition functions.hpp:1758
void set_xr(std::vector< float > new_xr)
Set the x coordinates representing the centers of the primitive.
Definition functions.hpp:1729
void set_yr(std::vector< float > new_yr)
Set the y coordinates representing the centers of the primitive.
Definition functions.hpp:1739
std::vector< float > xr
Definition functions.hpp:1756
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:1750
std::vector< float > zr
Definition functions.hpp:1761
A class that wraps a callable entity taking three floats and returning a float.
Definition functions.hpp:93
Function()
Default constructor. Initializes the delegate function to a default that returns 0.
Definition functions.hpp:99
HMAP_FCT_XY_TYPE get_delegate() const
Get the current delegate function.
Definition functions.cpp:44
void set_delegate(HMAP_FCT_XY_TYPE new_delegate)
Set a new delegate function.
Definition functions.cpp:54
float get_value(float x, float y, float ctrl_param) const
Call the delegate function with given arguments.
Definition functions.cpp:49
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:112
GaussianPulse (x, y) function class.
Definition functions.hpp:293
glm::vec2 center
Primitive reference center.
Definition functions.hpp:316
float sigma
Pulse half-width.
Definition functions.hpp:315
void set_sigma(float new_sigma)
Set the half-width.
Definition functions.hpp:308
A class for generating fractal noise functions based on an underlying noise function.
Definition functions.hpp:1301
float get_weight() const
Get the weight of the fractal noise.
Definition functions.hpp:1417
void set_octaves(int new_octaves)
Set the number of octaves in the fractal noise.
Definition functions.hpp:1344
void set_persistence(float new_persistence)
Set the persistence of the fractal noise.
Definition functions.hpp:1355
void scale_amp0(float scale)
Scale the initial amplitude of the fractal noise.
Definition functions.hpp:1377
int octaves
Number of octaves in the fractal noise.
Definition functions.hpp:1432
float get_lacunarity() const
Get the lacunarity of the fractal noise.
Definition functions.hpp:1387
float weight
Weight of the base noise function.
Definition functions.hpp:1433
int get_octaves() const
Get the number of octaves in the fractal noise.
Definition functions.hpp:1397
float amp0
Initial amplitude of the fractal noise.
Definition functions.hpp:1436
void set_kw(glm::vec2 new_kw) override
Set the frequency scaling vector.
Definition functions.hpp:1323
std::unique_ptr< NoiseFunction > p_base
Unique pointer to the base noise function.
Definition functions.hpp:1431
float lacunarity
Lacunarity of the fractal noise.
Definition functions.hpp:1435
float get_persistence() const
Get the persistence of the fractal noise.
Definition functions.hpp:1407
float persistence
Persistence of the fractal noise.
Definition functions.hpp:1434
void set_lacunarity(float new_lacunarity)
Set the lacunarity of the fractal noise.
Definition functions.hpp:1334
void update_amp0()
Update the initial amplitude (amp0) based on the current octaves and persistence.
Definition fbm_functions.cpp:396
void set_seed(std::uint32_t new_seed) override
Set a new random seed for the noise generation.
Definition functions.hpp:1366
A class for generating noise functions.
Definition functions.hpp:714
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:779
glm::vec2 get_kw() const
Get the frequency scaling vector.
Definition functions.hpp:746
virtual void set_kw(glm::vec2 new_kw)
Set a new frequency scaling vector.
Definition functions.hpp:773
virtual void set_seed(std::uint32_t new_seed)
Set a new random seed for noise generation.
Definition functions.hpp:764
std::uint32_t get_seed() const
Get the random seed.
Definition functions.hpp:755
NoiseFunction(glm::vec2 kw, std::uint32_t seed)
Constructor to initialize with specific frequency scaling and seed.
Definition functions.hpp:737
NoiseFunction()
Default constructor. Initializes with default frequency scaling and seed.
Definition functions.hpp:720
NoiseFunction(glm::vec2 kw)
Constructor to initialize with specific frequency scaling.
Definition functions.hpp:728
std::uint32_t seed
Random seed for noise generation.
Definition functions.hpp:780
Parberry (x, y) function class.
Definition functions.hpp:791
void initialize()
Initialize generator.
Definition parberry_function.cpp:30
float mu
Gradient magnitude exponent.
Definition functions.hpp:796
void set_seed(std::uint32_t)
Set the seed attribute.
Definition functions.hpp:818
Perlin 'billow' (x, y) function class.
Definition functions.hpp:892
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:908
Perlin (x, y) function class.
Definition functions.hpp:859
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:875
Perlin 'half' (x, y) function class.
Definition functions.hpp:925
float k
Definition functions.hpp:927
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:944
Perlin 'mix' (x, y) function class.
Definition functions.hpp:961
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:977
RectangleFunction (x, y) function class.
Definition functions.hpp:327
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:349
float rx
Definition functions.hpp:357
float ry
Radius of the rectangle.
Definition functions.hpp:357
float slope
Slope of the rectangle.
Definition functions.hpp:359
glm::vec2 center
Primitive reference center.
Definition functions.hpp:360
float angle
Angle of the rectangle.
Definition functions.hpp:358
Rift (x, y) function class.
Definition functions.hpp:375
bool sharp_bottom
Rift bottom sharpness.
Definition functions.hpp:408
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:405
glm::vec2 center
Primitive reference center.
Definition functions.hpp:409
float width
Rift width.
Definition functions.hpp:407
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:397
float slope
Rift slope.
Definition functions.hpp:406
OpenSimplex2 (x, y) function class.
Definition functions.hpp:994
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1010
OpenSimplex2S (x, y) function class.
Definition functions.hpp:1027
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1043
Slope (x, y) function class.
Definition functions.hpp:424
float slope
Step slope.
Definition functions.hpp:449
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:440
glm::vec2 center
Primitive reference center.
Definition functions.hpp:450
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:448
Step (x, y) function class.
Definition functions.hpp:465
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:489
glm::vec2 center
Primitive reference center.
Definition functions.hpp:491
float slope
Step slope.
Definition functions.hpp:490
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:481
Value Cubic noise (x, y) function class.
Definition functions.hpp:1093
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1109
ValueDelaunayNoise (x, y) function class.
Definition functions.hpp:1126
void update_interpolation_function()
Update base interpolation.
Definition noise_functions.cpp:147
void set_kw(glm::vec2 new_kw)
Set the wavenumber attribute.
Definition functions.hpp:1141
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1152
ValueLinearNoiseFunction (x, y) function class.
Definition functions.hpp:1168
void update_interpolation_function()
Update base interpolation.
Definition noise_functions.cpp:233
void set_kw(glm::vec2 new_kw)
Set the wavenumber attribute.
Definition functions.hpp:1183
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1194
Value noise (x, y) function class.
Definition functions.hpp:1060
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1076
Wave dune (x, y) function class.
Definition functions.hpp:507
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:542
glm::vec2 center
Primitive reference center.
Definition functions.hpp:548
float xbottom
1]).
Definition functions.hpp:545
float xtop
Relative location of the top of the dune profile (in [0, 1]).
Definition functions.hpp:544
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:543
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:534
float phase_shift
Phase shift (in radians).
Definition functions.hpp:547
Wave sine (x, y) function class.
Definition functions.hpp:563
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:592
glm::vec2 center
Primitive reference center.
Definition functions.hpp:595
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:584
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:593
float phase_shift
Phase shift (in radians).
Definition functions.hpp:594
Wave square (x, y) function class.
Definition functions.hpp:610
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:631
float phase_shift
Phase shift (in radians).
Definition functions.hpp:641
glm::vec2 center
Primitive reference center.
Definition functions.hpp:642
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:639
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:640
Wave triangular (x, y) function class.
Definition functions.hpp:658
float slant_ratio
Relative location of the triangle apex, in [0, 1].
Definition functions.hpp:691
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:689
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:690
float phase_shift
Phase shift (in radians).
Definition functions.hpp:692
glm::vec2 center
Primitive reference center.
Definition functions.hpp:693
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:681
Worley (x, y) function class.
Definition functions.hpp:1245
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1273
float ratio
Amplitude ratio between each Worley noise.
Definition functions.hpp:1250
float k
Transition smoothing parameter.
Definition functions.hpp:1255
Worley (x, y) function class.
Definition functions.hpp:1210
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1228
Definition algebra.hpp:23
std::unique_ptr< hmap::NoiseFunction > create_noise_function_from_type(NoiseType noise_type, glm::vec2 kw, std::uint32_t seed)
Create a noise function based on the specified noise type.
Definition noise_functions.cpp:344
std::function< float(float, float)> make_xy_function_from_array(const Array &array, const glm::vec4 &bbox={0.f, 1.f, 0.f, 1.f})
Create a continuous 2D function from a sampled array.
Definition functions.cpp:16
NoiseType
Enumeration of various noise types used for procedural generation.
Definition functions.hpp:67
@ WORLEY
Worley.
Definition functions.hpp:78
@ SIMPLEX2S
OpenSimplex2S.
Definition functions.hpp:73
@ WORLEY_DOUBLE
Worley double.
Definition functions.hpp:79
@ VALUE_DELAUNAY
Value (delaunay)
Definition functions.hpp:76
@ PERLIN_BILLOW
Perlin billow.
Definition functions.hpp:70
@ PARBERRY
Parberry (Perlin variant)
Definition functions.hpp:68
@ WORLEY_VALUE
Worley (cell value return)
Definition functions.hpp:80
@ PERLIN
Perlin.
Definition functions.hpp:69
@ SIMPLEX2
OpenSimplex2.
Definition functions.hpp:72
@ PERLIN_HALF
Perlin half.
Definition functions.hpp:71
@ VALUE_LINEAR
Value (linear)
Definition functions.hpp:77
@ VALUE_CUBIC
Value (cubic)
Definition functions.hpp:75
@ VALUE
Value.
Definition functions.hpp:74