Jump to content
  • Advertisement
Sign in to follow this  
acid2

How is terrain blending done now?

This topic is 4990 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, My game programming background has mainly been DirectX 7 hardware, so no shaders at all. The way that I used to handle terrain was to basically duplicate the terrain and apply a different texture. Then I would use vertex alpha to blend all of these layers together. But seeing as I am now creating a totally shader orientated project - how is terrain blending done? Is there a way that requires only one "layer" of terrain? I had a look at splatting and the article was written in 2002, is this technique still largely used? Any advice helpful! Thanks, - aCiD2

Share this post


Link to post
Share on other sites
Advertisement
The way I am doing this is simply using vertex color (i.e. rgba) values as weights given to four different texture maps in the pixel shader.

So for each pixel do four texture lookups, multiply each one by a component of the color, and then sum these. I thought that four texture lookups might kill framerate (especialy where only one texture is getting applied this technique is very wasteful) but so far it seems fine.

If you needed more than for textures per patch of terrian you could always add more per vertex attributes etc.

The only thing to be careful of is to make sure that the sum of all the color components i.e. r + g + b + a = 1.0 or else you will get saturated areas.

Of course with the technique I just said you are wasting te alpha chanel (though you don't really need it) I just use color for simplicity, when in reality any per vertex attribute is fine.

Peace,
Rob

edit: if you want to look at screenies of my currently VERY simplified terrain (made as a project for my job...soon to become a kick ass demo when I get my sky sorted...) check out http://ciir.cs.umass.edu/~rwhall/terrain.html

As you can see from the wireframe I am not doing any form of LOD at the moment, and only three materials (snow, grass, stone) is used.

Share this post


Link to post
Share on other sites
Looks nice. It's the first time I've heard of a fully shader-based solution as well. Sounds reasonable although does it mean your entire map is limited to 4 different ground types? I guess using the specualr component you could get up to 8 (or have a custom vertex format) but you really want to have up to maybe 3 textures for any given vertex, out of a set of maybe 30 ground types. I've yet to see a decent implementation of this, certaily not making use of shaders in a clever way... I have each vertex using one ground type and these are blended between vertices.

Share this post


Link to post
Share on other sites
cant you somehow store texture and weighting information in the vertex?

i dont know jack about shaders, but if you have a small LUT with texture references in it, you could differentiate between a shitload of textures with only a couple of bits.

Share this post


Link to post
Share on other sites
I once tried to use volume textures to store different ground levels in the slices. The works good for things near the camera but distant terrain gets only a single color as a volume texture gets reduced in all 3 dimensions with each mipmap level. When you store a precalculated base map and use spatting only in areas near the camera it works. This way there is no limit to the number of terrain types used when they just represent height levels. If the order of terrain types is not strictly given by the height and for instance snow can directly go over to grass, rock or debries it might be a bit problematic to build that volume map.

Even if you got more terrain types than textures you can fetch in one pass most of the terrain splats will only require a limeted subset of all terrain textures. If this is not that case with a splat you can always do multiple passes. The number of weighting factors needed to blend the textures together in the pixel shader shouldn't be that much of a problem I think. You've got 8 from diffuse and specuar color. If you really need more you can probably use some of the texture coordinates as the individual ground levels shouldn't need unique texture coordinates.

Share this post


Link to post
Share on other sites
Wow, munkuh your technique sounds awesome! Mind if I implant it in mine, that sounds really nifty - and best of all, simple :)

Share this post


Link to post
Share on other sites
Don't expect micacles. The simplicity of this comes for a price. As I already mentioned mipmapping does not work. May be some "do it yourself" mipmapping could be implemented but I don't know what the visual quality would be. Another point is texture compression. At least nVidia cards don't expose any compressed volume formats in DirectX.

Share this post


Link to post
Share on other sites
Quote:
Original post by d000hg
Looks nice. It's the first time I've heard of a fully shader-based solution as well. Sounds reasonable although does it mean your entire map is limited to 4 different ground types? I guess using the specualr component you could get up to 8 (or have a custom vertex format) but you really want to have up to maybe 3 textures for any given vertex, out of a set of maybe 30 ground types. I've yet to see a decent implementation of this, certaily not making use of shaders in a clever way... I have each vertex using one ground type and these are blended between vertices.


The only limit to the number of ground types that can be applied this way are:

- number of allowed per-vertex attributes (most of which are 4-component vectors, so you have plenty of space there)

and

- number of texture reads you are doing per pixel (don't want this to get too high, or else you probably kill framerate, however ps3.0 (conditionals in pixel shaders) should negate this when it becomes mainstream).

If you divide your terrain into patches, then you can change the textures you use on a patch-wise basis...you probably wont want much more than 3 or 4 textures per patch anyway, since terrain is usually fairly homogenous over short distances, but theres no limit to the number of materials used over the entire terrain...

Share this post


Link to post
Share on other sites
To get volume texture slabs working with mip-maps, you need to use more than a single pixel slab per terrain layer.

For instance, if you have 256x256 textures with 4 different layers, and you want 4 levels of mipmaps, you make the top 3d texture layer

256x256x32.

then, the lower mip-levels become :

128x128x16
64x64x8
32x32x4

Each slice in the top layer is 8 pixels high, and your texture coordinate should sample from the middle of each slice. That way, as you drop miplevels, you are still grabbing from only that one layer.

I know of at least one commercial game that uses my idea for this successfully.

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!