• Advertisement
Sign in to follow this  

How is terrain blending done now?

This topic is 4722 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
Texture splatting (or some form of it) is the most common method I've seen.

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
Quote:
Original post by SimmerD
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.


I had the same idea when I experimented a bit with this some time ago. Isn't there a problem with blending between different texture layers as it will never will work the same way for all resolutions without adjusting texture coordinates according to which mipmap level is currently used?

By simply doubling each slice each mipmap level will get "sharper" transistions between ground levels wouldn't it? Even when manually interpolating the inbetween slices I never got it excectly right.

Share this post


Link to post
Share on other sites
see here
http://motueka.homeip.net/captain_courgette.html
under shaders directory ... terrain ... .glsl
they give an example of how to do it, u can easily expand the num of layers ie
rgba = 4 but u can easily pack two (or four) values into r thus giving u 8 or 16 layers

Share this post


Link to post
Share on other sites
If my card only has 2 texture units, can I still pass info to shaders using the tex-coord pointers for other texture units (TEXCOORD0-7)?

Share this post


Link to post
Share on other sites
Are there any cards with only 2 texture units that run shaders? DX8 class hardware is required to have 4 texture units I think. Anyway if there are only 2 texture units there won't be more texture registers to pass data to fragment processing.

Share this post


Link to post
Share on other sites
The idea is that you use the volume trick to reduce batch size, not for blending the layers.

You can use the volume trick to give you one of several layers with proper tiling & mip-maps, then fetch this multiple times in the shader for each layer at a different 'r' texture coordiante, and blend them together.

Otherwise, if you have many combinations of layers, like each terrain chunk can have 4 layers out of a possible 16, then you can do this all in one call. Otherwise, you'd need to handle many more permutations.


Quote:
Original post by muhkuh
Quote:
Original post by SimmerD
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.


I had the same idea when I experimented a bit with this some time ago. Isn't there a problem with blending between different texture layers as it will never will work the same way for all resolutions without adjusting texture coordinates according to which mipmap level is currently used?

By simply doubling each slice each mipmap level will get "sharper" transistions between ground levels wouldn't it? Even when manually interpolating the inbetween slices I never got it excectly right.

Share this post


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

  • Advertisement