Generating your first Terrain

In this tutorial we'll create a very simple terrain. This isn't the only way to generate terrain, but it'll get you in the right direction:

Adding your Generator Node

As explained in GaeaGenerator, add your GaeaGenerator node and create a GaeaGraph, GaeaGenerationSettings, and GaeaTaskPool resource.

For this tutorial we will use a simple tile-based renderer.

Basic setup with the Generator, Renderer, and TileMapLayer nodes

So, add a TileMapGaeaRenderer node and assign the generator to it. Also add a TileMapLayer node and assign it to the first element of the renderer's tile_map_layers array.

Render node

You also need to setup your TileSet. Please refer to the TileSet documentation for more details on how to do that.

Generating the Noise Data

Terrain is usually created with noise, a black and white texture. Right click, and in the nodes list, under Sampling/Noise, you'll find the Noise2D node. Double click to add it. This node will be the base of our generation. Click the closed eye icon next to the data output to see the preview:

A Noise2D node with the preview activated

If you've never experimented with procedural generation, that may not look like much, but it's the base of the terrain from games like Minecraft or Terraria, and many others.

Mapping it to Tiles

Now add a ThresholdMapper node. (Tip: you can search for nodes in the popup)

This will allow to map certain values in the noise texture to GaeaMaterials (tiles in TileMapRenderers, elements in GridMapRenderers, etc.). Move around the handles in the range parameter to whatever you want. In my case, I'll do 0.5-1.0. Noise textures go from 0-1, 0 being completely black and 1 being completely white.

Connect the Noise output from the Noise2D node to the input of the ThresholdMapper node by dragging the white square of the Noise2D node to the input reference of the ThresholdMapper node.

The 2 nodes connected

Now, we need a material. Create a MaterialParameter node.

Parameters

In the inspector, click on the GaeaGraph resource. If you've added the parameter node, you'll see a parameters dropdown. Open it and you'll see your new parameter!

In the node, you can change the name of your parameter to whatever you want. Let's say, GrassMaterial. It'll automatically update in the inspector. Now set that parameter to a GaeaMaterial resource. For this example, we'll use a TileMapGaeaMaterial.

The inspector with the GaeaGraph resource and the GrassMaterial parameter opened

This resource tells the renderer what to draw. In this case, we set the type to Single Cell, and set the Source ID, Atlas Coord and Alternative Tile to match a grass tile in our TileSet. See the Material documentation for more details on how to set up your materials.

Now, connect the MaterialParameter node to the material input in the mapper. Finally, connect the mapper's map output to the (0) Layer 0 input in the Output node.

All the nodes connected together

That's it! Click the generate button in the top right of the panel and see the magic happen! It should look a bit like this:

A natural-looking terrain made out of only grass

Adding More Terrain Types

You can add more terrain types by adding more mapper nodes, and merging their outputs with the MapSetOpUnion node. For example, this...

A graph with more ThresholdMappers for sand and water, of the ranges 0.45-0.5 and 0.0-0.45 respectively. They all connect to a MergeMaps node, which outputs to the Output node

... generates this (The materials have been remplaced by terrain to use some tile variations and automatic tile connections.) :

A complete generation with grass, sand and water

As you can see, nodes can output to multiple other nodes at the same time. (Like how the Noise2D node connects to multiple ThresholdMapper nodes).

You can keep adding to this! You could even add decorations with layers, without having to make new tiles for each decoration and terrain type! Mess around with it as you'd like.

You can also do the same result using less nodes by using the GradientMaterial and setting different thresholds for each color in the gradient, but I wanted to show you how to use more nodes and merge them together.