GLSL Terrain Shader

Share your advanced PureBasic knowledge/code with the community.
Kelebrindae
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 01, 2008 3:23 pm

GLSL Terrain Shader

Post by Kelebrindae »

Hi,

While fiddling with my material/shader editor (http://www.purebasic.fr/english/viewtop ... 27&t=50024), I managed to merge two GLSL shaders found on the net: one that handles normal mapping, and another that textures terrains.
:mrgreen: Yay! :mrgreen:

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 ... :wink:
Example + sources here: http://keleb.free.fr/codecorner/downloa ... Shader.zip (3 Mo)
(Don't forget to set "OpenGL" as subsystem in the Compiler Options)
Image
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: GLSL Terrain Shader

Post by falsam »

Kelebrindae wrote::mrgreen: Yay! :mrgreen:
Image

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: GLSL Terrain Shader

Post by Num3 »

Nice xD
Post Reply