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.