Jump to content
  • Advertisement
Sign in to follow this  
LastWorldDeveloper

OpenGL Creating alpha maps on the fly

This topic is 4312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm relatively new to OpenGL programming and I need some advice. I'm currently in the process of creating a 3D Real Time Strategy game for my final year project at university. It's supposed to work cross platform in Linux and Windows, so I've opted for OpenGL + SDL + C++. I'm looking into using texture splatting to texture my height mapped terrain but my question is this: How do I create the alpha maps for texture splatting to work? I know that say I had a height mapped splat section: 1-------*-------*-------* |////////|////////|////////| |////////|////////|////////| |////////|////////|////////| *-------*-------*-------* |////////|////////|////////| |////////|////////|////////| |////////|////////|////////| *-------*-------*-------* |////////|////////|////////| |////////|////////|////////| |////////|////////|////////| *-------*-------*-------16 Where vertex 16 is at the the height where I want sand and vertex 1 is at the height where I want grass, I would need two alpha maps for each texture one where 16 was fully opaque (Alpha 1.0) and 1 was completely transparent (Alpha 0.0), for the sand, and the opposite values for the grass, but how do I go about creating the map programmatically? Can anyone give me pointers or suggest a suitable tutorial? Or even tell me if I've missed the point? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You will only have a single alpha map for each texture type. For grass, you'll have a single map with values ranging from 0 to 255. 0 being completely transparent and 255 being completely opaque. The easiest way to generate the maps is loop through each pixel in the alpha map, figure out its location on the terrain, take the height and slope of the terrain at that point and perform some calculation based on those values to decide which texture should be there. Or more specifically, say you're generating the map for grass, and you want it at any height but only at relatively flat areas. When you calculate the angle at a certain point in the alpha map, if that angle is above say 30 degrees, set the alpha map value to 0. If its less than 30 degrees, set it to 255. If its 30 degrees +- 10, then perform some sort of smoothing to ease the transition.

Same goes for the rock texture.

Here's a good article on doing what I described above.
http://www.jenkz.org/articles/terraintexture.htm

And then there's already software to do this for you.
T2 Terrain texture
Freeworld3D
L3DT
World Machine

Take your pick.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!