I'm creating a little terraria-like 2D side-scroller game with TypeScript. Currently, I divide parts of the world into biomes, which each have their own properties (flat, mountainous terrain, etc.). I am using a one dimensional Perlin noise to generate the height of the terrain for each biome. Currently this is a problem for me because the borders between biomes are not at the same height. How could I make the transitions between biomes smoother?
-
2\$\begingroup\$ Does this answer your question? How to blend biomes with procedural terrain \$\endgroup\$– user35344Commented Jun 28, 2021 at 10:27
-
\$\begingroup\$ I'm not sure ... technically speaking, I'd like to know if it's possible to locally add octaves to a perlin noise? it could allows to have height variations per biome in a single perlin noise which would be smooth. \$\endgroup\$– EkkaiaCommented Jun 28, 2021 at 12:35
1 Answer
Conceptually, to transition between the 2 biomes smoothly, you need 2 biomes and a transition weight. That is, you do not choose between just one of them, but generate both and interpolate between their features (such as height, temperature, savagery, etc). The weight used to interpolate is also generated (preferably with a (relatively) smooth function), therefore you'll need to sample 3 different noises at once and do some math over the values.
Notice a smooth transition, despite the biomes' differences in maximum height and height variability.
For properties that can't be interpolated, a value may be selected based on a threshold. For example, in many games a biome type is a categorical value, it has to be either one or another, not something in between. In that case, a simplest approach is to choose a biome with a biggest weight.
-
\$\begingroup\$ Thank you very much for your answer. Which smooth function should I use? \$\endgroup\$– EkkaiaCommented Jul 1, 2021 at 21:42
-
\$\begingroup\$ @Ekkaia You want a function that keeps the weight high for the most part of the biome, but has a fall-off on the edges. I used
sin(b*π)²
in my example, whereb
is current position in the biome, value ranging between0.0
to1.0
. This requires to know the real bounds of the biome though. If that's unknown, you'll have to rely on very smooth / low frequency noise, e.g.perlin(x * 0.01)
. \$\endgroup\$ Commented Jul 1, 2021 at 22:36 -
\$\begingroup\$ Thank you for your answer! I found another way to do it thanks to a smooth cubic function. I did some tests on Codepen, if you want you can saw them here : codepen.io/Ekkaia/pen/abWbVVN?editors=0010 \$\endgroup\$– EkkaiaCommented Jul 2, 2021 at 0:06