Blending Terrain Textures

One of the most common methods for texturing a height map terrain is with multiple tiling layers.  These texture layers are stacked on top of each other and blended together to create the final textured look. In addition to the tiling texture, each layer also has an opacity map which controls how much of the texture is blended in at any point on the terrain. Unlike the tiling texture this opacity map is stretched over the entire terrain and is therefore very low detail.

Textured Terrain in Titan Quest

In a simple example, our terrain could have two layers: sand and grass. Anywhere the opacity map for the grass layer was painted 1 (opaque) we would just see grass. Where the opacity map was 0 we would see sand, and where it was 0.5 we’d see a mix of sand and grass. Note that the bottom layer doesn’t have an opacity map since the base layer must appear everywhere. This blending operation for two textures is implemented like this:

float4 blend(float4 texture0, float4 texture1, float layerOpacity)
{
    return lerp(texture0, texture1, layerOpacity);
}

The problem with this basic technique is that alpha blending a grass texture with 50% opacity over a sand texture doesn’t really look very good when you look at a closely:

The blended result on the bottom resembles green sand more than a patch of sandy grass.  If the textures were more closely related this would work better, so this can be solved by adding additional artist crafted transition textures.  This however creates more work for the artists, and requires us to render an additional texture layer. Finally, for every combination of textures that we’re going to layer we’d need a different transition texture, and ultimately we might need several.

There is however what I consider to be a better an easier solution which we successfully used on Titan Quest. The idea is that instead of drawing 50% of each texture at every pixel, at 50% of the pixels we draw one texture and at the other 50% we draw the second. This is what it looks like when we do this:

To implement this, we store a mask in the alpha channel of each of the tiling textures. This mask uses the entire range of values and determines whether or not a texel will be displayed when the layer has a particular opacity. Specifically, a texel is displayed if the mask is less than the opacity value.  This new, splotchy blending technique is simply implemented like this:

float4 blend(float4 texture0, float4 texture1, float layerOpacity)
{
    if (texture1.a < layerOpacity)
    {
        return texture1;
    }
    else
    {
        return texture0;
    }
}

The result has a more natural look, and the splotching pattern can be tailored for each type of texture individually. While this grass texture uses a noisy pattern, textures with more structure — such as stones — could be setup so that the blending follows the structure.  With stones, that the alpha mask can be created with high values in the cracks and low values on the flat surfaces.  When this is blended on top of a grass texture, the grass will first appear only in the cracks as the layer opacity is increased.

Because this is a binary decision, the result has hard edges and suffers from aliasing.  It looks best if we smooth out the edges between the textures by doing a small amount of regular alpha blending between the textures. Here’s one way to implement it, although other methods can certainly be used (for Titan Quest we used a simpler method to fit within the instruction limits of ps1.0):

float4 blend(float4 texture0, float4 texture1, float layerOpacity)
{
 
    const float blendRange = 0.1;
 
    if (texture1.a < layerOpacity - blendRange)     
    {
         return texture1;
    }
    else if (texture1.a > layerOpacity + blendRange)
    {
        return texture0;
    }
    else
    {
        float f = (texture1.a - layerOpacity + blendRange) / (2 * blendRange);
        return lerp(texture1, texture0, f);
    }
}

Here’s what the final result looks like:

Although these examples show two textures, any number of layers can be blended this way, just like with the basic technique. This type of blending also isn’t limited to terrain textures, and interesting effects can be produced when the layer opacity is animated. For example,you can see the same type of blending at work in this prototype of dynamic infestation for Natural Selection 2:

61 Responses to “Blending Terrain Textures”

  1. Bramz said:

    May 14, 10 at 11:00 am

    Finally =)

    Nice trick you’re showing here. Discretisation of the ‘control texture’ after interpolation is great to keep different ‘regions’ from mixing too much. It’s simple but very effective. Keep them coming!

    Cheers,
    Bram

  2. Manu said:

    May 15, 10 at 3:06 am

    Very interesting, hope you’ll share other clever tricks with us.
    Good thing with this is, that you can use a really low-res interpolated texture as density input but details in the blending show up in the res of the detail texture. This also plays very nice with detailed specularmaps and bumpmaps.
    I already used a variation of this technique, but never found it described anywhere except in a recent paper on Rendering Grass that also uses something similar to guide the grass-density. Soft particles share the fate: around since ca. 2000 (I still have a copy of the old flipcode article on my hdd), but well known after there was a nvidia white paper in 2007.

  3. marco said:

    May 19, 10 at 12:39 am

    Nice technique, love the detailled description!

  4. Elmigo said:

    Jun 21, 10 at 2:57 am

    Greate tutorial!
    in near future will make variant map class with this technique

    Thanks from Russia!

  5. Dlinna said:

    Jul 20, 10 at 1:01 am

    Hey, nice article.
    But I’ve a little question – what about the size of the blending texture? Let’s say we have a big field – and want to texture it using this technique. So what are the possible ways to solve the problem with the resolution of the blending texture. We can, for example, repeat out texture and, perhaps, also mirror it – but it will look unnaturally (because of repeating the same pattern) especially when looking not from close distance.

  6. Real-Time Rendering · Clearing the Queue (a little) said:

    Sep 08, 10 at 7:30 pm

    [...] Blending Terrain Textures is a nice little article on just that. Lerping bad, thresholding good. [...]

  7. Eric Chadwick said:

    Sep 13, 10 at 2:46 pm

    Stumbled across your blog today, great reading!

    Playing with the Titan Quest editor, it seems to use vertex alpha for the artist-painted opacity map, rather than an actual bitmap. Maybe vertex alpha was just a way for you to generate the bitmap you needed, because it’s easier for the level designers to “paint” vert colors in realtime?

  8. Eric Chadwick said:

    Sep 13, 10 at 3:17 pm

    A couple other examples of the same basic technique:

    Unreal:
    http://www.youtube.com/watch?v=LI4ZHVDuiKo

    Source:
    http://developer.valvesoftware.com/wiki/$blendmodulatetexture

  9. Max said:

    Sep 18, 10 at 1:14 am

    We used textures for the opacity in Titan Quest. They are very low resolution though; if I remember correctly they were about one texel per square meter.

  10. 暗黑3渲染技术分析-地表 « fseraph's space said:

    Oct 06, 11 at 6:01 pm

    [...] 地表混合采用的也是比较传统的方法,这个图是从Titan的主程网站上取来用的,原文在这里:http://www.m4x0r.com/blog/2010/05/blending-terrain-textures/ [...]

  11. rhmznuhsenxq said:

    Aug 07, 12 at 12:35 am

    dinkeDvyHFaZksRiNiF Christian Louboutin Outlet upgareHESeW

  12. N/A said:

    Dec 06, 12 at 2:08 pm

    Great delivery. Sound arguments. Keep up the amazing spirit.

  13. when can i download the fifa 13 demo said:

    Apr 19, 13 at 11:58 am

    This is likely because of the sheer to get down
    thinking draught strategies. The statistical data that they render can serve
    you

  14. cheap nfl jerseys said:

    Jun 08, 13 at 5:17 am

    This is a topic that is near to my heart.
    .. Cheers! Where are your contact details though?

  15. buy proxies said:

    Jul 25, 13 at 11:23 am

    you’re really a excellent webmaster. The website loading velocity is incredible. It seems that you’re doing any distinctive trick.
    Also, The contents are masterwork. you have performed a magnificent
    activity on this topic!

  16. dragreers said:

    Aug 02, 13 at 11:38 am

  17. dragreers said:

    Aug 02, 13 at 12:29 pm

    The Chariot Cougar 1 is the equal seater type of the most popular daughter trailer in the Chariot lineup. It sits in the midway of the Play series between the less costly Cheetah, and flagship CX models, striking a up between features, outlay and weight.
    The Cougar 1 is the in any event trailer as the Cougar 2 individually from the tons of seats, so exchange for a Chariot Cougar 1 study please see the Chariot Cougar 2 review.
    https://www.zotero.org/ganerzbasin Highlights include hold-up that is adjustable to the weight of your children, a sheerest comfortable inner with side foot in the door draught vents and small items safe keeping, five conversion kits to maximise the inject you can contract from your trailer, fold-down storage and superior cover features, including piles of meditative and photo-luminescent materials all around.
    The Cougar 1 is the same trailer as the Cougar 2 separately from the number of seats, so for a Chariot Cougar 1 study divert see the Chariot Cougar 2 review.
    Chariot Cougar 1

  18. PPZOJTX said:

    Aug 02, 13 at 12:35 pm

    http://buylasix.carbonmade.com/#6640 where do i buy lasix – lasix furosemide order

  19. recharge cell phone without charger said:

    May 06, 14 at 2:42 am

    This is also an accessory that works great in boosting a cell phone’s signal.

    Those who call to USA or Canada the most
    will definitely love this sizzlling plan of Tata indicom.

    These chargers have very long lfe because batteries aare thhe
    maion component of these chargers and you can easily replace them with
    the new one.

  20. deer hunter 2014 game for ipad said:

    May 15, 14 at 10:42 am

    Thanks a bunch for sharing this with all folks
    you really realize what you are speaking approximately!
    Bookmarked. Kindly additionally consult with my web site =).

    We can have a link trade contract among us

  21. publicize said:

    May 17, 14 at 2:05 am

    publicize

    Max’s Programming Blog» Blog Archive » Blending Terrain Textures

  22. Valeria said:

    May 20, 14 at 4:13 pm

    Go through this short article for a few of individuals recipes.
    ) It is just the same as the difference between playing the guitar hero game and dreaming of being a rock God – and being a dreamer all your life.
    Place a frying pan or iron skillet over medium to high heat.

  23. jungle heat cheat said:

    May 24, 14 at 1:31 am

    Since then the Cassini spacecraft has detected a slight variation in Titan’s rotation rate that could be caused by a subsurface ocean. Anyone can own a winter jacket
    that not only keeps them warm but looks fashionable. Let’s finish
    with some sort of thought from star Elvis Lopez: ‘I
    love jungle warm hack.

  24. cheap china android said:

    May 24, 14 at 9:31 am

    It’s awesome to pay a visit this site and reading the views of all colleagues concerning this piece
    of writing, while I am also keen of getting familiarity.

  25. illy coffee said:

    May 25, 14 at 9:24 am

    I every time used to read paragraph in news papers but now as
    I am a user of net so from now I am using
    net for posts, thanks to web.

  26. プラダ キーケース レディース said:

    May 25, 14 at 5:44 pm

    You have made your point extremely well..

  27. megapolis cheats android gratuit said:

    Jun 04, 14 at 2:43 pm

    Attractive element of content. I simply stumbled upon your web site and
    in accession capital to claim that I acquire actually enjoyed account your weblog posts.
    Anyway I will be subscribing for your augment and
    even I achievement you get admission to consistently quickly.

  28. Fast Terrain Rendering with Continuous Detail on a Modern GPU | Ragnarok Connection said:

    Jun 06, 14 at 5:50 am

    […] also intended to modify the blending around contiguous features, however that detail wasn’t needed for my immediate application in a flight simulator so I […]

  29. clash of clan hack gemme said:

    Jun 06, 14 at 4:07 pm

    You ought to be a part of a contest for one of the
    best websites online. I’m going to recommend this blog!

  30. Samurai Siege Hack gratuit said:

    Jun 12, 14 at 5:42 am

    This excellent website definitely has all of the information and facts I needed about
    this subject and didn’t know who to ask.

  31. comment tricher sur game of war said:

    Jun 14, 14 at 3:49 pm

    I’ve been exploring for a little for any high quality articles or weblog posts in this sort of
    area . Exploring in Yahoo I finally stumbled upon this web site.
    Studying this info So i’m happy to show that I have a very excellent uncanny feeling
    I came upon just what I needed. I most without a doubt will make sure to don?t overlook this
    site and provides it a glance on a continuing basis.

  32. Telecharger Criminal Case Hack gratuit said:

    Jun 15, 14 at 7:50 am

    Wow, this post is nice, my sister is analyzing these things, thus I am going to inform her.

  33. Dragon City hack indir 2014 said:

    Jun 15, 14 at 8:28 am

    Thank you a lot for sharing this with all folks you really recognize what you’re speaking approximately!
    Bookmarked. Please also consult with my web site =). We may have a
    link alternate agreement among us

  34. Jurassic Park Builder Cheat Codes Gratuit said:

    Jun 15, 14 at 8:31 am

    Wow, incredible weblog structure! How lengthy have you ever been blogging for?
    you make blogging look easy. The entire glance of your web site is excellent, let alone the content!

  35. dragon city hack 2014 gratis ita said:

    Jun 15, 14 at 8:32 am

    It’s actually a nice and helpful piece of info.
    I am happy that you just shared this useful info with us. Please stay us up to date like this.
    Thanks for sharing.

  36. case studies said:

    Jun 15, 14 at 8:27 pm

    case studies

    Max’s Programming Blog» Blog Archive » Blending Terrain Textures

  37. business to business marketing said:

    Jun 17, 14 at 4:10 am

    business to business marketing

    Max’s Programming Blog» Blog Archive » Blending Terrain Textures

  38. properties for sale said:

    Jun 18, 14 at 1:00 am

    properties for sale

    Max’s Programming Blog» Blog Archive » Blending Terrain Textures

  39. Jurassic Park Builder iphone hack gratuit said:

    Jun 21, 14 at 3:54 am

    Paragraph writing is also a fun, if you be familiar with then you
    can write if not it is difficult to write.

  40. top eleven hack indir said:

    Jun 21, 14 at 7:23 am

    If some one desires expert view about blogging after that i advise him/her to go to see this web site,
    Keep up the fastidious work.

  41. amanda knox said:

    Jun 21, 14 at 6:13 pm

    amanda knox

    Max’s Programming Blog» Blog Archive » Blending Terrain Textures

  42. battle pirates hack gratuit said:

    Jun 21, 14 at 6:38 pm

    Hi! I simply want to give you a huge thumbs up for your excellent information you
    have got here on this post. I will be coming back to your blog for more soon.

  43. Photorealistic maps said:

    Jun 28, 14 at 9:13 am

    […] […]

  44. download rust said:

    Jun 28, 14 at 11:07 am

    I like what you guys tend to be up too. This
    sort of clever work and coverage! Keep up the wonderful works guys I’ve incorporated you guys to my blogroll.

  45. download darkwood pc said:

    Jun 28, 14 at 11:07 am

    My developer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the
    expenses. But he’s tryiong none the less. I’ve been using WordPress
    on numerous websites for about a year and am nervous about switching to another platform.
    I have heard great things about blogengine.net. Is there a way I can import all my wordpress posts into it?

    Any help would be greatly appreciated!

  46. goat simulator download said:

    Jun 28, 14 at 11:10 am

    Hello my loved one! I wish to say that this post is awesome, nice
    written and come with approximately all significant infos.
    I would like to see more posts like this .

  47. download motogp 14 said:

    Jun 28, 14 at 11:11 am

    Amazing blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple tweeks would really make my blog shine.
    Please let me know where you got your theme. Cheers

  48. Minecraft Pocket Edition download free said:

    Jun 28, 14 at 1:59 pm

    Hi Dear, are you really visiting this website regularly, if so then you will absolutely obtain fastidious knowledge.

  49. download sniper elite 3 said:

    Jun 28, 14 at 9:54 pm

    I will immediately clutch your rss feed as I can’t find your email subscription link or e-newsletter service.
    Do you’ve any? Kindly allow me know so that I may subscribe.
    Thanks.

  50. real homes real estate said:

    Jul 06, 14 at 12:18 pm

    real homes real estate

    Max’s Programming Blog» Blog Archive » Blending Terrain Textures

  51. depilacja laserowa warszawa said:

    Jul 08, 14 at 9:20 am

    Greetings I am so grateful I found your blog page, I really found you by mistake,
    while I was researching on Yahoo for something else, Nonetheless I am
    here now and would just like to say thanks a lot for a tremendous post and a all round thrilling blog (I also love the theme/design), I don’t have time to read through it all at the
    minute but I have saved it and also added your
    RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the excellent
    b.

  52. Pearl said:

    Jul 09, 14 at 5:03 am

    Thanks on your marvelous posting! I seriously enjoyed reading it,
    you might be a great author. I will make sure to bookmark your blog and will eventually come back sometime soon. I want to encourage one to continue your great work, have a nice afternoon!

  53. sukienki weselne said:

    Jul 09, 14 at 11:16 am

    It’s awesome in support of me to have a site, which is beneficial in favor of my knowledge.
    thanks admin

  54. rich hemp edibles said:

    Jul 12, 14 at 9:04 am

    I absolutely love your blog and find nearly all of your post’s to be exactly what I’m
    looking for. Do you offer guest writers to write content available for you?
    I wouldn’t mind composing a post or elaborating
    on a few of the subjects you write concerning here. Again, awesome website!

  55. http://neftegaz.Ru said:

    Jul 12, 14 at 1:32 pm

    Thanks designed for sharing such a pleasant opinion,
    post is good, thats why i have read it entirely

  56. serrurier serrure said:

    Jul 13, 14 at 11:51 am

    This key works exactly on service de serrurier val de marne the entry and exit points.

    I checked the cuts of the cost of labor should stay fairly low.

    When you stuck such kind of machine, it is important that you will get instant reaction and which can damage your car, get their service, and still in the
    primary locksmith services, as well. See if that locksmith services for
    offices and hotels.

  57. Alpha Fuel XT said:

    Jul 14, 14 at 12:29 am

    Alpha Fuel XT helps your body look ripped. A must try if you want a strong body!

  58. LED Gaming Keyboard said:

    Jul 15, 14 at 1:30 pm

    An interesting discussion is definitely worth comment.
    I believe that you ought to write more about this issue, it
    may not be a taboo subject but typically folks don’t speak about
    these subjects. To the next! Best wishes!!

  59. http://www.atriciaounger.blog.com/2014/07/15/hack-fifa-14-unlimited-money-free-coins-cheats-program said:

    Jul 22, 14 at 12:44 am

    You really make it seem so easy with your presentation but I find this topic to be actually something which
    I think I would never understand. It seems too
    complex and very broad for me. I am looking forward for your next post, I’ll
    try to get the hang of it!

  60. resultscare.com said:

    Jul 22, 14 at 10:23 am

    In fact when someone doesn’t know after that its up to other users that
    they will help, so here it takes place.

  61. angry birds epic hack tool said:

    Jul 23, 14 at 6:19 pm

    Hi Dear, are you truly visiting this web page daily, if so
    then you will without doubt get nice experience.


Leave a Reply