Wednesday, June 6, 2012

Distance Based Texture Blending (UE3/UDK)

Repetitive patterns of tileable textures can be a real pain, espacially when working on terrains. Common ways to fight this effect is the use of detail textures or a multiplication of the texture by itself at a different scale. However these methods have some drawbacks and won't give you completely satisfying results in some situations.

This led me to another approach: blending the diffuse map with another texture at a certain distance. That can be (for example) the same texture with a different (=less) tiling, an overall landscape texture or a multiple tiled version of the same texture just without noticeable repetitiveness.



Material

For a material editor implementation you start off with calculating the distance between the World Position and Camera World Position. This is usually a quite large value but by dividing it by a large number (I suggest values between 4096-32768) you can bring it close to the 0-1 range. Afterwards you plug that on into a power node to control the transition falloff. A minimum value of 2 is highly recommended to prevent the near diffuse texture to get blurry. All you have to do now is clamping the result between 0 and 1 to use it as the alpha input of a Lerp node.



In older UE3 builds (like in UT3) there won't be neither a WorldPosition node nor a Distance node. But you can recreate those node functions by setting up your material like this:





Example

Here you can see typical repetitive patterns of a tileable texture on a large landscape:


For the distance blending I did create a 16 times tiled version of the same
texture in Photoshop and removed recognizable repeatings:

 Finally, a screenshot with just the Lerp nodes alpha input:


7 comments:

  1. Awesome tutorial man! I have been wondering how to do this for a while now and stumbled across it whilst looking for something else. Thank you very much :)

    ReplyDelete
  2. thank you so much man this was exactly what i was looking for!

    ReplyDelete
  3. ThANK YOU SO MUCH!!

    ReplyDelete
  4. Hello

    Please can you explain how to achieve the same distance based texture blending with UE4 ?

    ReplyDelete
  5. Thank you so much for this tutorial! I've been struggling with this for a while and finally managed to get it working thanks to your help. For others making the same mistake as me, what you need to lerp is the *textures* UV-ed at different tile sizes, do not lerp the UV tile-size itself and feed it into a single texture node like I was mistakenly doing.

    PS: This tutorial works for UE4 as well, all the node names are almost the same just use the new material editor and plug the nodes like in this tutorial.

    ReplyDelete