3D biomes

This commit is contained in:
2026-11-07 12:13:43 -03:00
parent b726ce9695
commit 22191d260c
53 changed files with 874 additions and 316 deletions
+17 -5
View File
@@ -7,6 +7,7 @@
// are features, after it
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
import type { WorldShape } from "@/common/world_shape.ts";
import { BIOME_CELL_HEIGHT } from "@/common/section.ts";
import { get_biome } from "./biomes.ts";
import type { NoiseTerrain, TerrainColumn } from "./terrain.ts";
import {
@@ -17,8 +18,9 @@ import {
type SurfaceContext,
} from "./surface_rules.ts";
// fills blocks (indexed (y - min_y) * CHUNK_AREA + z * CHUNK_SIZE + x) and each column's surface height and biome. block is
// a block's numeric id with its default states
// fills blocks (indexed (y - min_y) * CHUNK_AREA + z * CHUNK_SIZE + x), each column's surface height and each biome
// cell's biome (indexed like blocks, a layer of cells at a time, see column_biomes). block is a block's numeric id with
// its default states
export function generate_noise_chunk(
blocks: Uint32Array,
heights: Int32Array,
@@ -39,6 +41,9 @@ export function generate_noise_chunk(
const cave_levels = height / cave_cell_height + 1;
const x0 = chunk_x * CHUNK_SIZE;
const z0 = chunk_z * CHUNK_SIZE;
const cells = height / BIOME_CELL_HEIGHT;
// the cell a y is in, below the world the lowest
const ground_cell = (y: number) => Math.max(0, Math.floor((y - min_y) / BIOME_CELL_HEIGHT));
// density at the corners of every cell
const corner_columns: TerrainColumn[] = [];
@@ -160,10 +165,17 @@ export function generate_noise_chunk(
const ground = column.height;
const neighbors = [column_at(x - 1, z), column_at(x + 1, z), column_at(x, z - 1), column_at(x, z + 1)];
const steep = neighbors.some((neighbor) => Math.abs(neighbor.height - ground) >= settings.steep);
const biome = terrain.biome(column, surface_y, steep);
heights[z * CHUNK_SIZE + x] = surface_y;
biomes[z * CHUNK_SIZE + x] = biome;
// the biome of each cell, worked out once for the whole column when no rule looks at heights. the ground's
// surface is its own cell's
let biome = "";
for (let cell = 0; cell < cells; cell++) {
const y = min_y + cell * BIOME_CELL_HEIGHT;
if (cell === 0 || terrain.by_height) biome = terrain.biome(column, surface_y, steep, y);
biomes[cell * CHUNK_AREA + z * CHUNK_SIZE + x] = biome;
}
biome = biomes[ground_cell(surface_y) * CHUNK_AREA + z * CHUNK_SIZE + x];
context.x = x0 + x;
context.z = z0 + z;