unity – How to blend a 2D terrain

Let’s start with some basics: in this case linear interpolation (and its limitations), using pure colours. Once you’re on the right track, you can figure things out from there.

First, try to recreate the below image using Mathf.Lerp(), to create a controlled 1D interpolation between two adjacent colours:

enter image description here

(expanded vertically so you can see it more clearly)

enter image description here

Next, try to Lerp() in 2D, also known as bilerp() to create an interpolation on a quadrilateral with 4 colours, one at each of the corners of the quad:

enter image description here

(You can see that bilinear interpolation specifically operates on quads.)

You can see here how the final result comes out between (grid-aligned) world tiles / chunks, with the 2D / bilerped example above, being the middle tile between 4 pure colour tiles:

enter image description here

The easiest way to create the above in Unity is to set up a textured quad facing the camera, then use Texture2D.setPixel() to build a texture according to the numbers you get out of your linear interpolation functions given above.

Once implemented on the CPU using Unity’s Lerp() & custom Bilerp(), you can then shift this logic over to lerp() textures correctly on the GPU if desired.

EDIT per comments How your input map must look to be blended this way (grid-aligned cells):

enter image description here