I\'ve implemented a heightmap in OpenGL. For now it is just a sine/cosine curved terrain. At the moment I am interpolating between the white \"ice\" and the darker \"stone\" te
The other answers have already provided solutions for the genralized mix()
function you asked for. But I'd recommend using a different approach, since you explicitely wrote about an "interpolation order (ice, stone, grass)". In that case, you don't need arbitrary weights for each element, you only mix neighboring ones, like ice+stone or stone+grass, but never ice+grass or ice+stone+grass. If that is the case, you can simply use 3D textures and use (tri)linear filtering. Just use each of your 2D texture as a slice in the 3D texture. The first two texcoords can stay as they are, and the third can be directly used to select an arbitrary blending between two neighboring slices. Since texcoords are always in the range [0,1], you just have to map your range to that interval. The "center" of the i
-th slice will lie at
p=i/num_layers + 1/(2*num_layers)
Say you have those 3 slices for ice, stone and grass. So you get
0/3+1/6 = 0.16667 100% ice
1/3+1/6 = 0.5 100% stone
2/3+1/6 = 0.83333 100% grass
and arbirtrary linear blends between neighboring layers just inbetween, like
1/3 = 0.3333 50% ice + 50% stone
0.6 70% stone + 30% grass
...