Jump to content
  • Advertisement
Sign in to follow this  
QuadMV

Terrain texture blending

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

Hey all, I know this might be a soar subject for some, since it’s been talked about soo many times on so many different threads. I apologize if I offend anyone by asking the same thing over again. I’ve been programming for over 30 years. I use to do DirectX as a hobby, but have been away from it for a number of years. I’m trying to get back into it, and I’m taking a 3rd crack at trying to nail my terrain system. At this point, I still have some problems with texture rendering/blending, and although there are a lot of posts most of the time I don’t understand the technical details being discussed and I am therefore hoping a kind individual would be willing to share some conversation either over email or ICQ, or this form is fine too. My previous work can be seen at http://www.3dmuve.com, but I’ve not touched it in a couple of years. Two of my questions are as follows: 1. I’ve seen discussions about using multi-pass and using a weight for the alpha blending on the vertices. Does this mean the textures are all solid (no alpha channel in the texture itself), and the alpha is defined as part of the DirectX vertex within the vertex buffer? My vertex currently looks something like this: #define D3DFVF_TERRAINVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) If so, does this also imply different vertex buffers for each pass, since the alpha would be different for each pass? If so, isn't that a lot of video memory? Is it safe to assume most people have 128+ meg and probably isn't worth worrying about? 2. Although my textures are tile-able, due to patterns in the texture, I’m still getting a very blocky looking affect on my terrain (no version). Are there textures that don’t produce this artifact, or are there other tricks being used the help eliminate this? Thanks to any and all for helping me out. Q

Share this post


Link to post
Share on other sites
Advertisement
Hey QuadMV,


1)
Instead of the multipass aproach, it seems more feasable to do one pass multi-texture. For each vertex include information for weighting on each texture and on the vertex processing step apply the weight to the alpha channel.

2) To get rid of repeating textures, its nice to stretch one base texture across your whole terrain. This will help break up the repetition.

I would explain more in-depth but there is a great, easy to follow article by Frank Luna here Read it and if you have any questions post them back here.

Share this post


Link to post
Share on other sites
Thanks, I took a look at it, and it's definitely given me some ideas. Let me ask a couple of quick questions.

1. what is .cs, c-sharp? I use Visual Studio 6 w/ c++. When I tried to run the sample app, it crashes during initialization. My video card is an ATI Radeon 9800Pro, which should have all the minimum requirements.

2. Before I get too far down one path, I want to continue with my current engine, which I can change and manipulate easily. Therefore, could you help me understand how to setup my environment for multi-pass, and I’ll go back to messing with shaders later.

In my current environment I’m setting up a vertex buffer using:

#define D3DFVF_TERRAINVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)

If I want to blend 3 textures over the same triangle, how do I define my vertex buffer? What represents the blending, diffuse, or is there another value I need to add? Do I need 3 different vertex buffers?

Remember, I’m just trying to get it working with my current system for now, without overcomplicating things.

3. What would I set the various texture stages to, and any other device settings prior to calling the draw primitive? Currently it’s something like this:

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );



Thanks

Share this post


Link to post
Share on other sites
Well, you still don't need 3 vertex buffers, though you could and it would make programming really easy! If you went the 3 vb approach you would just calculate the alpha value for each vertex of the triangle. Then enable alpha blending and render three times with each vertex buffer. Of course, you could pack them all into one vertex buffer end to end and make one draw primitive call. If you did it this way, all you would need is XYZ|DIFFUSE|TEX1 the diffuse components alpha would need to be set for each textures weight.

There is also the option of storing the blending into the diffuse and specular channel and using multi-texturing. That way in one pass you could get two texture blended and then another pass you could do the remaining texture.

Share this post


Link to post
Share on other sites
1. Since each texture would need a different alpha, and since the alpha is part of the vertex definition within the vertex buffer, I'll need different VB's or I'll need to redefine the color component of the VB for each texture rendered, right

2. Is D3DCOLOR (R,G,B,A) based on 0-1 or 0-255, so 100% alpha = 255 or 1?

3. When using the alpha component of the diffuse color, what do I set the src and dest blend to?

D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR
D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR

or

D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA

When I use srcalpha, nothing happens. with srccolor, it does seem to work, but I don't think it's because of the diffuse setting. A set the color back to 0, and I'm stillgetting some sort of blending, so I think I have my texture stage settings wrong.

Share this post


Link to post
Share on other sites
To get really nice terrain you will probably have to go with alpha-maps. These modulate the texture transparency for each texture-layer per-pixel (instead of per-vertex as with vertex-alpha) using a single alpha-map texture for each texture-layer.

For a decent frame-rate you will want to multi-texture rather than multi-pass - modern graphics-cards handle this very well (I'm getting 300 FPS+ on my 6800).

In my current terrain engine i'm using a pixel-shader to access the alpha-map, which has alpha values for all layers encoded into the RGBA channels of a single alpha-texture which speeds things up considerably.

I'd be happy to provide more information if you need it, 'cos I like talking about terrain :)

Share this post


Link to post
Share on other sites
The texture alpha map idea works but its makes it harder to get more realistic terrain.

Using the simple vertex alpha method you can set the alpha based on the "slope" of the triangle. Thus you render solid rock first, then render grass, and depending on the "slope" of the triangles the grass will show or won't show. A steep triangle will be pure rock where flat triangles will be pure grass. Of course this method requires a lot of tweaking to get right.

Afaik the alpha map method works fine and is much easier but the you gotta take the time to make your cliffs look like cliffs for example...I think, I've never tried the alpha map method.


If the two methods are combinable, then you could use the alpha-maps to get your walkways, paths, roads, etc onto your terrain afterwards.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I too am interested in achieving nice multitexturing effects for terrain using the fixed function pipeline only. QuadMV, if you discover a technique that works, will you please post it here? I will do the same :)

Share this post


Link to post
Share on other sites
Scoot,

I am interested in learning more about alpha-maps as well as leveraging pixel shaders.

What I was trying to do was something quick and dirty just to see I can have something reasonable working, then go back and add alpha maps and/or pixel shaders.

At the moment, I can't get multi-pass working and I'm pretty sure it's because I have something wrong with my settings such as: SetTextureStageState, what do I set for multi-pass? If you could help with this initial need, I'd appreciate it.

Next, once that is working I'd like to proceed to a single pass, and in that case I'll need help understanding how to setup directx for single pass renderring, and a lot of help understanding how to apply and alpha-map. I understand alpha when it's part of the texture as used in billboards, and I understand the concept of alpha when it's part of the vertex color channel, but when it comes to mixing it all together to generate a single pass multi-texture terrain, my knowledge level falls way off.

Any sample or code snipets would be greatly appreciated.

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Halsafar
The texture alpha map idea works but its makes it harder to get more realistic terrain.

Using the simple vertex alpha method you can set the alpha based on the "slope" of the triangle. Thus you render solid rock first, then render grass, and depending on the "slope" of the triangles the grass will show or won't show. A steep triangle will be pure rock where flat triangles will be pure grass. Of course this method requires a lot of tweaking to get right.

Afaik the alpha map method works fine and is much easier but the you gotta take the time to make your cliffs look like cliffs for example...I think, I've never tried the alpha map method.

If the two methods are combinable, then you could use the alpha-maps to get your walkways, paths, roads, etc onto your terrain afterwards.


Oooook - well, to get "realistic" terrain then (in my opinion) the only real option is alpha maps - I think you are getting confused. Think of the difference between vertex lighting and per-pixel lighting (e.g. normal maps) - the per-pixel version gives you far finer control (and so much more realistic results), but is basically the same technique.

Alpha-maps are basically the per-pixel version of rendering with per-vertex alpha - they allow you to define sharper edges to your blending, whilst with vertex-blends you will only ever get as good blending as your geometry-density is.

As for slopes/whatnot, how you generate your alpha-maps is up to you, I use rules for applying texture-layers (gradient is one of them), and use a nice blurred airbrush effect to blend the edges of textures together to reduce the old-fashioned vertex-blended look of older terrain engines.

I guess it all comes down to a couple of things: How good a terrain quality do you require, and what hardware do you wish it to run on? If your answer is good quality, and with a reasonable hardware-set (such as your 9800), then go for a vertex/pixel shader combo using alpha maps and detail textures. Detail textures are important because without them your terrain will look extremely tiled at long distance.

Using a decent frustrum-culling algorithm, some kind of CLOD, and shaders you can get some extremely good framerates (around 300 FPS), even with a large draw-distance (10 miles+).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!