HighMap library (C++)
Loading...
Searching...
No Matches
functions.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
16#pragma once
17#include <cmath>
18#include <cstdint>
19#include <functional>
20#include <memory>
21#include <utility>
22#include <vector>
23
24#include "FastNoiseLite.h"
25#include "macrologger.h"
26
27#include "highmap/array.hpp"
28#include "highmap/math/core.hpp"
29
34#define HMAP_FCT_XY_TYPE std::function<float(float, float, float)>
35
36#define HMAP_GRADIENT_OFFSET 0.001f
37
38namespace hmap
39{
40
54std::function<float(float, float)> make_xy_function_from_array(
55 const Array &array,
56 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
57
82
83//----------------------------------------
84// Base Function class and derived
85//----------------------------------------
86
93{
94public:
99 Function() : delegate([](float, float, float) { return 0.f; })
100 {
101 }
102
106 virtual ~Function() = default;
107
112 explicit Function(HMAP_FCT_XY_TYPE delegate) : delegate(std::move(delegate))
113 {
114 }
115
120 HMAP_FCT_XY_TYPE get_delegate() const;
121
129 float get_value(float x, float y, float ctrl_param) const;
130
135 void set_delegate(HMAP_FCT_XY_TYPE new_delegate);
136
137private:
138 HMAP_FCT_XY_TYPE delegate;
139};
140
151{
152public:
161 ArrayFunction(Array array, glm::vec2 kw, bool periodic = true);
162
168 void set_array(Array new_array)
169 {
170 this->array = new_array;
171 }
172
173protected:
174 glm::vec2 kw;
175 bool periodic;
176
177private:
178 Array array;
179};
180
189{
190public:
197 BiquadFunction(float gain, glm::vec2 center);
198
199protected:
200 float gain;
201 glm::vec2 center;
202};
203
211class BumpFunction : public Function
212{
213public:
220 BumpFunction(float gain, glm::vec2 center);
221
222protected:
223 float gain;
224 glm::vec2 center;
225};
226
235{
236public:
250 float depth,
251 float lip_decay,
252 float lip_height_ratio,
253 glm::vec2 center);
254
255protected:
256 float radius;
257 float depth;
258 float lip_decay;
260 glm::vec2 center;
261};
262
267class DiskFunction : public Function
268{
269public:
277 DiskFunction(float radius, float slope, glm::vec2 center);
278
279protected:
280 float radius;
281 float slope;
282 glm::vec2 center;
283};
284
293{
294public:
301 GaussianPulseFunction(float sigma, glm::vec2 center);
302
308 void set_sigma(float new_sigma)
309 {
310 this->sigma = new_sigma;
311 this->inv_sigma2 = 1.f / (this->sigma * this->sigma);
312 }
313
314protected:
315 float sigma;
316 glm::vec2 center;
317
318private:
319 float inv_sigma2;
320};
321
327{
328public:
338 RectangleFunction(float rx,
339 float ry,
340 float angle,
341 float slope,
342 glm::vec2 center);
343
349 void set_angle(float new_angle)
350 {
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);
354 }
355
356protected:
357 float rx, ry;
358 float angle;
359 float slope;
360 glm::vec2 center;
361
362private:
363 float ca;
364 float sa;
365};
366
374class RiftFunction : public Function
375{
376public:
386 RiftFunction(float angle,
387 float slope,
388 float width,
389 bool sharp_bottom,
390 glm::vec2 center);
391
397 void set_angle(float new_angle)
398 {
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);
402 }
403
404protected:
405 float angle;
406 float slope;
407 float width;
409 glm::vec2 center;
410
411private:
412 float ca;
413 float sa;
414};
415
424{
425public:
433 SlopeFunction(float angle, float slope, glm::vec2 center);
434
440 void set_angle(float new_angle)
441 {
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);
445 }
446
447protected:
448 float angle;
449 float slope;
450 glm::vec2 center;
451
452private:
453 float ca;
454 float sa;
455};
456
464class StepFunction : public Function
465{
466public:
474 StepFunction(float angle, float slope, glm::vec2 center);
475
481 void set_angle(float new_angle)
482 {
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);
486 }
487
488protected:
489 float angle;
490 float slope;
491 glm::vec2 center;
492
493private:
494 float ca;
495 float sa;
496};
497
507{
508public:
522 WaveDuneFunction(glm::vec2 kw,
523 float angle,
524 float xtop,
525 float xbottom,
526 float phase_shift,
527 glm::vec2 center = {0.5f, 0.5f});
528
534 void set_angle(float new_angle)
535 {
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);
539 }
540
541protected:
542 glm::vec2 kw;
543 float angle;
544 float xtop;
545 float xbottom;
548 glm::vec2 center;
549
550private:
551 float ca;
552 float sa;
553};
554
563{
564public:
574 WaveSineFunction(glm::vec2 kw,
575 float angle,
576 float phase_shift,
577 glm::vec2 center = {0.5f, 0.5f});
578
584 void set_angle(float new_angle)
585 {
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);
589 }
590
591protected:
592 glm::vec2 kw;
593 float angle;
595 glm::vec2 center;
596
597private:
598 float ca;
599 float sa;
600};
601
610{
611public:
621 WaveSquareFunction(glm::vec2 kw,
622 float angle,
623 float phase_shift,
624 glm::vec2 center = {0.5f, 0.5f});
625
631 void set_angle(float new_angle)
632 {
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);
636 }
637
638protected:
639 glm::vec2 kw;
640 float angle;
642 glm::vec2 center;
643
644private:
645 float ca;
646 float sa;
647};
648
658{
659public:
670 WaveTriangularFunction(glm::vec2 kw,
671 float angle,
672 float slant_ratio,
673 float phase_shift,
674 glm::vec2 center = {0.5f, 0.5f});
675
681 void set_angle(float new_angle)
682 {
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);
686 }
687
688protected:
689 glm::vec2 kw;
690 float angle;
693 glm::vec2 center;
694
695private:
696 float ca;
697 float sa;
698};
699
700//----------------------------------------
701// NoiseFunction class and derived
702//----------------------------------------
703
714{
715public:
720 NoiseFunction() : Function(), kw(glm::vec2(0.f, 0.f)), seed(0)
721 {
722 }
723
728 NoiseFunction(glm::vec2 kw) : Function(), kw(kw), seed(0)
729 {
730 }
731
737 NoiseFunction(glm::vec2 kw, std::uint32_t seed)
738 : Function(), kw(kw), seed(seed)
739 {
740 }
741
746 glm::vec2 get_kw() const
747 {
748 return this->kw;
749 }
750
755 std::uint32_t get_seed() const
756 {
757 return this->seed;
758 }
759
764 virtual void set_seed(std::uint32_t new_seed)
765 {
766 this->seed = new_seed;
767 }
768
773 virtual void set_kw(glm::vec2 new_kw)
774 {
775 this->kw = new_kw;
776 }
777
778protected:
779 glm::vec2 kw;
780 std::uint32_t seed;
781};
782
783//----------------------------------------
784// Actual functions
785//----------------------------------------
786
791{
792public:
796 float mu;
797
806 ParberryFunction(glm::vec2 kw, std::uint32_t seed, float mu);
807
811 void initialize();
812
818 void set_seed(std::uint32_t /*new_seed*/)
819 {
820 // FIX ME seed cannot be changed with current implemtantion.
821 }
822
823private:
827 int perlin_b = 0X100;
828
832 int perlin_bm = 0xff;
833
837 int perlin_n = 0x100;
838
842 std::vector<int> p;
843
847 std::vector<std::vector<float>> g2;
848
852 std::vector<float> m;
853};
854
859{
860public:
868 PerlinFunction(glm::vec2 kw, std::uint32_t seed);
869
875 void set_seed(std::uint32_t new_seed)
876 {
877 NoiseFunction::set_seed(new_seed);
878 this->noise.SetSeed(new_seed);
879 }
880
881private:
885 FastNoiseLite noise;
886};
887
892{
893public:
901 PerlinBillowFunction(glm::vec2 kw, std::uint32_t seed);
902
908 void set_seed(std::uint32_t new_seed)
909 {
910 NoiseFunction::set_seed(new_seed);
911 this->noise.SetSeed(new_seed);
912 }
913
914private:
918 FastNoiseLite noise;
919};
920
925{
926public:
927 float k;
928
937 PerlinHalfFunction(glm::vec2 kw, std::uint32_t seed, float k);
938
944 void set_seed(std::uint32_t new_seed)
945 {
946 NoiseFunction::set_seed(new_seed);
947 this->noise.SetSeed(new_seed);
948 }
949
950private:
954 FastNoiseLite noise;
955};
956
961{
962public:
970 PerlinMixFunction(glm::vec2 kw, std::uint32_t seed);
971
977 void set_seed(std::uint32_t new_seed)
978 {
979 NoiseFunction::set_seed(new_seed);
980 this->noise.SetSeed(new_seed);
981 }
982
983private:
987 FastNoiseLite noise;
988};
989
994{
995public:
1003 Simplex2Function(glm::vec2 kw, std::uint32_t seed);
1004
1010 void set_seed(std::uint32_t new_seed)
1011 {
1012 NoiseFunction::set_seed(new_seed);
1013 this->noise.SetSeed(new_seed);
1014 }
1015
1016private:
1020 FastNoiseLite noise;
1021};
1022
1027{
1028public:
1036 Simplex2SFunction(glm::vec2 kw, std::uint32_t seed);
1037
1043 void set_seed(std::uint32_t new_seed)
1044 {
1045 NoiseFunction::set_seed(new_seed);
1046 this->noise.SetSeed(new_seed);
1047 }
1048
1049private:
1053 FastNoiseLite noise;
1054};
1055
1060{
1061public:
1069 ValueNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1070
1076 void set_seed(std::uint32_t new_seed)
1077 {
1078 NoiseFunction::set_seed(new_seed);
1079 this->noise.SetSeed(new_seed);
1080 }
1081
1082private:
1086 FastNoiseLite noise;
1087};
1088
1093{
1094public:
1102 ValueCubicNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1103
1109 void set_seed(std::uint32_t new_seed)
1110 {
1111 NoiseFunction::set_seed(new_seed);
1112 this->noise.SetSeed(new_seed);
1113 }
1114
1115private:
1119 FastNoiseLite noise;
1120};
1121
1126{
1127public:
1134 ValueDelaunayNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1135
1141 void set_kw(glm::vec2 new_kw)
1142 {
1143 NoiseFunction::set_kw(new_kw);
1145 }
1146
1152 void set_seed(std::uint32_t new_seed)
1153 {
1154 NoiseFunction::set_seed(new_seed);
1156 }
1157
1162};
1163
1168{
1169public:
1176 ValueLinearNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1177
1183 void set_kw(glm::vec2 new_kw)
1184 {
1185 NoiseFunction::set_kw(new_kw);
1187 }
1188
1194 void set_seed(std::uint32_t new_seed)
1195 {
1196 NoiseFunction::set_seed(new_seed);
1198 }
1199
1204};
1205
1210{
1211public:
1219 WorleyFunction(glm::vec2 kw,
1220 std::uint32_t seed,
1221 bool return_cell_value = false);
1222
1228 void set_seed(std::uint32_t new_seed)
1229 {
1230 NoiseFunction::set_seed(new_seed);
1231 this->noise.SetSeed(new_seed);
1232 }
1233
1234private:
1238 FastNoiseLite noise;
1239};
1240
1245{
1246public:
1250 float ratio;
1251
1255 float k;
1256
1266 WorleyDoubleFunction(glm::vec2 kw, std::uint32_t seed, float ratio, float k);
1267
1273 void set_seed(std::uint32_t new_seed)
1274 {
1275 NoiseFunction::set_seed(new_seed);
1276 this->noise1.SetSeed(new_seed);
1277 this->noise2.SetSeed(new_seed + 1);
1278 }
1279
1280private:
1284 FastNoiseLite noise1, noise2;
1285};
1286
1287//----------------------------------------
1288// Composite functions
1289//----------------------------------------
1290
1301{
1302public:
1312 explicit GenericFractalFunction(std::unique_ptr<NoiseFunction> p_base,
1313 int octaves,
1314 float weight,
1315 float persistence,
1316 float lacunarity);
1317
1323 void set_kw(glm::vec2 new_kw) override
1324 {
1325 NoiseFunction::set_kw(new_kw);
1326 this->p_base->set_kw(new_kw);
1327 }
1328
1334 void set_lacunarity(float new_lacunarity)
1335 {
1336 this->lacunarity = new_lacunarity;
1337 }
1338
1344 void set_octaves(int new_octaves)
1345 {
1346 this->octaves = new_octaves;
1347 this->update_amp0();
1348 }
1349
1355 void set_persistence(float new_persistence)
1356 {
1357 this->persistence = new_persistence;
1358 this->update_amp0();
1359 }
1360
1366 void set_seed(std::uint32_t new_seed) override
1367 {
1368 NoiseFunction::set_seed(new_seed);
1369 this->p_base->set_seed(new_seed);
1370 }
1371
1377 void scale_amp0(float scale)
1378 {
1379 this->amp0 *= scale;
1380 }
1381
1387 float get_lacunarity() const
1388 {
1389 return this->lacunarity;
1390 }
1391
1397 int get_octaves() const
1398 {
1399 return this->octaves;
1400 }
1401
1407 float get_persistence() const
1408 {
1409 return this->persistence;
1410 }
1411
1417 float get_weight() const
1418 {
1419 return this->weight;
1420 }
1421
1422protected:
1427 void update_amp0();
1428
1429protected:
1430 std::unique_ptr<NoiseFunction>
1433 float weight;
1436 float amp0;
1437};
1438
1444{
1445public:
1455 FbmFunction(std::unique_ptr<NoiseFunction> p_base,
1456 int octaves,
1457 float weight,
1458 float persistence,
1459 float lacunarity);
1460};
1466{
1467public:
1478 FbmIqFunction(std::unique_ptr<NoiseFunction> p_base,
1479 int octaves,
1480 float weight,
1481 float persistence,
1482 float lacunarity,
1483 float gradient_scale);
1484
1490 void set_gradient_scale(float new_gradient_scale)
1491 {
1492 this->gradient_scale = new_gradient_scale;
1493 }
1494
1495protected:
1497};
1498
1504{
1505public:
1519 FbmJordanFunction(std::unique_ptr<NoiseFunction> p_base,
1520 int octaves,
1521 float weight,
1522 float persistence,
1523 float lacunarity,
1524 float warp0,
1525 float damp0,
1526 float warp_scale,
1527 float damp_scale);
1528
1534 void set_warp0(float new_warp0)
1535 {
1536 this->warp0 = new_warp0;
1537 }
1538
1544 void set_damp0(float new_damp0)
1545 {
1546 this->damp0 = new_damp0;
1547 }
1548
1554 void set_warp_scale(float new_warp_scale)
1555 {
1556 this->warp_scale = new_warp_scale;
1557 }
1558
1564 void set_damp_scale(float new_damp_scale)
1565 {
1566 this->damp_scale = new_damp_scale;
1567 }
1568
1569protected:
1570 float warp0;
1571 float damp0;
1574};
1575
1581{
1582public:
1592 FbmPingpongFunction(std::unique_ptr<NoiseFunction> p_base,
1593 int octaves,
1594 float weight,
1595 float persistence,
1596 float lacunarity);
1597
1603 void set_k_smoothing(float new_k_smoothing)
1604 {
1605 this->k_smoothing = new_k_smoothing;
1606 }
1607
1608protected:
1610};
1611
1617{
1618public:
1629 FbmRidgedFunction(std::unique_ptr<NoiseFunction> p_base,
1630 int octaves,
1631 float weight,
1632 float persistence,
1633 float lacunarity,
1634 float k_smoothing);
1635
1641 void set_k_smoothing(float new_k_smoothing)
1642 {
1643 this->k_smoothing = new_k_smoothing;
1644 }
1645
1646protected:
1648};
1649
1655{
1656public:
1667 FbmSwissFunction(std::unique_ptr<NoiseFunction> p_base,
1668 int octaves,
1669 float weight,
1670 float persistence,
1671 float lacunarity,
1672 float warp_scale);
1673
1679 void set_warp_scale(float new_warp_scale)
1680 {
1681 this->warp_scale = new_warp_scale;
1682 this->warp_scale_normalized = new_warp_scale / this->kw.x;
1683 }
1684
1685protected:
1688};
1689
1690//----------------------------------------
1691// Field functions
1692//----------------------------------------
1693
1699{
1700public:
1706 FieldFunction(std::unique_ptr<Function> p_base);
1707
1719 FieldFunction(std::unique_ptr<Function> p_base,
1720 std::vector<float> xr,
1721 std::vector<float> yr,
1722 std::vector<float> zr);
1723
1729 void set_xr(std::vector<float> new_xr)
1730 {
1731 this->xr = new_xr;
1732 }
1733
1739 void set_yr(std::vector<float> new_yr)
1740 {
1741 this->yr = new_yr;
1742 }
1743
1750 void set_zr(std::vector<float> new_zr)
1751 {
1752 this->zr = new_zr;
1753 }
1754
1755protected:
1756 std::vector<float> xr;
1758 std::vector<float> yr;
1760 std::vector<float>
1763
1764private:
1765 std::unique_ptr<Function> p_base;
1766
1770 void setup_delegate();
1771};
1772
1773//----------------------------------------
1774// Helpers
1775//----------------------------------------
1776
1791std::unique_ptr<hmap::NoiseFunction> create_noise_function_from_type(
1792 NoiseType noise_type,
1793 glm::vec2 kw,
1794 std::uint32_t seed);
1795
1796} // namespace hmap
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