Need assistance with blending biomes

Godot Version

4.3

Question

Hi! I have 3 biomes currently that each spawn at varying heights in the world. I have a noise map to calculate the altitude at a given point in the world for biome placement. The 3 biomes also have noise maps to create different terrain shapes.

Currently I am using the Terrain3D plugin which takes a heightmap as an input and deforms a mesh to create a landscape, therefore I am plotting all the biomes onto 1 heightmap (I’m not entirely sure if this is the correct way to map biomes onto terrain).

My problem occurs when the borders of biomes meet. Below is an image of the biome borders without blending. (scaled up for better visual)


I assume this is due to the different terrainscale parameters I have for each of the biomes and thought it would be an easy fix by blending.

Below is the code I have for “blending” the biomes.

for x in range(0, width):
	for y in range(0, height):
	# init vars
		var heightMapVal : float = HeightMap.get_pixel(x,y).r # decides which biome to place
		var temperatureVal = Temperature.get_image().get_pixel(x,y).r # currently unused
		var scaledHeight : float = mapHeight - (heightMapVal * mapHeight) # the heightmap scaled by mapheight (500), i am using depth so must subtract the mapheight
		var selectedBiomes : Array[BiomeRules] # biomes influence a given point 
	# create list of biomes at point
		for i in range (0,Biomes.size()):
			var biome : BiomeRules = Biomes[i]
			# heightBlendDropoff is how much you want the borders to overlap 
			if biome.DepthMax + HeightBlendDropoff >= scaledHeight and biome.DepthMin - HeightBlendDropoff <= scaledHeight:
				if biome.TemperatureHigh + TemperatureBlendOffset >= temperatureVal and biome.TemperatureLow - TemperatureBlendOffset <= temperatureVal:
					selectedBiomes.append(biome)
	# loop overlapping biomes
		var biomeAlpha : float = 1 # the alpha used to alter the overlapping biome influence
		var finalBiomeVal : float = 0
		var offset : float = 0
		for biome : BiomeRules in selectedBiomes:
			if scaledHeight >= biome.DepthMax:
				biomeAlpha = 1 - abs(scaledHeight - biome.DepthMax) / HeightBlendDropoff
			elif scaledHeight <= biome.DepthMin:
				biomeAlpha = 1 - abs(biome.DepthMin - scaledHeight) / HeightBlendDropoff

			var biomeVal : float = biome.TerrainNoise.get_image().get_pixel(x, y).r # the value of the biome noisemap at a given point
			var scalarFloat : float = (biome.TerrainHeightScale / mapHeight) # how much to scale the biome noise by
			offset = clampf(heightMapVal - scalarFloat, 0, 1.0) # offset of the heightmap (the lowest point of the biome)
			var finalVal : float = (biomeVal * scalarFloat) # this value mapped onto terrain is the first image
			finalBiomeVal += (finalVal * biomeAlpha) # altering biome influence for multiple biomes?
		finalBiomeVal += offset

If anyone knows of an alternative way to create terrain w/biomes in Godot or may know where I am going wrong with this I would greatly appreciate the help :slight_smile:

What’s the problem you’re encountering? You’ve got a thing you wanted to solve (smoothing the boundaries between biomes), you’ve got a proposed solution (blending) with code. The solution looks like it ought to work. Is it not working? Or is it “working” but unacceptably slow or something?

This is the result of the blend

Removing the offset makes it more clear

Update: I wasn’t resetting the biomeAlpha to 1 after every iteration through overlapping biomes which resulted in the mirrored heights. Adding that line of code in, the blending is looking much better but not perfect:

Even when multiplying the heightBlendDropoff by 5x there is still a clear line that seems to extend higher than both biomes, not sure why this is as both the 0-1 height value of the biome and the terrainScale are multiplied by the biome alpha

I’d suggest looking into ease functions for the blending; that could take the sharp angles off.

Are you sure the sum of your biome.TerrainNoise alpha values is 1.0 for any given pixel?

You were right the sum wasn’t 1.0, I wasn’t subtracting the heightBlendDroppoff from the biome border which made the biome blend begin at the edge of the biomes and not heightBlendDroppoff amount of pixels from the edge, thanks :slight_smile:

1 Like

You’re also using textures that produce a lot of aliasing, you might want to test it with a few different textures, and especially tune the code with relevant assets.
Keep devin’ and playing hard!
Cheers !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.