Jump to content
  • Advertisement
Sign in to follow this  
cragwolf

OpenGL simple idea for terrain map ... possible?

This topic is 4968 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

I have no experience with shaders, but I'm wondering if it's possible to do the following with them: Start off with a terrain 512x512 vertices. 1) You have 3 base textures: a grass texture, a dirt texture, and a rock texture. 2) You also have a 512x512 image that I will call a land-use map. 3) You will colour each vertex of the terrain mesh according to the colour of the corresponding pixel on the land use map. 4) Create a shader that does the following: i) Reads the vertex (or fragment) colour, and then applies the correct blend of the 3 base textures. For example, a red (255, 0, 0) vertex means just show the dirt texture; a green vertex (0, 255, 0) means just show the grass texture; a blue vertex (0, 0, 255) means just show the rock texture; other colours will cause the shader to blend the 3 textures in appropriate percentages. ii) Do this in one pass. I guess this means using multitextures? iii) I think this technique uses 3 texture units leaving one free (am I right in thinking that most video cards that gamers use have 4 texture units?) for something else, either another base texture (e.g. sand), in which case I can use rgba, or something completely different like a detail texture or a lightmap (I suppose I could do the lighting in the shader as well). Consider the advantage of this technique to a game developer. Now, if users of his game want to create maps for his RTS game, they simply create a land use map, no need for the user to have superb artistic skills to create the textures themselves. Then the game will read the land-use map at the start, and then in one pass per frame it can render the terrain. Is this possible with shaders and OpenGL? I guess I have a lot of reading and experimenting to do, but I wanted to know from the start whether such an idea was feasible, or even if there was a simpler way to do it.

Share this post


Link to post
Share on other sites
Advertisement
You can have 1 texture that is your land use map (LandTex), where R = BaseTex0, G = BaseTex1 and B = BaseTex2. Then in your shader you basically do:
color = LandTex.r*BaseTex0 + LandTex.g*BaseTex1 + LandTex.b*BaseTex2
(depending on pixel shader version you may have to do dot products to extract the individual LandTex colors, but it can still be done). This could be done in 1 pass on a GeForce3/Radeon8500 or better.

Is that what you are looking for?

Share this post


Link to post
Share on other sites
cragwolf: sounds like youve got a good mind to yah :-) However, there is something nearly exactly like that already in existence(sp?) Its called "texture splatting", and its a great technique. Of course there are little implementation details but yeah. I suggest you start learning glsl (openGL Shading Language).

hope that helps
-Dan

Share this post


Link to post
Share on other sites
As has been said, this is a pretty common technique. And you don't even need any "artist" to paint your land-use map. The different weights can very easily be computed based on the height and slope of the terrain. Of course it's probably a good idea to have some sort of mechanism in place to override that so that using something like your land-use map so that you can have more control in places where you want a certain texture.

Share this post


Link to post
Share on other sites
Quote:
Is this possible with shaders and OpenGL?

yes, check out the terrain shaders in my game they use this technique

Share this post


Link to post
Share on other sites
I made this using a tutorial I found in Flipcode.

http://rel.betterwebber.com/junk.php?id=38

He called it the terrain blender.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
To re-iterate, not only is this possible, it's quite easy with shaders. Multi-texturing with a fragment program is a good several orders of magnitude easier than multi-texturing with the OpenGL register combiner extensions in my opinion.

Share this post


Link to post
Share on other sites
It's indeed extremely easy with shaders. Multitexturing takes a lot more passes and may not necessarily be faster. To blend 2 textures using a 3rd alpha texture for alpha map you need to interpolate between them using the 3rd texture's alpha -- that's 3 texture units... then you need to combine the result with the GL_PRIMARY_COLOR to have proper lighting and material properties applied, thats a 4th texture unit with a blank texture, unless there's an easier way? It's possible to cram the alpha texture into an alpha channel of the 2 textures as well, but then you can't stretch it across the terrain...

Pixel shaders are incredibly easy though. Making my terrain look like this a year ago took no time at all:

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!