Rework biome generation according to tectonic
This commit is contained in:
@@ -26,12 +26,19 @@ export function named_noise_3d(seed: string, name: string): NoiseFunction3D {
|
||||
return noise;
|
||||
}
|
||||
|
||||
// where an octave starts, like the random origin of each of minecraft's ImprovedNoise. simplex noise is 0 at 0 for
|
||||
// every seed, so without it every world would have the same thing at 0, 0
|
||||
function octave_offset(seed: string, name: string): number[] {
|
||||
const random = new Alea(`${seed}_${name}_offset`);
|
||||
return [random.next() * 256, random.next() * 256, random.next() * 256];
|
||||
}
|
||||
|
||||
// several octaves of simplex noise, like minecraft's NormalNoise: each octave has twice the frequency and half the
|
||||
// strength of the last, times its amplitude. wavelength is the size in blocks of the first octave's features, an
|
||||
// amplitude of 0 skips that octave. the result is roughly -1 to 1 but bunched in the middle, see Quantiles for an
|
||||
// even spread
|
||||
export class OctaveNoise2D {
|
||||
#octaves: { noise: NoiseFunction2D; frequency: number; amplitude: number }[] = [];
|
||||
#octaves: { noise: NoiseFunction2D; frequency: number; amplitude: number; offset: number[] }[] = [];
|
||||
#total: number;
|
||||
|
||||
constructor(seed: string, name: string, wavelength: number, amplitudes: number[]) {
|
||||
@@ -41,6 +48,7 @@ export class OctaveNoise2D {
|
||||
noise: named_noise_2d(seed, `${name}_${i}`),
|
||||
frequency: 2 ** i / wavelength,
|
||||
amplitude: amplitude / 2 ** i,
|
||||
offset: octave_offset(seed, `${name}_${i}`),
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -49,15 +57,15 @@ export class OctaveNoise2D {
|
||||
|
||||
sample(x: number, z: number) {
|
||||
let value = 0;
|
||||
for (const { noise, frequency, amplitude } of this.#octaves) {
|
||||
value += noise(x * frequency, z * frequency) * amplitude;
|
||||
for (const { noise, frequency, amplitude, offset } of this.#octaves) {
|
||||
value += noise(x * frequency + offset[0], z * frequency + offset[2]) * amplitude;
|
||||
}
|
||||
return value / this.#total;
|
||||
}
|
||||
}
|
||||
|
||||
export class OctaveNoise3D {
|
||||
#octaves: { noise: NoiseFunction3D; frequency: number; amplitude: number }[] = [];
|
||||
#octaves: { noise: NoiseFunction3D; frequency: number; amplitude: number; offset: number[] }[] = [];
|
||||
#total: number;
|
||||
// how much slower it changes vertically than horizontally
|
||||
#vertical_stretch: number;
|
||||
@@ -69,6 +77,7 @@ export class OctaveNoise3D {
|
||||
noise: named_noise_3d(seed, `${name}_${i}`),
|
||||
frequency: 2 ** i / wavelength,
|
||||
amplitude: amplitude / 2 ** i,
|
||||
offset: octave_offset(seed, `${name}_${i}`),
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -79,8 +88,9 @@ export class OctaveNoise3D {
|
||||
sample(x: number, y: number, z: number) {
|
||||
let value = 0;
|
||||
const sy = y / this.#vertical_stretch;
|
||||
for (const { noise, frequency, amplitude } of this.#octaves) {
|
||||
value += noise(x * frequency, sy * frequency, z * frequency) * amplitude;
|
||||
for (const { noise, frequency, amplitude, offset } of this.#octaves) {
|
||||
value += noise(x * frequency + offset[0], sy * frequency + offset[1], z * frequency + offset[2]) *
|
||||
amplitude;
|
||||
}
|
||||
return value / this.#total;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user