Generate a terrain texture - not with a terrain object

I’ve been trying to figure out this problem for a long… long time, and have searched numerous places… The only thing that really made sense is using a terrain object and splat maps but I’m not looking for that specifically…

I have a script to generate a mesh based on Perlin noise and I’m trying to figure out how to make a texture to change based on the height of the mesh verticies.

I’ve been trying to make it so that at very vertex, it would check the height and apply a splat map at that point thinking that it would be the easiest but I can’t think of how to translate the vertex position to the 2D texture map. Is this the way I should be trying to do this? Can I make a height map apply to a standard mesh and work it from generated texture first?

When you generate the mesh, you could use the vertex color to store information about the terrain at that point. For example, you could store the normalized height of the map in the red channel.

Then in your shader, you could blend between two textures, say one with grass and one with stone, based on the red value at that vertex.

Base Map:

alt text

Red Channel:

alt text

Textures:

alt text

Resulting Blend:

alt text