Terrain Mesh Normal Blending with Virtual Textures Guide!

Hey its my first post here. Hope this guide will help yall !
Couple of months ago when i started playing with Ue4 i was obsessed with terrain mesh blending. So i started searching but couldnt find any tutorial on how to do it. After some search time and experimenting i finally found a solution. It was already there but i couldnt get it to work properly. Since i found how to do it, im sharing it.
I used Unreal Engine 4.24 for this guide. For fastest testing i only used base color and normal map textures for both landscape and meshes. And constant 1 roughness. Since this method uses runtime virtual textures, at certain angles textures will stretch. Thats the downside of this method. I think it can be fixed with tri planar textures if you need to.

First let me show you how it looks. Lit, unlit and world normal.

1-) First of all i enabled virtual texture and mesh distance fields from project settings. Neither of them are necessary but its the convenient way to do it. Distance field will mask closest meshes. It can be done with vertex color painting instead, which is perfectly fine and more optimized. Virtual texturing is for sampling normals and textures of terrain to blend. Optionally render target 2d can be used instead but i dont recommend it.

2-) Next, i created a runtime virtual texture (You can tweak its values for higher res textures). Than i selected my landscape and choose my virtual texture from details panel. Than i added a runtime virtual texture volume to my leve. I selected my landscape from details panel and copied rotation and scale and selected my runtime virtual texture.

3-) Landscape material. I used a simple material for landscape, it has 2 layers. Than added a runtime virtual texture output and plugged my base color and normal textures. The problem is normal output will give tangent space normals to other meshes. Which i dont want because i need to blend with terrains world space normals. For that i used transform vector node thats set to tangent to world space. But it gives an error. I dont know why, its working fine so i didnt mind but i will try to fix that in the future.

4-) Blending mesh material. First of all, i disabled tangent space normals from details panel. Because it will sample world space normals from terrain so it shouldnt see it as a tangent normal. And for meshes normal map i used transform vector and convert it from tangent to world space which normally what happens when tangent space normal is enabled. I only need to blend edges so i used distance to nearest surface and created a material function for that. And then i added a runtime virtual texture sample node to get terrains textures, and i selected my virtual texture from details panel. And lerped meshes and terrains textures.

5-) I added a mesh to my level, created an instance of blending material, select my meshes textures. I disabled “affect distance field lighting” from meshes details panel because when its enabled it gives inaccurate results.

And here is shader complexity.

I think thats pretty much it. I hope that was helpful. You can ask questions if you have any, or reccomendations.


Awesome work, I was wondering if there was a way to do terrain mesh blending without having to manually set up the material with whatever terrain material is under it and this is the way to do it. Thanks dude!

Edit 3: Figured it out - the size of your terrain is sadly kinda limited by the maximum VT size, or else you get blurry results from the VT Texture Sample.

how much compiling shaders you have when use virtual texture? in my map is about 54000 compiling shaders and crash 4.24

And which size is this, currently? I’m thinking about using RVT for a landscape.

This is the method i’m actualy using too but as **n00854180t**said, RVT are actualy unusable with common lanscape size, until Epic adds adaptive virtual texturing to the engine like what Ubisoft did in their Dunia engine used for Far Cry 4. But I don’t even think it’s on the roadmap

RVT blending is very interesting with posibility of auto texture color blending from the landscape. Do you know is it possible also blending with RVT between meshes/assets? Under is an example of blending landscape-sphere and landscape-megascans asset. But how to blend between sphere and asset?

I’d be veeeeery curious to know the answer to the question of RONOWE, just up above… Some guys on discord tell me it’s possible but I never seen this usage (blend regular 3D assets instead of blend an asset with the landscape). I also tried by myself but as a total noob to RVT, nothing work for the moment…

The rtv captures what it sees in a flat 2d space, so using it with something like a sphere is already a bad idea.

Very interesting… So according to what you said, I can claim that the RVT does work, maybe, between two regular meshes, if one of them is a flat surface ! It’s a bad idea if you try to blend two meshes like these in the RONOWE’s picture (I’m talking about the rock and the sphere) but, let’s say we are trying to blend this (let’s say it’s a rock on top of, I don’t know, some kind of platform) :

The surface that blends is flat (or let’s say almost). But in the same time, the assets are not just simple flat surfaces. I mean they are not 2D planes. So the question I’m asking is : What the RVT captures or sees exactly ? The entire texture or just the area where the textures of each assets cross together ? When I see how it works in videos, I guess it captures only where it cross but, I don’t know, I have a doubt… Well, in other words :

This way of blending with RVT (landscape with mesh) is OK, for sure :

This way is bad, for sure too (let’s say it’s 2 rocks or kind of that) : ](filedata/fetch?id=1837911&d=1606836250)

But what about my first picture ? Is the RVT system will capture some duplicate Z points (I’m talking about the height coordinates) as the blue mesh has, in short, a face above and a face below ? And so this is certainly problematic… Or will it capture just the area where the textures of each assets cross together ?
If the second assumption is right, so it’s all good. If it’s the first that is, I guess we could easily fix this issue by cutting the blue mesh to make it look more like a real 2D plane, like so (like if it has a hole) :

Maybe it also needs to cut the blue mesh a little heighter because it is still a bit curved “toward the inside” so that’s why I colored the base in light blue (it’s a very simplified and schematic draw ; find the parts of the mesh that “curve toward the inside” would be more complex in reality, on a 3D asset, but I think you get what I mean…)

What do you think about this ?

What happens if you take a screenshot in TOP view when a rock is over a terrain? Do you see the bottom of said rock?
This is exactly the same for what the RTV produces.

Thanks ! So it’s plain and simple : it means it works ! I thought it can be used only with the landscape but it’s not. A bit weird that everybody use RVT only with landscape but, well… So good to hear that RVT offers such possibilities ! Gonna continue to learn this awesome stuff ! :stuck_out_tongue: …

1 Like

Hi, as today is there a good solution for blending 2 meshes?