X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnoise.cpp;h=a5a9a2057957f361d449581eec3cbd29d94aeae6;hb=76b3ec0f6aa0dacf6d4944a2787991f3585299e8;hp=6d59224c2f41f4de89ae982627387fcacd7235a2;hpb=c877ddd21f402381d88a6bebdd5c7c0b4ac28ba9;p=blank.git diff --git a/src/noise.cpp b/src/noise.cpp index 6d59224..a5a9a20 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -12,12 +12,12 @@ constexpr float one_sixth = 1.0f/6.0f; namespace blank { -GaloisLFSR::GaloisLFSR(std::uint64_t seed) +GaloisLFSR::GaloisLFSR(std::uint64_t seed) noexcept : state(seed) { } -bool GaloisLFSR::operator ()() { +bool GaloisLFSR::operator ()() noexcept { bool result = state & 1; state >>= 1; if (result) { @@ -30,7 +30,7 @@ bool GaloisLFSR::operator ()() { } -SimplexNoise::SimplexNoise(unsigned int seed) +SimplexNoise::SimplexNoise(unsigned int seed) noexcept : grad({ { 1.0f, 1.0f, 0.0f }, { -1.0f, 1.0f, 0.0f }, @@ -45,16 +45,15 @@ SimplexNoise::SimplexNoise(unsigned int seed) { 0.0f, 1.0f, -1.0f }, { 0.0f, -1.0f, -1.0f }, }) { - unsigned int val = seed; + GaloisLFSR random(seed ^ 0x0123456789ACBDEF); for (size_t i = 0; i < 256; ++i) { - val = 2346765 * val + 6446345; - perm[i] = val % 256; + random(perm[i]); perm[i + 256] = perm[i]; } } -float SimplexNoise::operator ()(const glm::vec3 &in) const { +float SimplexNoise::operator ()(const glm::vec3 &in) const noexcept { float skew = (in.x + in.y + in.z) * one_third; glm::vec3 skewed(glm::floor(in + skew)); @@ -119,22 +118,22 @@ float SimplexNoise::operator ()(const glm::vec3 &in) const { } -unsigned char SimplexNoise::Perm(size_t idx) const { +unsigned char SimplexNoise::Perm(size_t idx) const noexcept { return perm[idx]; } -const glm::vec3 &SimplexNoise::Grad(size_t idx) const { +const glm::vec3 &SimplexNoise::Grad(size_t idx) const noexcept { return grad[idx % 12]; } -WorleyNoise::WorleyNoise(unsigned int seed) +WorleyNoise::WorleyNoise(unsigned int seed) noexcept : seed(seed) , num_points(8) { } -float WorleyNoise::operator ()(const glm::vec3 &in) const { +float WorleyNoise::operator ()(const glm::vec3 &in) const noexcept { glm::vec3 center = floor(in); float closest = 1.0f; // cannot be farther away than 1.0