From eb831608e0fbec27150c89178611b24047698a71 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 20 Jun 2020 01:15:37 +0200 Subject: [PATCH] Add smooth transitions between biomes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simliar to the way biome transitions are rendered in Minecraft itself, add smoothing by averaging biome-based colors over all biome values with distance ≤3 (1-norm). --- src/MinedMap.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/MinedMap.cpp b/src/MinedMap.cpp index e3107bb..885ecc2 100644 --- a/src/MinedMap.cpp +++ b/src/MinedMap.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ namespace MinedMap { +static const int BIOME_SMOOTH = 3; static const size_t DIM = World::Region::SIZE*World::Chunk::SIZE; @@ -90,7 +92,32 @@ static Resource::Color collectColors(size_t x, size_t z, const World::Block &blo if (!block.isVisible()) return Resource::Color(); - return block.getColor(biomeAt(x, z, biomemaps)); + std::unordered_map biomes; + for (int dx = -BIOME_SMOOTH; dx <= BIOME_SMOOTH; dx++) { + for (int dz = -BIOME_SMOOTH; dz <= BIOME_SMOOTH; dz++) { + if (std::abs(dx) + std::abs(dz) > BIOME_SMOOTH) + continue; + + uint8_t biome = biomeAt(x+dx, z+dz, biomemaps); + if (biomes.count(biome)) + biomes[biome]++; + else + biomes[biome] = 1; + } + } + + Resource::FloatColor c = {}; + size_t total = 0; + + for (const auto &e : biomes) { + uint8_t biome = e.first; + size_t count = e.second; + + c = c + count * block.getColor(biome); + total += count; + } + + return (1.0f / total) * c; } static void addChunk(Resource::Color image[DIM*DIM], uint8_t lightmap[2*DIM*DIM], size_t X, size_t Z,