]> git.localhorst.tv Git - blank.git/blobdiff - src/noise.hpp
noexcept all the things
[blank.git] / src / noise.hpp
index 166a60a71058b998d60df732f752259b993beea4..0f370318cef376e614c2fde2f3d1d824b62e0871 100644 (file)
@@ -12,13 +12,13 @@ class GaloisLFSR {
 
 public:
        // seed should be non-zero
-       explicit GaloisLFSR(std::uint64_t seed);
+       explicit GaloisLFSR(std::uint64_t seed) noexcept;
 
        // get the next bit
-       bool operator ()();
+       bool operator ()() noexcept;
 
        template<class T>
-       void operator ()(T &out) {
+       void operator ()(T &out) noexcept {
                constexpr int num_bits =
                        std::numeric_limits<T>::digits +
                        std::numeric_limits<T>::is_signed;
@@ -35,17 +35,18 @@ private:
 
 };
 
+
 /// (3D only) adaptation of Stefan Gustavson's SimplexNoise java class
 class SimplexNoise {
 
 public:
-       explicit SimplexNoise(unsigned int seed);
+       explicit SimplexNoise(unsigned int seed) noexcept;
 
-       float operator ()(const glm::vec3 &) const;
+       float operator ()(const glm::vec3 &) const noexcept;
 
 private:
-       unsigned char Perm(size_t idx) const;
-       const glm::vec3 &Grad(size_t idx) const;
+       unsigned char Perm(size_t idx) const noexcept;
+       const glm::vec3 &Grad(size_t idx) const noexcept;
 
 private:
        unsigned char perm[512];
@@ -58,9 +59,9 @@ private:
 class WorleyNoise {
 
 public:
-       explicit WorleyNoise(unsigned int seed);
+       explicit WorleyNoise(unsigned int seed) noexcept;
 
-       float operator ()(const glm::vec3 &) const;
+       float operator ()(const glm::vec3 &) const noexcept;
 
 private:
        const unsigned int seed;
@@ -68,6 +69,29 @@ private:
 
 };
 
+
+template<class Noise>
+float OctaveNoise(
+       const Noise &noise,
+       const glm::vec3 &in,
+       int num,
+       float persistence,
+       float frequency = 1.0f,
+       float amplitude = 1.0f,
+       float growth = 2.0f
+) {
+       float total = 0.0f;
+       float max = 0.0f;
+       for (int i = 0; i < num; ++i) {
+               total += noise(in * frequency) * amplitude;
+               max += amplitude;
+               amplitude *= persistence;
+               frequency *= growth;
+       }
+
+       return total / max;
+}
+
 }
 
 #endif