24#include "FastNoiseLite.h"
33#define HMAP_FCT_XY_TYPE std::function<float(float, float, float)>
35#define HMAP_GRADIENT_OFFSET 0.001f
55 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
98 Function() : delegate([](float, float, float) {
return 0.f; })
111 explicit Function(HMAP_FCT_XY_TYPE delegate) : delegate(std::move(delegate))
128 float get_value(
float x,
float y,
float ctrl_param)
const;
137 HMAP_FCT_XY_TYPE delegate;
169 this->array = new_array;
309 this->sigma = new_sigma;
310 this->inv_sigma2 = 1.f / (this->sigma * this->
sigma);
350 this->angle = new_angle;
351 this->ca = std::cos(
angle / 180.f * M_PI);
352 this->sa = std::sin(
angle / 180.f * M_PI);
398 this->angle = new_angle;
399 this->ca = std::cos(
angle / 180.f * M_PI);
400 this->sa = std::sin(
angle / 180.f * M_PI);
441 this->angle = new_angle;
442 this->ca = std::cos(
angle / 180.f * M_PI);
443 this->sa = std::sin(
angle / 180.f * M_PI);
482 this->angle = new_angle;
483 this->ca = std::cos(
angle / 180.f * M_PI);
484 this->sa = std::sin(
angle / 180.f * M_PI);
526 glm::vec2
center = {0.5f, 0.5f});
535 this->angle = new_angle;
536 this->ca = std::cos(
angle / 180.f * M_PI);
537 this->sa = std::sin(
angle / 180.f * M_PI);
576 glm::vec2
center = {0.5f, 0.5f});
585 this->angle = new_angle;
586 this->ca = std::cos(
angle / 180.f * M_PI);
587 this->sa = std::sin(
angle / 180.f * M_PI);
623 glm::vec2
center = {0.5f, 0.5f});
632 this->angle = new_angle;
633 this->ca = std::cos(
angle / 180.f * M_PI);
634 this->sa = std::sin(
angle / 180.f * M_PI);
673 glm::vec2
center = {0.5f, 0.5f});
682 this->angle = new_angle;
683 this->ca = std::cos(
angle / 180.f * M_PI);
684 this->sa = std::sin(
angle / 180.f * M_PI);
765 this->
seed = new_seed;
826 int perlin_b = 0X100;
831 int perlin_bm = 0xff;
836 int perlin_n = 0x100;
846 std::vector<std::vector<float>> g2;
851 std::vector<float> m;
877 this->noise.SetSeed(new_seed);
910 this->noise.SetSeed(new_seed);
946 this->noise.SetSeed(new_seed);
979 this->noise.SetSeed(new_seed);
1012 this->noise.SetSeed(new_seed);
1019 FastNoiseLite noise;
1045 this->noise.SetSeed(new_seed);
1052 FastNoiseLite noise;
1078 this->noise.SetSeed(new_seed);
1085 FastNoiseLite noise;
1111 this->noise.SetSeed(new_seed);
1118 FastNoiseLite noise;
1220 bool return_cell_value =
false);
1230 this->noise.SetSeed(new_seed);
1237 FastNoiseLite noise;
1275 this->noise1.SetSeed(new_seed);
1276 this->noise2.SetSeed(new_seed + 1);
1283 FastNoiseLite noise1, noise2;
1325 this->p_base->set_kw(new_kw);
1335 this->lacunarity = new_lacunarity;
1345 this->octaves = new_octaves;
1356 this->persistence = new_persistence;
1368 this->p_base->set_seed(new_seed);
1429 std::unique_ptr<NoiseFunction>
1491 this->gradient_scale = new_gradient_scale;
1535 this->warp0 = new_warp0;
1545 this->damp0 = new_damp0;
1555 this->warp_scale = new_warp_scale;
1565 this->damp_scale = new_damp_scale;
1642 this->k_smoothing = new_k_smoothing;
1680 this->warp_scale = new_warp_scale;
1719 std::vector<float>
xr,
1720 std::vector<float>
yr,
1721 std::vector<float>
zr);
1764 std::unique_ptr<Function> p_base;
1769 void setup_delegate();
1793 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:150
bool periodic
Flag indicating whether the domain is periodic or not.
Definition functions.hpp:174
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:173
void set_array(Array new_array)
Set the array object.
Definition functions.hpp:167
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
Biquad (x, y) function class.
Definition functions.hpp:188
glm::vec2 center
Primitive reference center.
Definition functions.hpp:200
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:199
Bump (x, y) function class.
Definition functions.hpp:211
glm::vec2 center
Primitive reference center.
Definition functions.hpp:223
float gain
Gain value that controls the steepness of the bump.
Definition functions.hpp:222
Crater (x, y) function class.
Definition functions.hpp:234
float depth
Depth of the crater.
Definition functions.hpp:256
float lip_decay
Decay rate of the crater's lip.
Definition functions.hpp:257
glm::vec2 center
Primitive reference center.
Definition functions.hpp:259
float radius
Radius of the crater.
Definition functions.hpp:255
float lip_height_ratio
Height ratio of the crater's lip.
Definition functions.hpp:258
DiskFunction (x, y) function class.
Definition functions.hpp:267
glm::vec2 center
Primitive reference center.
Definition functions.hpp:281
float radius
Radius of the disk.
Definition functions.hpp:279
float slope
Slope of the disk.
Definition functions.hpp:280
Fractional Brownian Motion (FBM) function class.
Definition functions.hpp:1443
IQ layering function class.
Definition functions.hpp:1465
float gradient_scale
Gradient scale influence.
Definition functions.hpp:1495
void set_gradient_scale(float new_gradient_scale)
Set the gradient scale.
Definition functions.hpp:1489
Jordan layering function class.
Definition functions.hpp:1503
void set_damp0(float new_damp0)
Set the initial damp.
Definition functions.hpp:1543
float warp0
Initial warp.
Definition functions.hpp:1569
void set_warp0(float new_warp0)
Set the initial warp.
Definition functions.hpp:1533
float damp_scale
Damp scale.
Definition functions.hpp:1572
float damp0
Initial damp.
Definition functions.hpp:1570
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1553
float warp_scale
Warp scale.
Definition functions.hpp:1571
void set_damp_scale(float new_damp_scale)
Set the damp scale.
Definition functions.hpp:1563
Pingpong layering function class.
Definition functions.hpp:1580
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1602
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1608
Ridged layering function class.
Definition functions.hpp:1616
float k_smoothing
Smoothing parameter.
Definition functions.hpp:1646
void set_k_smoothing(float new_k_smoothing)
Set the smoothing parameter.
Definition functions.hpp:1640
Swiss layering function class.
Definition functions.hpp:1654
void set_warp_scale(float new_warp_scale)
Set the warp scale.
Definition functions.hpp:1678
float warp_scale
Warping scale.
Definition functions.hpp:1685
float warp_scale_normalized
Normalized warping scale.
Definition functions.hpp:1686
Field function class.
Definition functions.hpp:1698
std::vector< float > yr
Definition functions.hpp:1757
void set_xr(std::vector< float > new_xr)
Set the x coordinates representing the centers of the primitive.
Definition functions.hpp:1728
void set_yr(std::vector< float > new_yr)
Set the y coordinates representing the centers of the primitive.
Definition functions.hpp:1738
std::vector< float > xr
Definition functions.hpp:1755
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:1749
std::vector< float > zr
Definition functions.hpp:1760
A class that wraps a callable entity taking three floats and returning a float.
Definition functions.hpp:92
Function()
Default constructor. Initializes the delegate function to a default that returns 0.
Definition functions.hpp:98
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:111
GaussianPulse (x, y) function class.
Definition functions.hpp:292
glm::vec2 center
Primitive reference center.
Definition functions.hpp:315
float sigma
Pulse half-width.
Definition functions.hpp:314
void set_sigma(float new_sigma)
Set the half-width.
Definition functions.hpp:307
A class for generating fractal noise functions based on an underlying noise function.
Definition functions.hpp:1300
float get_weight() const
Get the weight of the fractal noise.
Definition functions.hpp:1416
void set_octaves(int new_octaves)
Set the number of octaves in the fractal noise.
Definition functions.hpp:1343
void set_persistence(float new_persistence)
Set the persistence of the fractal noise.
Definition functions.hpp:1354
void scale_amp0(float scale)
Scale the initial amplitude of the fractal noise.
Definition functions.hpp:1376
int octaves
Number of octaves in the fractal noise.
Definition functions.hpp:1431
float get_lacunarity() const
Get the lacunarity of the fractal noise.
Definition functions.hpp:1386
float weight
Weight of the base noise function.
Definition functions.hpp:1432
int get_octaves() const
Get the number of octaves in the fractal noise.
Definition functions.hpp:1396
float amp0
Initial amplitude of the fractal noise.
Definition functions.hpp:1435
void set_kw(glm::vec2 new_kw) override
Set the frequency scaling vector.
Definition functions.hpp:1322
std::unique_ptr< NoiseFunction > p_base
Unique pointer to the base noise function.
Definition functions.hpp:1430
float lacunarity
Lacunarity of the fractal noise.
Definition functions.hpp:1434
float get_persistence() const
Get the persistence of the fractal noise.
Definition functions.hpp:1406
float persistence
Persistence of the fractal noise.
Definition functions.hpp:1433
void set_lacunarity(float new_lacunarity)
Set the lacunarity of the fractal noise.
Definition functions.hpp:1333
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:1365
A class for generating noise functions.
Definition functions.hpp:713
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:778
glm::vec2 get_kw() const
Get the frequency scaling vector.
Definition functions.hpp:745
virtual void set_kw(glm::vec2 new_kw)
Set a new frequency scaling vector.
Definition functions.hpp:772
virtual void set_seed(std::uint32_t new_seed)
Set a new random seed for noise generation.
Definition functions.hpp:763
std::uint32_t get_seed() const
Get the random seed.
Definition functions.hpp:754
NoiseFunction(glm::vec2 kw, std::uint32_t seed)
Constructor to initialize with specific frequency scaling and seed.
Definition functions.hpp:736
NoiseFunction()
Default constructor. Initializes with default frequency scaling and seed.
Definition functions.hpp:719
NoiseFunction(glm::vec2 kw)
Constructor to initialize with specific frequency scaling.
Definition functions.hpp:727
std::uint32_t seed
Random seed for noise generation.
Definition functions.hpp:779
Parberry (x, y) function class.
Definition functions.hpp:790
void initialize()
Initialize generator.
Definition parberry_function.cpp:30
float mu
Gradient magnitude exponent.
Definition functions.hpp:795
void set_seed(std::uint32_t)
Set the seed attribute.
Definition functions.hpp:817
Perlin 'billow' (x, y) function class.
Definition functions.hpp:891
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:907
Perlin (x, y) function class.
Definition functions.hpp:858
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:874
Perlin 'half' (x, y) function class.
Definition functions.hpp:924
float k
Definition functions.hpp:926
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:943
Perlin 'mix' (x, y) function class.
Definition functions.hpp:960
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:976
RectangleFunction (x, y) function class.
Definition functions.hpp:326
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:348
float rx
Definition functions.hpp:356
float ry
Radius of the rectangle.
Definition functions.hpp:356
float slope
Slope of the rectangle.
Definition functions.hpp:358
glm::vec2 center
Primitive reference center.
Definition functions.hpp:359
float angle
Angle of the rectangle.
Definition functions.hpp:357
Rift (x, y) function class.
Definition functions.hpp:374
bool sharp_bottom
Rift bottom sharpness.
Definition functions.hpp:407
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:404
glm::vec2 center
Primitive reference center.
Definition functions.hpp:408
float width
Rift width.
Definition functions.hpp:406
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:396
float slope
Rift slope.
Definition functions.hpp:405
OpenSimplex2 (x, y) function class.
Definition functions.hpp:993
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1009
OpenSimplex2S (x, y) function class.
Definition functions.hpp:1026
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1042
Slope (x, y) function class.
Definition functions.hpp:423
float slope
Step slope.
Definition functions.hpp:448
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:439
glm::vec2 center
Primitive reference center.
Definition functions.hpp:449
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:447
Step (x, y) function class.
Definition functions.hpp:464
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:488
glm::vec2 center
Primitive reference center.
Definition functions.hpp:490
float slope
Step slope.
Definition functions.hpp:489
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:480
Value Cubic noise (x, y) function class.
Definition functions.hpp:1092
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1108
ValueDelaunayNoise (x, y) function class.
Definition functions.hpp:1125
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:1140
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1151
ValueLinearNoiseFunction (x, y) function class.
Definition functions.hpp:1167
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:1182
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1193
Value noise (x, y) function class.
Definition functions.hpp:1059
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1075
Wave dune (x, y) function class.
Definition functions.hpp:506
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:541
glm::vec2 center
Primitive reference center.
Definition functions.hpp:547
float xbottom
1]).
Definition functions.hpp:544
float xtop
Relative location of the top of the dune profile (in [0, 1]).
Definition functions.hpp:543
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:542
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:533
float phase_shift
Phase shift (in radians).
Definition functions.hpp:546
Wave sine (x, y) function class.
Definition functions.hpp:562
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:591
glm::vec2 center
Primitive reference center.
Definition functions.hpp:594
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:583
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:592
float phase_shift
Phase shift (in radians).
Definition functions.hpp:593
Wave square (x, y) function class.
Definition functions.hpp:609
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:630
float phase_shift
Phase shift (in radians).
Definition functions.hpp:640
glm::vec2 center
Primitive reference center.
Definition functions.hpp:641
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:638
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:639
Wave triangular (x, y) function class.
Definition functions.hpp:657
float slant_ratio
Relative location of the triangle apex, in [0, 1].
Definition functions.hpp:690
glm::vec2 kw
Frequency scaling vector.
Definition functions.hpp:688
float angle
Overall rotation angle (in degrees).
Definition functions.hpp:689
float phase_shift
Phase shift (in radians).
Definition functions.hpp:691
glm::vec2 center
Primitive reference center.
Definition functions.hpp:692
void set_angle(float new_angle)
Set the angle.
Definition functions.hpp:680
Worley (x, y) function class.
Definition functions.hpp:1244
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1272
float ratio
Amplitude ratio between each Worley noise.
Definition functions.hpp:1249
float k
Transition smoothing parameter.
Definition functions.hpp:1254
Worley (x, y) function class.
Definition functions.hpp:1209
void set_seed(std::uint32_t new_seed)
Set the seed attribute.
Definition functions.hpp:1227
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
Cloud scale(const Cloud &cloud, glm::vec2 scale, glm::vec2 center={0.5f, 0.5f})
Scales the point coordinates in a cloud relative to a center point.
Definition cloud_functions.cpp:165
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:66
@ WORLEY
Worley.
Definition functions.hpp:77
@ SIMPLEX2S
OpenSimplex2S.
Definition functions.hpp:72
@ WORLEY_DOUBLE
Worley double.
Definition functions.hpp:78
@ VALUE_DELAUNAY
Value (delaunay)
Definition functions.hpp:75
@ PERLIN_BILLOW
Perlin billow.
Definition functions.hpp:69
@ PARBERRY
Parberry (Perlin variant)
Definition functions.hpp:67
@ WORLEY_VALUE
Worley (cell value return)
Definition functions.hpp:79
@ PERLIN
Perlin.
Definition functions.hpp:68
@ SIMPLEX2
OpenSimplex2.
Definition functions.hpp:71
@ PERLIN_HALF
Perlin half.
Definition functions.hpp:70
@ VALUE_LINEAR
Value (linear)
Definition functions.hpp:76
@ VALUE_CUBIC
Value (cubic)
Definition functions.hpp:74
@ VALUE
Value.
Definition functions.hpp:73