Skip to content

QuentinWach/terra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The tiny terrain generator. Maintained by Quentin Wach.

License: MIT GitHub Repo stars GitHub latest commit

Terra provides various physics simulations, geological primitives, tesselations, filters, and more to generate realistic terrains. (It's pretty bad right now but getting better!)

Examples

Example 1. Eroded Mountains. The heightmap and colormap were generated with Terra using the code below then exported and rendered in Blender. Fractal Perlin noise is used to generate the terrain. In order to make the terrain more mountain-like, a custom pointify filter is applied on every level of the Perlin noise. Lastly, we simulate 20,000 particles for hydraulic erosion.

heightmap = pointy_perlin(X=600, Y=600, scale=100)
eroded_heightmap, path_map = erode(heightmap, num_iterations=20000)
export(heightmap, 'terrain.png', cmap='Greys_r')
export(eroded_heightmap, 'erosion.png', cmap='Greys_r')
export(eroded_heightmap, "erosion_color.png", cmap=terrain_cmap())
export(np.log1p(path_map), 'path_map.png', cmap='Blues')

As you can see, it only takes two lines to create the terrain! Everything else is just exporting the various maps that are generated. Below is a more simpler example showing some of the maps:

Example 2. A Tiny Island. Using fractal Perlin noise with the pointify effect at every level, a simple island can be generated effortlessly. The image here shows the heightmap, the colourmap, and normal map generated with Terra.

island = hill(500, 500)
export(island, "hill.png", cmap="Greys_r")
export(island, "hill_coloured.png", cmap=terrain_cmap())
export(normal_map(island), "hill_normal.png", cmap="viridis")

Features

The example shown above involved various steps. With very few functions, Terra still offers a lot of flexibility in creating terrains.

Randomness random

  • Normal Distribution
  • Perlin Noise
  • Billow Noise
  • Fractal Perlin Noise
  • Warping
  • Pointify
  • Pointy Perlin

Tesselation tess

  • Voronoi Tesselation
  • Tesselation Relaxation with Fortune's Algorithm
  • Tesselated Height Map with Constant Elevation per Cell

Rendering render

  • Linear Gradient
  • Whittaker Biome Classification and Color Map
  • 2D Map Export (i.e. to generate a 3D file and render it in Blender)
  • Radial Gradient / Mask
  • Standard Terrain Height Map
  • Normal Map Calculation
  • Gradient of Map
  • Divergence of Map
  • Import (i.e. to import images to be used as height maps, filters, assets etc.)
  • Gras Shader: Grow Gras Only on Flat, Low Areas
  • Snow Deposition
  • High-Res Exports for maps for better rendering and re-use

Simulation sim

Geo Primitives

  • Hill
  • 🔨 NEXT: Mountains
  • 🔨 NEXT: Dunes

Manual Edit

  • Add and subtract by drawing on any map

Other Links

  • World Building Pasta. A phenomenal and in-depth blog about everything that shapes planets, their terrain, and how to create new worlds yourself.

Get Started

Clone the repository or download it as a zip. Create or open a local Python environment (I recommend Anaconda) and install the dependencies dependencies.txt.


🤝🏻 Contribute

There is much to do. The plan:

  1. Implement various terrain generation algorithms and tools quickly in Python.
  2. Optimize the performance for real-time and large scales by improving the algorithms, using C, and the GPU.
  3. Create a GUI interface.

At this point, Terra is pretty much just educational. But it doesn't have to be. Leave your mark and add to this Python library. You know how it goes. You found a bug? Add an issue. Any ideas for improvement or feeling the need to add more features? Clone the repository, make the changes, and submit a pull request, or...

Leave a ⭐ to show your support!

MIT License