The tiny terrain generator.
Terra provides various physics simulations, geological primitives, tesselations, filters, and more to generate realistic terrains. (It's pretty bad right now but getting better!)
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")
The example shown above involved various steps. With very few functions, Terra still offers a lot of flexibility in creating terrains.
- Normal Distribution
- Perlin Noise
- Billow Noise
- Fractal Perlin Noise
- Warping
- Pointify
- Pointy Perlin
- Voronoi Tesselation
- Tesselation Relaxation with Fortune's Algorithm
- Tesselated Height Map with Constant Elevation per Cell
- 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
- Hydraulic Single-Particle Terrain Erosion
- Optimized Erosion Rain Pattern: Rain Only Over Mountain Peaks to Speed Up the Erosion Effect
- 🔨 NEXT: Fast Physically-Based Analytical Erosion
- First version
- Improve the rain pattern
- Improve the flux/motion of the water
- Improve evaporation
- Fix the common hole-digging error with an add. heuristic
- 🔨 NEXT: Fractal Pixel Mountain Generation
- Hill
- 🔨 NEXT: Mountains
- 🔨 NEXT: Dunes
- Add and subtract by drawing on any map
- World Building Pasta. A phenomenal and in-depth blog about everything that shapes planets, their terrain, and how to create new worlds yourself.
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
.
There is much to do. The plan:
- Implement various terrain generation algorithms and tools quickly in Python.
- Optimize the performance for real-time and large scales by improving the algorithms, using C, and the GPU.
- 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!