diff options
Diffstat (limited to 'src/Math/Noise.cpp')
| -rw-r--r-- | src/Math/Noise.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Math/Noise.cpp b/src/Math/Noise.cpp index a174efe..1ef8ce5 100644 --- a/src/Math/Noise.cpp +++ b/src/Math/Noise.cpp @@ -17,14 +17,16 @@ float noise2d(Vector<2> pos) { {0.01f, {250.0f, 20.0f}, 0.5f}, }; + auto wrap = [](auto x) -> float { + float wx = std::fmod(x, NOISE_SEED_SIZE); + return wx < 0 ? wx + NOISE_SEED_SIZE : wx; + }; + auto total_weight = 0.0f; auto res = 0.0f; for (const auto& layer : layers) { auto pos_with_scale_and_offset = (pos - layer.offset) * layer.scale; - auto p = pos_with_scale_and_offset.map([](auto x) -> float { - float wx = std::fmod(x, NOISE_SEED_SIZE); - return wx < 0 ? wx + NOISE_SEED_SIZE : wx; - }); + auto p = pos_with_scale_and_offset.map(wrap); auto x = p.x(); auto y = p.y(); @@ -33,7 +35,9 @@ float noise2d(Vector<2> pos) { auto x2 = x1 + 1.0f; auto y1 = y2 + 1.0f; - auto value = [](float x, float y){ return noise_seed[(uint)x][(uint)y] / 255.0f; }; + auto value = [=](float x, float y){ + return noise_seed[(uint)wrap(x)][(uint)wrap(y)] / 255.0f; + }; auto q12 = value(x1, y2); auto q22 = value(x2, y2); |
