feat(world-gen): larger biomes, smooth height blending, capped mountains; centralize tunables in Configuration
Terrain feel: biome regions ~10x larger (Voronoi cell size 96->960); terrain height now eases across biome borders via a Voronoi distance blend (smooth, and ~25x cheaper than the old 169-sample box blur); mountains capped to ~2/3 world height and gentled (ridged amplitude/frequency lowered), snow line lowered to match. Centralization: ~27 world-gen/render tuning constants (biome amplitudes & frequencies, climate-noise frequencies/octaves, biome-selection thresholds, blend width, cell size, filler depth, snow line, camera near plane, spawn offset, overlay scale) hoisted from scattered literals into a region-organized, fully-commented Configuration. Configuration is threaded into NoiseSource, the biomes, BiomeRegistry, BiomeMap (+Classify), TerrainSampler, WorldGenerator (+BlockAt filler depth), and Camera via Player. Defaults equal the prior values, so generation is unchanged; worldgen tests updated for the new constructor signatures.
This commit is contained in:
@@ -1,38 +1,40 @@
|
||||
using VoxelEngine.Core;
|
||||
|
||||
namespace VoxelEngine.World.WorldGen;
|
||||
|
||||
public sealed class TerrainSampler
|
||||
{
|
||||
// Box-blur radius (in blocks) applied to the biome-height field to smooth
|
||||
// biome borders. A full (2R+1)x(2R+1) kernel at 1-block spacing bounds the
|
||||
// per-block height change to ~maxBiomeHeightDiff / (2R+1), preventing cliffs.
|
||||
// A sparse kernel does NOT bound it (axis-aligned borders flip several samples
|
||||
// at once), so the kernel must be dense.
|
||||
private const int BlendRadius = 6;
|
||||
|
||||
private readonly NoiseSource _noise;
|
||||
private readonly BiomeMap _biomes;
|
||||
private readonly Configuration _cfg;
|
||||
|
||||
public TerrainSampler(NoiseSource noise, BiomeMap biomes)
|
||||
public TerrainSampler(NoiseSource noise, BiomeMap biomes, Configuration cfg)
|
||||
{
|
||||
this._noise = noise;
|
||||
this._biomes = biomes;
|
||||
this._cfg = cfg;
|
||||
}
|
||||
|
||||
public int HeightAt(float worldX, float worldZ)
|
||||
{
|
||||
// For each kernel point find the biome THERE, but evaluate its height AT the
|
||||
// column. Averaging blurs the hard biome borders into smooth transitions.
|
||||
float sum = 0f;
|
||||
int count = 0;
|
||||
for (int dz = -TerrainSampler.BlendRadius; dz <= TerrainSampler.BlendRadius; dz++)
|
||||
for (int dx = -TerrainSampler.BlendRadius; dx <= TerrainSampler.BlendRadius; dx++)
|
||||
{
|
||||
IBiome biome = this._biomes.BiomeAt(worldX + dx, worldZ + dz);
|
||||
sum += biome.SampleHeight(this._noise, worldX, worldZ);
|
||||
count++;
|
||||
}
|
||||
float avg = sum / count;
|
||||
int h = (int)System.MathF.Round(avg);
|
||||
return System.Math.Clamp(h, 0, WorldConstants.WorldHeight - 1);
|
||||
// Blend the two nearest biomes' heights (each evaluated AT this column) by
|
||||
// how deep inside the nearer cell we are: exactly on the border they mix
|
||||
// 50/50, easing to 100% of the nearer biome over BiomeBlendWidth blocks.
|
||||
BiomeMap.BiomeBlend blend = this._biomes.NearestTwo(worldX, worldZ);
|
||||
float hNear = blend.Near.SampleHeight(this._noise, worldX, worldZ);
|
||||
float hFar = blend.Far.SampleHeight(this._noise, worldX, worldZ);
|
||||
|
||||
float fracFar = 0.5f * (1f - SmoothStep01(blend.BorderDistance / this._cfg.BiomeBlendWidth));
|
||||
float avg = hNear * (1f - fracFar) + hFar * fracFar;
|
||||
|
||||
int h = (int)MathF.Round(avg);
|
||||
return Math.Clamp(h, 0, WorldConstants.WorldHeight - 1);
|
||||
}
|
||||
|
||||
// Hermite smoothstep on [0,1].
|
||||
private static float SmoothStep01(float t)
|
||||
{
|
||||
t = Math.Clamp(t, 0f, 1f);
|
||||
return t * t * (3f - 2f * t);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user