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.
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using VoxelEngine.Core;
|
|
|
|
namespace VoxelEngine.World.WorldGen;
|
|
|
|
public sealed class TerrainSampler
|
|
{
|
|
private readonly NoiseSource _noise;
|
|
private readonly BiomeMap _biomes;
|
|
private readonly Configuration _cfg;
|
|
|
|
public TerrainSampler(NoiseSource noise, BiomeMap biomes, Configuration cfg)
|
|
{
|
|
this._noise = noise;
|
|
this._biomes = biomes;
|
|
this._cfg = cfg;
|
|
}
|
|
|
|
public int HeightAt(float worldX, float worldZ)
|
|
{
|
|
// 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);
|
|
}
|
|
}
|