Terrar: ModularTerrain Generation System

Hello friends,

Each time when I am going to create some game I end with a tool for games or assets creation. Meet another one: the Terrar.

Terrar is a modular terrain generation system built with TypeScript. It provides a complete pipeline for creating, visualizing, and exporting digital landscapes with a clean, modular architecture. The project demonstrates production-ready engineering with thoughtful separation of concerns, comprehensive export capabilities, and seamless Babylon.js integration.

The library is structured around several focused packages, each serving a distinct purpose:

1. terrar/builder – The Render-Agnostic Terrain Engine

  • In-memory terrain asset construction
  • Heightmap, flow map, river map, lake map, and sediment map generation
  • Resource distribution mapping (coal, iron, copper)
  • Combined water and resources maps
  • Terrain serialization and deserialization
  • POI (Points of Interest) and road data generation

Noise defines the landform, erosion and hydrology make it believable, planners place gameplay features, and the renderer turns the cached snapshot into chunked LOD meshes.

More info about the world systems
terrar/HOW_IT_IS_DONE.md at main · eldinor/terrar · GitHub

The builder produces a TerrainAsset – a canonical runtime contract containing complete terrain data. This format is render-agnostic, meaning the same terrain data can be visualized in different engines without regeneration

Terrar employs a chunk-based terrain architecture, which is essential for handling large-scale worlds efficiently. Chunk-based architecture naturally supports level of detail (LOD) systems where chunks farther from the camera can be rendered at lower resolution while nearby chunks maintain full detail.

Terrar includes infrastructure for high-performance terrain processing through SharedArrayBuffer support and an implied worker pool architecture. These work together to enable true parallel chunk processing with additional chunk stitching. So it is really fast, for the volume of data used.

The export creates a well-organized directory:

my-terrain/
  manifest.json           # Metadata about the export
  terrain.asset.json      # Complete terrain data
  poi.json                # Points of interest
  roads.json              # Road networks
  maps/                   # PNG format maps
    heightmap.png
    flow.png
    river.png
    lake.png
    sediment.png
    resource-coal.png
    resource-iron.png
    resource-copper.png
    water-combined.png
    resources-combined.png

2. terrar/babylon – The Visualization Adapter
A dedicated adapter renders the render-agnostic terrain asset into a Babylon.js scene:

import { renderTerrainAsset } from "terrar/babylon";

const adapter = renderTerrainAsset(scene, terrain);
adapter.mount();

The adapter updates the terrain system based on the current camera position, managing chunk loading, LOD transitions, and occlusion. The number of draw calls with properly tuned LOD values is very low. The suspended rendering utlitiy stops render at demo page if there are no user interactions.

Use Cases

Game Development – Procedural world generation with Babylon.js rendering
Asset Pipeline – Generate terrain assets for export to game engines
Simulation – Terrain data for environmental or geospatial simulations
Visualization – Real-time terrain visualization with Babylon.js
Tooling – Build custom terrain generation tools and pipelines

The next evident step would be a Terrain Editor. I also think that the adapter could be easily ported to Babylon Lite. The texturing currently is done with 256*256 procedural textures (or user textures if chosen) and also may be improved.
Feedback and PRs are welcome!

11 Likes

Looking pretty cool!
Looks like you have a normal bug though if you move your camera to an aggressive dot product.

3 Likes

This looks super cool! I love procedural generation, and this is great. I particularly like how the roads follow the terrain, nice job.

1 Like

Awesome and very useful!

Just one small improvement to make editing smoother: right now, the value updates and starts processing continuously while the slider is being moved, which can sometimes cause it to get stuck. Ideally, the process should only start once the slider is released.

Sure, the shader and the texturing may be improved.

I added a bit of noise but the effect is too subtle.

I think I’ll try to create Lite adapter first then think again :slight_smile:

Thank you!

This is fixed.

I also added “Force LOD 0” button to see the whole terrain in the best resolution.

1 Like

I need this so badly! Thank you! :star_struck:
You rock :love_you_gesture:

1 Like

This is awesome!

1 Like

Meet the new Terrain Editor Mode and the separate World Smoothing

Terrain Editor Mode edits the generated terrain heightfield directly in the browser.

Sculpted elevations remain when Editor Mode is closed and are included in terrain exports.

And yes, sculpting is funny :slight_smile:

More info - terrar/docs/terrain-editor.md at main · eldinor/terrar · GitHub

3 Likes

So cooool