mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-17 16:17:02 +08:00
refactor: prevent desert from generation adjacent to mountain in biome generation
This commit is contained in:
@@ -280,16 +280,10 @@ void Chunk::resolve_blocks() {
|
||||
|
||||
float world_x = static_cast<float>(x + m_chunk_pos.x * CHUCK_SIZE);
|
||||
float world_z = static_cast<float>(z + m_chunk_pos.z * CHUCK_SIZE);
|
||||
|
||||
float biome_noise = PerlinNoise::noise(
|
||||
world_x * BIOME_NOISE_FREQUENCY,
|
||||
0.5f,
|
||||
world_z * BIOME_NOISE_FREQUENCY
|
||||
);
|
||||
|
||||
float temp = PerlinNoise::noise(world_x * BIOME_NOISE_FREQUENCY, 0.0f, world_z * BIOME_NOISE_FREQUENCY);
|
||||
float humid = PerlinNoise::noise(world_x * BIOME_NOISE_FREQUENCY, 1.0f, world_z * BIOME_NOISE_FREQUENCY);
|
||||
int height = Math::get_interpolated_height(world_x, world_z, biome_noise, temp, humid);
|
||||
int height = Math::get_interpolated_height(world_x, world_z, temp, humid);
|
||||
auto biome = get_biome_from_noise(temp, humid);
|
||||
for (int y = 5; y < height - 5; y++) {
|
||||
m_blocks[get_index(x, y, z)] = 3;
|
||||
|
||||
@@ -34,9 +34,8 @@ namespace Math {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
auto weight = [](float t, float h, float ct, float ch) -> float {
|
||||
float dt = t - ct;
|
||||
float dh = h - ch;
|
||||
@@ -44,16 +43,16 @@ namespace Math {
|
||||
return std::max(0.0f, 0.5f - dist);
|
||||
};
|
||||
|
||||
float w_mountain = weight(temp, humid, 0.25f, 0.25f);
|
||||
float w_plain = weight(temp, humid, 0.25f, 0.75f);
|
||||
float w_desert = weight(temp, humid, 0.75f, 0.25f);
|
||||
float w_mountain = weight(temp, humid, 0.25f, 0.15f);
|
||||
float w_plain = weight(temp, humid, 0.50f, 0.40f);
|
||||
float w_desert = weight(temp, humid, 0.75f, 0.15f);
|
||||
float w_forest = weight(temp, humid, 0.75f, 0.75f);
|
||||
// adjust transitions between chunks
|
||||
float pow_n = 8.0f; // the larger n is, the purer the biome
|
||||
w_mountain = std::pow(w_mountain, pow_n);
|
||||
w_plain = std::pow(w_plain, pow_n);
|
||||
w_desert = std::pow(w_desert, pow_n);
|
||||
w_forest = std::pow(w_forest, pow_n);
|
||||
w_mountain = std::pow(w_mountain, pow_n) * MOUNTAIN_FREQ;
|
||||
w_plain = std::pow(w_plain, pow_n) * PLAIN_FREQ;
|
||||
w_desert = std::pow(w_desert, pow_n) * DESERT_FREQ;
|
||||
w_forest = std::pow(w_forest, pow_n) * FOREST_FREQ;
|
||||
|
||||
float total = w_mountain + w_plain + w_desert + w_forest;
|
||||
w_mountain /= total; w_plain /= total; w_desert /= total; w_forest /= total;
|
||||
|
||||
Reference in New Issue
Block a user