X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnoise.hpp;h=166a60a71058b998d60df732f752259b993beea4;hb=e74f1ad236429f05db90c0ace825277e2a3fbc05;hp=c081fc6a64f842dc45042385f5a4c761da219380;hpb=e70967c971f77a4ac0f5c074e6eb94bdd0e2b7ab;p=blank.git diff --git a/src/noise.hpp b/src/noise.hpp index c081fc6..166a60a 100644 --- a/src/noise.hpp +++ b/src/noise.hpp @@ -1,11 +1,40 @@ #ifndef BLANK_NOISE_HPP_ #define BLANK_NOISE_HPP_ +#include +#include #include namespace blank { +class GaloisLFSR { + +public: + // seed should be non-zero + explicit GaloisLFSR(std::uint64_t seed); + + // get the next bit + bool operator ()(); + + template + void operator ()(T &out) { + constexpr int num_bits = + std::numeric_limits::digits + + std::numeric_limits::is_signed; + for (int i = 0; i < num_bits; ++i) { + operator ()(); + } + out = static_cast(state); + } + +private: + std::uint64_t state; + // bits 64, 63, 61, and 60 set to 1 (counting from 1 lo to hi) + static constexpr std::uint64_t mask = 0xD800000000000000; + +}; + /// (3D only) adaptation of Stefan Gustavson's SimplexNoise java class class SimplexNoise { @@ -24,6 +53,21 @@ private: }; + +/// implementation of Worley noise (aka Cell or Voroni noise) +class WorleyNoise { + +public: + explicit WorleyNoise(unsigned int seed); + + float operator ()(const glm::vec3 &) const; + +private: + const unsigned int seed; + const int num_points; + +}; + } #endif