My idea is to let the user to choose which textures want to render for different heights and slopes.
Example:
For steep slopes, the texture would be rock.
For gentle slopes and high heights the texture would be snow.
For gentle slopes and low heights the texture would be grass.
For heights below water level, the texture would be dust.
Textures and parameters are provided by the user.
Issue:
To build it, my idea is to render all the textures (snow, rock, grass and dust) covering the whole generated ground, then calculate the height and slope of each vertex and apply alpha (0 to 1) to each shader material depending if the material texture has to be rendered or not in that vertex. I hope I described well the issue.
My question:
Before doing it I wanted to ask the experts in the forum, just to know if this approach is correct, or maybe I should follow another approach.
This sounds like the way to go. Finding the right mix between slope and height might need some iterations. so, try to have some UI for fast iterations/tweaking and debugging.
Just do a custom shader with like a splat map then, load up some basic texture for dirt, grass, rock, etc and then paint your splat map with the colors associated with each material type. A custom splat map terrain texture is probably the simplest. You can then also procedurally paint the splat map but thats a whole different conversation.
Aww, man, I know there is a technique for it and I remember having seen the code. Cannot find it anymore
But it is really simple. You have a range for height layers and a terrain texture per each layer. The code is then as simple as
if vertex.y within(0, 2)
sample(dirtTex)
//etc.
// some blending on elevation edges
I do not remember that slopes were handled. Do you need the extra info about slopes at all? Just looking at your screenshot from above, is there any place where “slope” would conflict with “elevation”?
If you look at Labris’s job, I think he’s already dealing with slopes and elevations. I haven’t had time to review the code, but the approach might be very similar to that.
Slopes wouldn’t conflict with elevations since it is the user who decides which textures are rendered for each elevation and slope range.