September 15, 2016

Seamless Mountain Texturing in UE4


Landscape materials in UE4 can be quite daunting to tackle. Most of what your player will be looking at in your environment is the landscape, yet if the landscape material is too complex, it will become the worst performance hit in your project. Multiple surfaces need to blend in with each other, and the surface needs to work both up close and further in the distance, which means expensive materials all around! But mountain ranges are especially tricky with those tall, vertical mountainsides that stretch out textures beyond belief. So, how exactly is anyone expected to make a good mountain range or cliff using landscape in a videogame, exactly? Turns out, the answer is pretty novel: use world positioning to map a texture at the X and Y planes, blend around the edges, then blend that with a top surface to prevent too much texture stretching at the top. Along with that, you can use another simple color blend texture (1 pixel wide, 64+ pixels tall) to wrap up and create those nice Grand-Canyon-esque layers in the rock.

Benefits to this method:
  • Completely seamless texturing!
  • Supports normal maps, roughness maps, parallax occlusion, and all other texturing methods!
  • Looks great on both steep cliffs and smooth slopes!
  • World-aligned means you can set up geologic layers in the rock, and no matter how your models are positioned the material will still look appropriate!
  • World-aligned also means you don't need to setup UVs on any objects! Yay!
  • Cheaper than most complex materials to achieve XYZ texturing (22 extra instructions to go from basic UV texturing to XYZ seamless).
Limitations of this method:
  • The cost is more expensive than basic texturing via UV coordinates: plenty of blending and interpolation needs to be done to get it to function properly. But this cost is not bad for the final result.
  • Can be tricky to get complex textures to look good. Wrapping textures and smooth tops work the best. Complex blends can work with a more advanced mask setup, but also costs more in performance.
Make sure your texture tiles well when blended smoothly from side to side. This is crucial because if the texture does not look good when blended smoothly, it will break the illusion of a seamless blend. It also needs to tile seamlessly from all sides. Emphasize horizontal streaks in your texture. A normal map is also recommended. While my example uses a simple 0,0,1 smooth top normal, your top texture and normal can be whatever you want. However, more detail will not tile as well as less detail and doesn't blend as nicely. A complex blend for the top that effectively masks unused portions of the texture can be constructed on top of this method to create a very seamless and detailed surface, but it will require a greater performance hit than the method shown here.

This method was used on a rock surface costing only 110 instructions (vs. 88 for basic texturing). All things considered, this is the cheapest and best-looking XYZ blendable method I know of.


Absolute World Position, divided by your desired size, split into two separate masks: GB and RB. Or, a planar map from the X direction, followed by the Y direction. Plug those into two copies of each texture you wish to apply. Lerp between these two texture maps at their extremes, which I calculated by using the absolute value of a dot product between the vertex normal and X direction. The absolute value simply flips the opposite side, the end result is a smooth gradient mask across the object with surfaces angled towards the X direction as white, and perpendicular to the X direction as black. This is how the blend wraps around appropriately. Then, I lerped that with a dot product between 0,0,1 and vertex normal to determine a mask for the top surface. We will blend between the X and Y surfaces first to get a nice cylindrical blend, then the top blend later. You can use power, lerp, and clamping adjustments along with complex blends to control this top mask. For this example I lerped [-0.3;1.0] and raised it to a power of 4 to get a sharper blend towards the top and prevent the textures and normals from simply washing out.

Side blend (-X and +X are white, -Y and +Y are black)
Top blend (Z+ is white, perpendicular and bottom is black)
Combined Blend (red is Side Blend, green is Top Blend)
Final lit blend
The horizontal "layered" bands are also calculated in world position. While it is possible to put this coloring into the wrapping texture, it's nice to keep this separate to break up the repetition while giving the coloring a more consistent, logical approach. Eliminating this strand from the rendering process can optimize the technique.



This technique works on any kind of rocky assets! Just note that texture seams in the UVs will also cause the vertex normal to split, and, by association, this texturing method as well. If you're serious about using this method for perfectly seamless texturing on rocks, you can import your model without any UVs at all. Smooth normals alone will be fine. But if you like your Z-Brush normals, you can use a world-space version of those instead of the vertex normals :)

4 comments:

  1. hey man can u send a screenshot of the material using parallax occlusion with world aligned texture ?

    ReplyDelete
    Replies
    1. Wow! Sorry for the late reply. Unfortunately, I no longer recommend using parallax occlusion for this material. Since you'd have to perform the parallax 6 times, it would bog down performance to an insane degree, and landscape is already hard enough to render. Plus, parallax doesn't behave well with blending: parts of the material will appear to "float" over others. I think having good textures and normals will trump parallax effects, which should be kept to a minimum if you choose to use any at all.

      Delete
  2. Can you rotate it so it's slanted?

    ReplyDelete
    Replies
    1. Yes you can! I forgot the exact means of it, though. Something to do with the UVs of the texture and world z values...

      Delete