It is currently Wed May 22, 2013 7:51 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: GLSL Terrain Shader
PostPosted: Tue Jun 12, 2012 9:48 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Apr 01, 2008 3:23 pm
Posts: 129
Hi,

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.
: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/download/purebasic/terrainShader.zip (3 Mo)
(Don't forget to set "OpenGL" as subsystem in the Compiler Options)
Image


Top
 Profile  
 
 Post subject: Re: GLSL Terrain Shader
PostPosted: Tue Jun 12, 2012 11:21 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 21, 2011 9:11 am
Posts: 125
Location: France (Paris)
Kelebrindae wrote:
:mrgreen: Yay! :mrgreen:

Image

_________________
Noob Inside - (Windows XP, 7 & 8: Full Version PB 4.51 -> 5.00)


Top
 Profile  
 
 Post subject: Re: GLSL Terrain Shader
PostPosted: Thu Jun 14, 2012 10:03 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:51 pm
Posts: 2715
Location: Portugal, Lisbon
Nice xD

_________________
Software: http://xipa.org
Elevator Maintenance: http://central-elevadores.pt
Good web hosting!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye