X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnoise.hpp;h=0f370318cef376e614c2fde2f3d1d824b62e0871;hb=76b3ec0f6aa0dacf6d4944a2787991f3585299e8;hp=166a60a71058b998d60df732f752259b993beea4;hpb=c877ddd21f402381d88a6bebdd5c7c0b4ac28ba9;p=blank.git diff --git a/src/noise.hpp b/src/noise.hpp index 166a60a..0f37031 100644 --- a/src/noise.hpp +++ b/src/noise.hpp @@ -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 - void operator ()(T &out) { + void operator ()(T &out) noexcept { constexpr int num_bits = std::numeric_limits::digits + std::numeric_limits::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 +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