refactor: prevent desert from generation adjacent to mountain in biome generation

This commit is contained in:
2026-04-17 22:22:18 +08:00
parent e69d38ad94
commit f2328d19fd
5 changed files with 38 additions and 28 deletions

View File

@@ -4,13 +4,13 @@ constexpr int MAX_BLOCK_NUM = 5;
constexpr int MAX_UI_NUM = 1;
constexpr int CHUCK_SIZE = 16;
constexpr int DISTANCE = 16;
constexpr int DISTANCE = 24;
constexpr int MAX_BLOCK_STATUS = 1;
constexpr int MAX_CHARACTER = 128;
constexpr float NORMAL_FOV = 70.0f;
constexpr int MAX_BIOME_SUM = 4;
constexpr float BIOME_NOISE_FREQUENCY = 0.005f;
constexpr float BIOME_NOISE_FREQUENCY = 0.003f;
constexpr float VERTICES_POS[6][6][3] = {
// ===== front (z = +1) =====

View File

@@ -1,4 +1,5 @@
#pragma once
#include <cmath>
#include <array>
#include <functional>
#include <string>
@@ -29,6 +30,11 @@ struct ChunkPos {
};
};
constexpr float PLAIN_FREQ = 0.5f;
constexpr float FOREST_FREQ = 1.0f;
constexpr float DESERT_FREQ = 1.0f;
constexpr float MOUNTAIN_FREQ = 2.0f;
enum class Biome {
PLAIN = 0,
FOREST,
@@ -62,9 +68,20 @@ constexpr inline std::string get_biome_str(Biome biome) {
};
inline Biome get_biome_from_noise(float temp, float humid) {
if (temp < 0.5f && humid < 0.5f) return Biome::MOUNTAIN;
if (temp < 0.5f && humid >= 0.5f) return Biome::PLAIN;
if (temp >= 0.5f && humid < 0.5f) return Biome::DESERT;
auto weight = [](float t, float h, float ct, float ch) -> float {
float dt = t - ct;
float dh = h - ch;
float dist = std::sqrt(dt*dt + dh*dh);
return std::max(0.0f, 0.5f - dist);
};
float w_m = weight(temp, humid, 0.25f, 0.15f);
float w_p = weight(temp, humid, 0.50f, 0.40f);
float w_d = weight(temp, humid, 0.75f, 0.15f);
float w_f = weight(temp, humid, 0.75f, 0.75f);
w_m = pow(w_m, 8); w_p = pow(w_p, 8); w_d = pow(w_d, 8); w_f = pow(w_f, 8);
if (w_m >= w_p && w_m >= w_d && w_m >= w_f) return Biome::MOUNTAIN;
if (w_p >= w_m && w_p >= w_d && w_p >= w_f) return Biome::PLAIN;
if (w_d >= w_m && w_d >= w_p && w_d >= w_f) return Biome::DESERT;
return Biome::FOREST;
}
@@ -72,13 +89,13 @@ inline std::array<float, 3> get_noise_frequencies_for_biome(Biome biome) {
using enum Biome;
switch (biome) {
case PLAIN:
return {0.003f, 0.008f, 0.018f};
return {0.003f, 0.010f, 0.020f};
case FOREST:
return {0.004f, 0.012f, 0.022f};
case DESERT:
return {0.003f, 0.008f, 0.018f};
return {0.003f, 0.010f, 0.020f};
case MOUNTAIN:
return {0.006f, 0.015f, 0.03f};
return {0.006f, 0.015f, 0.030f};
}
Logger::warn("Unknown Biome");
return {0.003f, 0.015f, 0.06f};
@@ -88,11 +105,11 @@ inline BiomeHeightRange get_biome_height_range(Biome biome) {
using enum Biome;
switch (biome) {
case PLAIN:
return {62, 4};
return {62, 8};
case FOREST:
return {64, 8};
return {64, 12};
case DESERT:
return {61, 8};
return {61, 12};
case MOUNTAIN:
return {70, 70};
}

View File

@@ -2,5 +2,5 @@
#include <glm/glm.hpp>
namespace Math {
void extract_frustum_planes(const glm::mat4& mvp_matrix, std::vector<glm::vec4>& planes);
int get_interpolated_height(float world_x, float world_z, float biome_noise, float temp, float humid);
int get_interpolated_height(float world_x, float world_z, float temp, float humid);
}