While fiddling with my material/shader editor (http://www.purebasic.fr/english/viewtopic.php?f=27&t=50024
), I managed to merge two GLSL shaders found on the net: one that handles normal mapping, and another that textures terrains. Yay
What does it do?
=> When given a mesh (a terrain mesh, preferably), it applies three types of textures: grass where the mesh is rather horizontal, rock where it's steep, and sand where it's relatively flat and close to zero altitude (to simulate beaches). In addition, these textures are "blended" on the transition between zones, for prettier results.
Thus, no need to manually texture the terrain: the shader does it automatically, depending on the mesh topology.
The shader was originally a WebGl one. I've ported it to Ogre and I've added normal mapping; the result is a bit of a Frankenstein's monster, but (much to my surprise) it works.
Actually, it would be great for a mesh dynamically generated in PB, but as normal mapping needs the "tangent" of the mesh and PB can't generate them (yet?), I had to settle for a static mesh in the example.
The material sends several parameters to the shader, to adjust the result:
- Textures tiling;
- Min / max altitudes;
- Proportion of rocks;
- Transitions smoothing between areas.
There are still many things that could be improved, so don't hesitate to share your mods and tweaks ...
Example + sources here: http://keleb.free.fr/codecorner/download/purebasic/terrainShader.zip
(Don't forget to set "OpenGL" as subsystem in the Compiler Options)