Jump to content
  • Advertisement
Sign in to follow this  
ProgrammingNerd

texturing terrain

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

How can I texture my terrain, and I'm using a heightmap-style terrain. I recall reading in a earlier post how to do this using pixel shader 2.0. But, being poor, I only have a card with pixel shader 1.4 and vertex shader 2.0. Is it possible to do this? I don't want to have to resort to the ffp, though. Thanks for you help, ProgrammingNerd

Share this post


Link to post
Share on other sites
Advertisement
In FFP, you'd do this using texgen, which means you set up two vectors, and your texture coordinate is the dot product between your texel position and the vector.

You can do the same thing in your vertex shader. Send in two constant vec4-s, and do a DP4 between the world-space vertex position and the constants, stuffing the result in output U and V texture coordinates.

Assuming Y is up, you'd make the U vector something like (1/tile,0,0,-offsetU) and the V vector something like (0,1/tile,0,-offsetV), where -offsetU is the X coordinate at which you want to have U == 0.

Share this post


Link to post
Share on other sites
Hi,

Sorry I had to leave, needed some sleep.

That seems to be a ok way to do texturing, although it seems to be limited. Are there other ways to texture terrain. I wan't to find the best way possible.

Thanks for you help,
ProgrammingNerd

Share this post


Link to post
Share on other sites
hi,

I think the method I use can work in pixel shader 1.4 (I can't test it here though) The texturing method I use allow up to 4 detail textures being blended together.

I have basically 3 textures.

- 1 small (256x256 or 512x512) which gives the details (rocks, sand, grass, etc.) and is tileable. In fact, my detail textures are only in 256 grescale, so I can have 4 detail textures in 1 file (1 for each channel)

- 1 big color texture which gives the color. As the detail texture are greyscale, this color texture is needed.

- 1 big blending texture. This one tells how to blend the different detail textures together. The R channel will give the percentage of the detail texture stored in the R channel of the detail texture file, etc.


The small detail texture works as an overlay (like in photoshop) which modulate the color texture to add small detail.
I chose to do the texturing like that because the pixel shader become really simple :


float4 blending = tex2D(g_BlendingTextureSampler, iTexCoord0);
float4 color = tex2D(g_ColorMapTextureSampler, iTexCoord0);
float4 detail = tex2D(g_TiledTextureSampler, iTexCoord1);

// here, I apply the blending in only 1 multiplication
detail = detail * blending;

// then, I compute the overlay factor
float overlay = detail.r + detail.g + detail.b + detail.a;
overlay = overlay * 2.0f;

// and I modulate the color by the overlay term to add the details
oColor = overlay * color;




Nothing complicated. It's limited to 4 different details though (one in each channel)

Share this post


Link to post
Share on other sites
Sounds like a good method. Is it a bit limited though, being that I can't place rocks, etc exactly where I wanted them. It is a good concept, and it will be my fallback if I can't find anything else.

Thanks for your replies, you guys are great,
ProgrammingNerd

Share this post


Link to post
Share on other sites
I think you don't quite understand terrain rendering very well. Rocks and terrain features like trees and grass are generally placed in the level as meshes, not part of the terrain texture.

Share this post


Link to post
Share on other sites
I suppose placing rocks, etc is a bit tedious and redundant. Thanks for making that point. I just don't want the experience that it is the same ground i'm walking on all time; I want to use different textures on my terrain, not repeating the same ones; creating paved roads, etc. without having to use a separate mesh for it.


PS I know terrain rendering well enough. I created my heightmap engine without a book. And I know how to place objects, trees, lakes, etc. on it. Maybe I gave you the wrong impression.

Thanks for all the replies,
ProgrammingNerd

Share this post


Link to post
Share on other sites
hi again,

as i said, my method is limited to 4 different "type" of terrain. But it's easy to overcome this limitation. Imagine your terrain is formed by patches. Each patch may have different detail layers. You just need 1 detail layer which is common to neighbour patches (to make the transition between patches)

This way, you can have (for example) on 1 patch : sand, grass1, road, rock, and on a neighbour patch : sand, road, asphalt, grass2.
the sand detail layer makes the transition between the 2 patches.

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!