The generator tool in the plugin uses viewports and a series of shaders to produce an
Image, which is then applied to the terrain textures in the same way as the end of the documentation example. It's quite advanced and took a lot of iterative work to be the way it is now, so explaining how everything works in detail would take a while.
The doc example shows the basics of how to set pixels of the terrain and update the node in a single pass (i.e only one XY for loop). If you start from there you should be able to tinker with a result pretty quickly, and have a better understanding of the basics.
On the other hand, each feature of the plugin's generator is a subject on its own, you may have to learn how each of them is done.
The main approaches used are:
- Fractal noise: Perlin, OpenSimplex etc. This can be enough and is used by anyone generating their own terrain.
- Curving: the heightmap can be deformed by applying a function to the height. For example if a quadratic curve is applied (slow start, fast end), it will further flatten the lower heights and make the highest peaks even sharper. If a "stepify" function is applied, it will create a mesa-looking environment. I was considering using a
Curve resource later on.
- Multiple passes: each pass takes result from the preceding pass. First generate noise, then run erosion algorithm 30 times in a row, then a final pass to calculate normals from the result
- Fragment shaders: they are used instead of GDScript to speed up the process, but forces to wait one frame per pass so the generator usually takes a few seconds to complete.
- Viewports: required for shader rendering. They are never cleared to allow using results from previous passes.
- Tiling: this isn't strictly necessary but this generator runs on sub-sections of the terrain, because some graphics cards might not support largest viewport sizes. It also means the generator uses a bit of padding for tiles to be seamless, which is cropped later on.
- At the end, viewport contents are downloaded as
Image and copied into the terrain, just like the end of the documentation example shows.
It is copied here: https://github.com/Zylann/godot_heightmap_plugin/blob/0f52300afb39c8f6b5ea48b4f879f76667cee18e/addons/zylann.hterrain/tools/generator/generator_dialog.gd#L317
And uploaded here: See https://github.com/Zylann/godot_heightmap_plugin/blob/0f52300afb39c8f6b5ea48b4f879f76667cee18e/addons/zylann.hterrain/tools/generator/generator_dialog.gd#L340 (the generator only works on the heightmap at the moment).
And this is my own "formula" which I made in a somewhat messy way, there are plenty other possible tweaks.
This is all doable in GDScript without the extra bells and whistles, but it will be slower. If you want to go for the viewport shader approach, you may have to learn them first.