BlueRoseNote/03-UnrealEngine/LevelScene/Ue4中的场景物体融合方式与优化.md
2023-06-29 11:55:02 +08:00

85 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 前言
突然想起几个月前在Quixel发布的一篇技术文章里面归纳了几个场景物体融合方式主要是与地形融合甚是不错。隧简单翻译并分享给大家。
原文地址https://quixel.com/blog/2020/1/22/blending-megascans-assets-in-ue4?utm_campaign=Tutorials&utm_source=youtube&utm_medium=social&utm_content=Goddess%20Temple%20in%20UE4:%20Lighting%20%26%20Blending
这里使用MegaScans中的"Damp Soil"、"Cut Grass 2×2 M"与"Grass Clumps"资产。
## World aligned texturing
![](https://blog.megascans.se/wp-content/uploads/2020/01/image14-1.jpg)
直接译为**世界坐标映射贴图**。通过模型顶点的世界坐标将贴图映射到模型上。大致原理如下:
![](https://blog.megascans.se/wp-content/uploads/2020/01/image19.gif)
官方的AutomotiveMaterialPack与TwinmotionMaterialsPack材质包使用这个方法。这个方法广泛用在CAD、建筑等方面。这里介绍的主要是与地形融合的思路.
大致用法如下:
![](https://blog.megascans.se/wp-content/uploads/2020/01/image25.jpg)
上图展示了通过控制x、y值来控制贴图平铺效果。
映射到球体模型的效果如下:
![](https://blog.megascans.se/wp-content/uploads/2020/01/image16-min.gif)
一个完整的PBR材质大概是这个样子的
![](https://blog.megascans.se/wp-content/uploads/2020/01/image17.jpg)
材质实现https://blueprintue.com/blueprint/101g7t_k/
>这个方法的缺点在于平面与模型的接缝处过度十分突兀。但它的性能十分的好,配合其他方法使用能得到很好的效果。
## Pixel depth offset
![](https://blog.megascans.se/wp-content/uploads/2020/01/image5.gif)
为了解决过度突兀的问题,我们可以通过**像素深度偏移**(Pixel depth offset)配合DitherTemporalAA节点来解决这个问题。
大致用法如下:
![](https://blog.megascans.se/wp-content/uploads/2020/01/image22.png)
效果如下:
![](https://blog.megascans.se/wp-content/uploads/2020/01/image15.gif)
>仔细观察过度处可以看得出过度非常自然了。同时因为这个方法主要用到了TAA的抖动算法通过视觉暂留现象来实现半透明过度所以性能十分的好。缺点是材质Alpha较低时交界面容易产生错误的混合效果。当Alpha较高时容易产生TAA特有的鬼影现象。
![](https://blog.megascans.se/wp-content/uploads/2020/01/image13.gif)
材质实现https://blueprintue.com/blueprint/bwa_kbpc/
## Distance field mesh blending
![](https://blog.megascans.se/wp-content/uploads/2020/01/image9.gif)
该文作者认为这个可能是最佳方案。因为**距离场模型融合**是直接修改地形顶点,属于真实的过度效果。所以不会出现任何抖动问题。
大致效果如下:
https://www.bilibili.com/video/BV1ef4y1X7QZ/
{% raw %}
<iframe src="//player.bilibili.com/player.html?aid=287028163&bvid=BV1ef4y1X7QZ&cid=234182542&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
{% endraw %}
使用之前需要执行以下步骤:
1. 在Settings-Project Settings中搜索distance fields确保Generate Mesh Distance Fields选项处于勾选状态。
2. 在想要融合到地面的物体的属性中取消勾选Affect Distance Field Lighting选项。
![](https://blog.megascans.se/wp-content/uploads/2020/01/image20.png)
接下来就创建材质了:
![](https://blog.megascans.se/wp-content/uploads/2020/01/image10-1.jpg)
右边的粉色框中节点将会连入Normal槽你可以用一个参数变量来控制混合强度。因为当前材质没有混合地形与模型物体的纹理只是平滑了交接面附近的法线。所以为了得到更好的效果我们使用WorldAlignedTexture工作流程并给它们与地形接近的纹理这会达到一个更好的融合效果。
由于我们禁用了Affects Distance Field Lighting这使得该融合物体无法使用距离场AO以及距离场阴影。这个方法性能消耗较大用了曲面细分以及置换虽然会有很好的效果但如果你对性能优化以及场景的把控不足还是不建议使用。
材质实现https://blueprintue.com/blueprint/bqo9vg8i/
## Runtime virtual texturing
实时虚拟贴图RVT这个文档上都有就不翻译了。
材质实现https://blueprintue.com/blueprint/md12pcb5/
## 另一个视频中的优化技巧
这里我再追加另一个Quiexl视频中的性能技巧
- 使用Ue4的MergeActor将多个Mesh进行合并。视频2:00
- 使用MegaScans的Ue4插件将多个材质合并到一起。视频2:50
具体操作请参考https://www.bilibili.com/video/BV1Zv41117xB/
{% raw %}
<iframe src="//player.bilibili.com/player.html?aid=244561268&bvid=BV1Zv41117xB&cid=233968254&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
{% endraw %}