Multiple different textures/materials on 3D heightmap

over the weeks I have created a chunked infinite heightmap terrain. The chunk system is very simple and is not the topic of this question. The topic of this question is how to create a terrain heightmap with the possibility of blending between different textures/materials (grass, dirt, sand, etc.) smoothly.

A chunk is basically a grid of height values and texture values (so 0 is dirt, 1 is grass, 2 is something else). Then I generate the chunk mesh by taking all those values and turning them into vertex attributes (height is a buffer object and so is the texture/material; I only pass the height because I calculate the X and Z position in the shader).

Now, the vertex shader looks like this:

  #version 300 es
  layout (location = 0) in float height;
  layout (location = 1) in float material;

  out float h;
  out float m;
  out vec2 uv;
  
  uniform vec4 chunkPosition;
  uniform int chunkSize;
  uniform mat4 view, projection;

  void main () {
    int col = gl_VertexID % (chunkSize + 1);
    int row = gl_VertexID / (chunkSize + 1);
    vec4 position = vec4 (col, height, row, 1.0);
  
    gl_Position = projection * view * (chunkPosition + position);
    uv = vec2 (float (col) / float (chunkSize), float (row) / float (chunkSize));
    h = height;
    m = material;
  }

And the fragment shader looks like this:

  #version 300 es
  precision lowp float;

  in vec2 uv;
  in float h;
  in float m;
  out vec4 color;

  uniform sampler2D grass, drygrass, dirt;
  
  void main () {
    vec4 grs = texture (grass, uv);
    vec4 drt = texture (dirt, uv);
  
    color = mix (grs, drt, m);
  }

With the single value m representing the material at a given vertex I seem to be able to sucessfuly blend between two textures and it looks great. However, I can’t wrap my head around how to implement more textures here (in this example, how to make it so drygrass is also on the terrain).

I understand that the way it works here is it does a weighed average and interpolated between the grass and dirt materials based on the value m (which for now I have not made it go beyond 1).

I already tried making it so the value does go to 2 (so in this example it could be e.g. drygrass) but I find it hard to figure out how to mix it all.

Is the way to go to have a different “m” value for every single texture type in the terrain?