diff options
| author | Mel <einebeere@gmail.com> | 2022-10-29 21:44:56 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-29 21:44:56 +0200 |
| commit | ad694f46d5708ae8ca6a42ae9dab8dd9563de0b8 (patch) | |
| tree | 9cc0a6a95c351e50a930b0f256e83e2a4ec3429a /src | |
| parent | 40b2da87db59162baaa41710d2cc95101f1466f1 (diff) | |
| download | meowcraft-ad694f46d5708ae8ca6a42ae9dab8dd9563de0b8.tar.zst meowcraft-ad694f46d5708ae8ca6a42ae9dab8dd9563de0b8.zip | |
Smooth out noise at noise seed borders
Diffstat (limited to 'src')
| -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); |
