@plasius/gpu-world-generator
v0.0.8
Published
GPU-assisted world generation with hex-grid terrain synthesis.
Readme
@plasius/gpu-world-generator
GPU-assisted world generation focused on hex-grid terrain synthesis. This package targets pre-generation of terrain height/heat/biome layers using WebGPU compute jobs (compatible with @plasius/gpu-worker).
Goals
- Hierarchical hex grid (1000 km² regional zones down to ~10 m² tiles).
- 3D heat-map based terrain synthesis (height = depth, heat = biome driver).
- Extensible biome classification (tundra, savanna, river, city, village, ice, snow, mountainous, volcanic, road, town, castle, etc).
- Shader-first pipeline with CPU fallback helpers.
Layered Fractal Model
Generation now uses three explicit fractal layers:
- Layer 1 (terrain trend): cumulative height banding where
0.0..0.2is downward slope,0.2..0.8is flat, and0.8..1.0is upward slope. - Layer 2 (features/obstacles): dedicated fractal mask for obstacles and prop placement (rocks, boulders, ruins, water ripples, etc).
- Layer 3 (foliage): dedicated fractal mask for vegetation density (trees, bushes, grass tufts, reeds).
TerrainCell outputs may include surface, feature, obstacle, foliage, and slopeBand in addition to height, heat, moisture, and biome.
Install (local)
npm install
npm run buildUsage (WGSL)
import {
assembleWorkerWgsl,
loadJobWgsl,
} from "@plasius/gpu-worker";
import { terrainWgslUrl, loadTerrainWgsl } from "@plasius/gpu-world-generator";
const jobWgsl = await loadTerrainWgsl();
await loadJobWgsl({ wgsl: jobWgsl, label: "terrain" });
const workerWgsl = await loadWorkerWgsl();
const shaderCode = await assembleWorkerWgsl(workerWgsl, { debug: true });Usage (Temperate Mixed Forest)
import { generateTemperateMixedForest } from "@plasius/gpu-world-generator";
const { levelSpec, cells, terrain } = generateTemperateMixedForest({
seed: 1337,
radius: 6,
});Usage (raw import with bundlers)
import terrainWgsl from "@plasius/gpu-world-generator/terrain.wgsl?raw";Demo
The WebGPU mixed-forest demo lives in demo/. Run it with:
cd demo
npm install
npm run devDevelopment Checks
npm run lint
npm run typecheck
npm run test:coverage
npm run build
npm run pack:checkNotes
- For Vite/Pnpm setups, raw WGSL import is the most reliable.
- See
docs/plan.mdfor hierarchy and biome rules.
