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
26#include "highmap/array.hpp"
27#include "highmap/math/core.hpp"
28
33#define HMAP_FCT_XY_TYPE std::function<float(float, float, float)>
34
35#define HMAP_GRADIENT_OFFSET 0.001f
36
37namespace hmap
38{
39
53std::function<float(float, float)> make_xy_function_from_array(
54 const Array &array,
55 const glm::vec4 &bbox = {0.f, 1.f, 0.f, 1.f});
56
81
82//----------------------------------------
83// Base Function class and derived
84//----------------------------------------
85
92{
93public:
98 Function() : delegate([](float, float, float) { return 0.f; })
99 {
100 }
101
105 virtual ~Function() = default;
106
111 explicit Function(HMAP_FCT_XY_TYPE delegate) : delegate(std::move(delegate))
112 {
113 }
114
119 HMAP_FCT_XY_TYPE get_delegate() const;
120
128 float get_value(float x, float y, float ctrl_param) const;
129
134 void set_delegate(HMAP_FCT_XY_TYPE new_delegate);
135
136private:
137 HMAP_FCT_XY_TYPE delegate;
138};
139
150{
151public:
160 ArrayFunction(Array array, glm::vec2 kw, bool periodic = true);
161
167 void set_array(Array new_array)
168 {
169 this->array = new_array;
170 }
171
172protected:
173 glm::vec2 kw;
174 bool periodic;
175
176private:
177 Array array;
178};
179
188{
189public:
196 BiquadFunction(float gain, glm::vec2 center);
197
198protected:
199 float gain;
200 glm::vec2 center;
201};
202
210class BumpFunction : public Function
211{
212public:
219 BumpFunction(float gain, glm::vec2 center);
220
221protected:
222 float gain;
223 glm::vec2 center;
224};
225
234{
235public:
249 float depth,
250 float lip_decay,
251 float lip_height_ratio,
252 glm::vec2 center);
253
254protected:
255 float radius;
256 float depth;
257 float lip_decay;
259 glm::vec2 center;
260};
261
266class DiskFunction : public Function
267{
268public:
276 DiskFunction(float radius, float slope, glm::vec2 center);
277
278protected:
279 float radius;
280 float slope;
281 glm::vec2 center;
282};
283
292{
293public:
300 GaussianPulseFunction(float sigma, glm::vec2 center);
301
307 void set_sigma(float new_sigma)
308 {
309 this->sigma = new_sigma;
310 this->inv_sigma2 = 1.f / (this->sigma * this->sigma);
311 }
312
313protected:
314 float sigma;
315 glm::vec2 center;
316
317private:
318 float inv_sigma2;
319};
320
326{
327public:
337 RectangleFunction(float rx,
338 float ry,
339 float angle,
340 float slope,
341 glm::vec2 center);
342
348 void set_angle(float new_angle)
349 {
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);
353 }
354
355protected:
356 float rx, ry;
357 float angle;
358 float slope;
359 glm::vec2 center;
360
361private:
362 float ca;
363 float sa;
364};
365
373class RiftFunction : public Function
374{
375public:
385 RiftFunction(float angle,
386 float slope,
387 float width,
388 bool sharp_bottom,
389 glm::vec2 center);
390
396 void set_angle(float new_angle)
397 {
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);
401 }
402
403protected:
404 float angle;
405 float slope;
406 float width;
408 glm::vec2 center;
409
410private:
411 float ca;
412 float sa;
413};
414
423{
424public:
432 SlopeFunction(float angle, float slope, glm::vec2 center);
433
439 void set_angle(float new_angle)
440 {
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);
444 }
445
446protected:
447 float angle;
448 float slope;
449 glm::vec2 center;
450
451private:
452 float ca;
453 float sa;
454};
455
463class StepFunction : public Function
464{
465public:
473 StepFunction(float angle, float slope, glm::vec2 center);
474
480 void set_angle(float new_angle)
481 {
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);
485 }
486
487protected:
488 float angle;
489 float slope;
490 glm::vec2 center;
491
492private:
493 float ca;
494 float sa;
495};
496
506{
507public:
521 WaveDuneFunction(glm::vec2 kw,
522 float angle,
523 float xtop,
524 float xbottom,
525 float phase_shift,
526 glm::vec2 center = {0.5f, 0.5f});
527
533 void set_angle(float new_angle)
534 {
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);
538 }
539
540protected:
541 glm::vec2 kw;
542 float angle;
543 float xtop;
544 float xbottom;
547 glm::vec2 center;
548
549private:
550 float ca;
551 float sa;
552};
553
562{
563public:
573 WaveSineFunction(glm::vec2 kw,
574 float angle,
575 float phase_shift,
576 glm::vec2 center = {0.5f, 0.5f});
577
583 void set_angle(float new_angle)
584 {
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);
588 }
589
590protected:
591 glm::vec2 kw;
592 float angle;
594 glm::vec2 center;
595
596private:
597 float ca;
598 float sa;
599};
600
609{
610public:
620 WaveSquareFunction(glm::vec2 kw,
621 float angle,
622 float phase_shift,
623 glm::vec2 center = {0.5f, 0.5f});
624
630 void set_angle(float new_angle)
631 {
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);
635 }
636
637protected:
638 glm::vec2 kw;
639 float angle;
641 glm::vec2 center;
642
643private:
644 float ca;
645 float sa;
646};
647
657{
658public:
669 WaveTriangularFunction(glm::vec2 kw,
670 float angle,
671 float slant_ratio,
672 float phase_shift,
673 glm::vec2 center = {0.5f, 0.5f});
674
680 void set_angle(float new_angle)
681 {
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);
685 }
686
687protected:
688 glm::vec2 kw;
689 float angle;
692 glm::vec2 center;
693
694private:
695 float ca;
696 float sa;
697};
698
699//----------------------------------------
700// NoiseFunction class and derived
701//----------------------------------------
702
713{
714public:
719 NoiseFunction() : Function(), kw(glm::vec2(0.f, 0.f)), seed(0)
720 {
721 }
722
727 NoiseFunction(glm::vec2 kw) : Function(), kw(kw), seed(0)
728 {
729 }
730
736 NoiseFunction(glm::vec2 kw, std::uint32_t seed)
737 : Function(), kw(kw), seed(seed)
738 {
739 }
740
745 glm::vec2 get_kw() const
746 {
747 return this->kw;
748 }
749
754 std::uint32_t get_seed() const
755 {
756 return this->seed;
757 }
758
763 virtual void set_seed(std::uint32_t new_seed)
764 {
765 this->seed = new_seed;
766 }
767
772 virtual void set_kw(glm::vec2 new_kw)
773 {
774 this->kw = new_kw;
775 }
776
777protected:
778 glm::vec2 kw;
779 std::uint32_t seed;
780};
781
782//----------------------------------------
783// Actual functions
784//----------------------------------------
785
790{
791public:
795 float mu;
796
805 ParberryFunction(glm::vec2 kw, std::uint32_t seed, float mu);
806
810 void initialize();
811
817 void set_seed(std::uint32_t /*new_seed*/)
818 {
819 // FIX ME seed cannot be changed with current implemtantion.
820 }
821
822private:
826 int perlin_b = 0X100;
827
831 int perlin_bm = 0xff;
832
836 int perlin_n = 0x100;
837
841 std::vector<int> p;
842
846 std::vector<std::vector<float>> g2;
847
851 std::vector<float> m;
852};
853
858{
859public:
867 PerlinFunction(glm::vec2 kw, std::uint32_t seed);
868
874 void set_seed(std::uint32_t new_seed)
875 {
876 NoiseFunction::set_seed(new_seed);
877 this->noise.SetSeed(new_seed);
878 }
879
880private:
884 FastNoiseLite noise;
885};
886
891{
892public:
900 PerlinBillowFunction(glm::vec2 kw, std::uint32_t seed);
901
907 void set_seed(std::uint32_t new_seed)
908 {
909 NoiseFunction::set_seed(new_seed);
910 this->noise.SetSeed(new_seed);
911 }
912
913private:
917 FastNoiseLite noise;
918};
919
924{
925public:
926 float k;
927
936 PerlinHalfFunction(glm::vec2 kw, std::uint32_t seed, float k);
937
943 void set_seed(std::uint32_t new_seed)
944 {
945 NoiseFunction::set_seed(new_seed);
946 this->noise.SetSeed(new_seed);
947 }
948
949private:
953 FastNoiseLite noise;
954};
955
960{
961public:
969 PerlinMixFunction(glm::vec2 kw, std::uint32_t seed);
970
976 void set_seed(std::uint32_t new_seed)
977 {
978 NoiseFunction::set_seed(new_seed);
979 this->noise.SetSeed(new_seed);
980 }
981
982private:
986 FastNoiseLite noise;
987};
988
993{
994public:
1002 Simplex2Function(glm::vec2 kw, std::uint32_t seed);
1003
1009 void set_seed(std::uint32_t new_seed)
1010 {
1011 NoiseFunction::set_seed(new_seed);
1012 this->noise.SetSeed(new_seed);
1013 }
1014
1015private:
1019 FastNoiseLite noise;
1020};
1021
1026{
1027public:
1035 Simplex2SFunction(glm::vec2 kw, std::uint32_t seed);
1036
1042 void set_seed(std::uint32_t new_seed)
1043 {
1044 NoiseFunction::set_seed(new_seed);
1045 this->noise.SetSeed(new_seed);
1046 }
1047
1048private:
1052 FastNoiseLite noise;
1053};
1054
1059{
1060public:
1068 ValueNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1069
1075 void set_seed(std::uint32_t new_seed)
1076 {
1077 NoiseFunction::set_seed(new_seed);
1078 this->noise.SetSeed(new_seed);
1079 }
1080
1081private:
1085 FastNoiseLite noise;
1086};
1087
1092{
1093public:
1101 ValueCubicNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1102
1108 void set_seed(std::uint32_t new_seed)
1109 {
1110 NoiseFunction::set_seed(new_seed);
1111 this->noise.SetSeed(new_seed);
1112 }
1113
1114private:
1118 FastNoiseLite noise;
1119};
1120
1125{
1126public:
1133 ValueDelaunayNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1134
1140 void set_kw(glm::vec2 new_kw)
1141 {
1142 NoiseFunction::set_kw(new_kw);
1144 }
1145
1151 void set_seed(std::uint32_t new_seed)
1152 {
1153 NoiseFunction::set_seed(new_seed);
1155 }
1156
1161};
1162
1167{
1168public:
1175 ValueLinearNoiseFunction(glm::vec2 kw, std::uint32_t seed);
1176
1182 void set_kw(glm::vec2 new_kw)
1183 {
1184 NoiseFunction::set_kw(new_kw);
1186 }
1187
1193 void set_seed(std::uint32_t new_seed)
1194 {
1195 NoiseFunction::set_seed(new_seed);
1197 }
1198
1203};
1204
1209{
1210public:
1218 WorleyFunction(glm::vec2 kw,
1219 std::uint32_t seed,
1220 bool return_cell_value = false);
1221
1227 void set_seed(std::uint32_t new_seed)
1228 {
1229 NoiseFunction::set_seed(new_seed);
1230 this->noise.SetSeed(new_seed);
1231 }
1232
1233private:
1237 FastNoiseLite noise;
1238};
1239
1244{
1245public:
1249 float ratio;
1250
1254 float k;
1255
1265 WorleyDoubleFunction(glm::vec2 kw, std::uint32_t seed, float ratio, float k);
1266
1272 void set_seed(std::uint32_t new_seed)
1273 {
1274 NoiseFunction::set_seed(new_seed);
1275 this->noise1.SetSeed(new_seed);
1276 this->noise2.SetSeed(new_seed + 1);
1277 }
1278
1279private:
1283 FastNoiseLite noise1, noise2;
1284};
1285
1286//----------------------------------------
1287// Composite functions
1288//----------------------------------------
1289
1300{
1301public:
1311 explicit GenericFractalFunction(std::unique_ptr<NoiseFunction> p_base,
1312 int octaves,
1313 float weight,
1314 float persistence,
1315 float lacunarity);
1316
1322 void set_kw(glm::vec2 new_kw) override
1323 {
1324 NoiseFunction::set_kw(new_kw);
1325 this->p_base->set_kw(new_kw);
1326 }
1327
1333 void set_lacunarity(float new_lacunarity)
1334 {
1335 this->lacunarity = new_lacunarity;
1336 }
1337
1343 void set_octaves(int new_octaves)
1344 {
1345 this->octaves = new_octaves;
1346 this->update_amp0();
1347 }
1348
1354 void set_persistence(float new_persistence)
1355 {
1356 this->persistence = new_persistence;
1357 this->update_amp0();
1358 }
1359
1365 void set_seed(std::uint32_t new_seed) override
1366 {
1367 NoiseFunction::set_seed(new_seed);
1368 this->p_base->set_seed(new_seed);
1369 }
1370
1376 void scale_amp0(float scale)
1377 {
1378 this->amp0 *= scale;
1379 }
1380
1386 float get_lacunarity() const
1387 {
1388 return this->lacunarity;
1389 }
1390
1396 int get_octaves() const
1397 {
1398 return this->octaves;
1399 }
1400
1406 float get_persistence() const
1407 {
1408 return this->persistence;
1409 }
1410
1416 float get_weight() const
1417 {
1418 return this->weight;
1419 }
1420
1421protected:
1426 void update_amp0();
1427
1428protected:
1429 std::unique_ptr<NoiseFunction>
1432 float weight;
1435 float amp0;
1436};
1437
1443{
1444public:
1454 FbmFunction(std::unique_ptr<NoiseFunction> p_base,
1455 int octaves,
1456 float weight,
1457 float persistence,
1458 float lacunarity);
1459};
1465{
1466public:
1477 FbmIqFunction(std::unique_ptr<NoiseFunction> p_base,
1478 int octaves,
1479 float weight,
1480 float persistence,
1481 float lacunarity,
1482 float gradient_scale);
1483
1489 void set_gradient_scale(float new_gradient_scale)
1490 {
1491 this->gradient_scale = new_gradient_scale;
1492 }
1493
1494protected:
1496};
1497
1503{
1504public:
1518 FbmJordanFunction(std::unique_ptr<NoiseFunction> p_base,
1519 int octaves,
1520 float weight,
1521 float persistence,
1522 float lacunarity,
1523 float warp0,
1524 float damp0,
1525 float warp_scale,
1526 float damp_scale);
1527
1533 void set_warp0(float new_warp0)
1534 {
1535 this->warp0 = new_warp0;
1536 }
1537
1543 void set_damp0(float new_damp0)
1544 {
1545 this->damp0 = new_damp0;
1546 }
1547
1553 void set_warp_scale(float new_warp_scale)
1554 {
1555 this->warp_scale = new_warp_scale;
1556 }
1557
1563 void set_damp_scale(float new_damp_scale)
1564 {
1565 this->damp_scale = new_damp_scale;
1566 }
1567
1568protected:
1569 float warp0;
1570 float damp0;
1573};
1574
1580{
1581public:
1591 FbmPingpongFunction(std::unique_ptr<NoiseFunction> p_base,
1592 int octaves,
1593 float weight,
1594 float persistence,
1595 float lacunarity);
1596
1602 void set_k_smoothing(float new_k_smoothing)
1603 {
1604 this->k_smoothing = new_k_smoothing;
1605 }
1606
1607protected:
1609};
1610
1616{
1617public:
1628 FbmRidgedFunction(std::unique_ptr<NoiseFunction> p_base,
1629 int octaves,
1630 float weight,
1631 float persistence,
1632 float lacunarity,
1633 float k_smoothing);
1634
1640 void set_k_smoothing(float new_k_smoothing)
1641 {
1642 this->k_smoothing = new_k_smoothing;
1643 }
1644
1645protected:
1647};
1648
1654{
1655public:
1666 FbmSwissFunction(std::unique_ptr<NoiseFunction> p_base,
1667 int octaves,
1668 float weight,
1669 float persistence,
1670 float lacunarity,
1671 float warp_scale);
1672
1678 void set_warp_scale(float new_warp_scale)
1679 {
1680 this->warp_scale = new_warp_scale;
1681 this->warp_scale_normalized = new_warp_scale / this->kw.x;
1682 }
1683
1684protected:
1687};
1688
1689//----------------------------------------
1690// Field functions
1691//----------------------------------------
1692
1698{
1699public:
1705 FieldFunction(std::unique_ptr<Function> p_base);
1706
1718 FieldFunction(std::unique_ptr<Function> p_base,
1719 std::vector<float> xr,
1720 std::vector<float> yr,
1721 std::vector<float> zr);
1722
1728 void set_xr(std::vector<float> new_xr)
1729 {
1730 this->xr = new_xr;
1731 }
1732
1738 void set_yr(std::vector<float> new_yr)
1739 {
1740 this->yr = new_yr;
1741 }
1742
1749 void set_zr(std::vector<float> new_zr)
1750 {
1751 this->zr = new_zr;
1752 }
1753
1754protected:
1755 std::vector<float> xr;
1757 std::vector<float> yr;
1759 std::vector<float>
1762
1763private:
1764 std::unique_ptr<Function> p_base;
1765
1769 void setup_delegate();
1770};
1771
1772//----------------------------------------
1773// Helpers
1774//----------------------------------------
1775
1790std::unique_ptr<hmap::NoiseFunction> create_noise_function_from_type(
1791 NoiseType noise_type,
1792 glm::vec2 kw,
1793 std::uint32_t seed);
1794
1795} // 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: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