BlueRoseNote/03-UnrealEngine/Rendering/RenderFeature/VirtualTexture学习笔记.md

56 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

---
title: VirtualTexture学习笔记
date: 2023-07-29 12:26:09
excerpt:
tags: VirtualTexture
rating: ⭐
---
# 前言
学习文章:
- https://zhuanlan.zhihu.com/p/138484024
**Streaming VT** = 显存优化,但需要额外消耗一些性能。
**Runtime VT** = 性能优化可以预先将材质缓存到一张巨大的虚拟RT上一般用于地形。
# VirtualTexture
## 1. Software Virtual Texture
在MegaTexture的基础上id Software进一步提出了Virtual Texture的概念这个概念取自于Virtual Memory,与虚拟内存类似的是一个很大的Texture将不会全部加载到内存中而是根据实际需求将需要的部分加载。与虚拟内存不同的是它不会阻塞执行可以使用更高的mipmap来暂时显示它对基于block的压缩贴图有很好的支持。 基本思路是会将纹理的mipmap chain分割为相同大小的tile或page,这里的纹理叫虚纹理,然后通过某种映射,映射到一张内存中存在的纹理,这里的纹理是物理纹理,在游戏视野发生变化的时候,一部分物理纹理会被替换出去,一部分物理纹理会被加载。
![](https://pic4.zhimg.com/80/v2-8dd6e9e7750884bbab8d6da5fe221ec3_720w.webp)
这样的机制不仅仅减少了带宽消耗和内存显存消耗也带来了其他好处比如有利于合批而不用因为使用不同的Texture而打断合批这样可以根据需求来组织几何使得更利于Culling当然合批的好处是states change 变少。LightMap也可以预计算到一张大的Virtual Texture上用来合批。
**其关键在于地址映射**,比如四叉树映射:
![](https://pic1.zhimg.com/80/v2-754fb67195882775cb95dcb1d2366ad8_720w.webp)
# RuntimeVirtualTexture
其主要目的是Cache材质计算结果。可以参考李文磊的视频
https://www.bilibili.com/video/BV1KK411L7Rg/?spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=d47c0bb42f9c72fd7d74562185cee290
使用步骤:
1. 创建RuntimeVirtualTexture、RuntimeVirtualTextureActor、Landscape资产。
2. 在RuntimeVirtualTextureActor指定RuntimeVirtualTexture与Landscape资产并且复制Landscape的Bound。
3. 在Landscape的RenderToVirtualTexture中指定RuntimeVirtualTexture资产。
4. 修改Landscape的材质分别添加VirtualTexture Input、Export节点。 顺便也可以修改VirtualTexturePassType某些需求只需要将结果渲染到VT中无需在MainPass中渲染
5. 此时Landscape的材质大概率显示不正确这时需要添加VirtualTextureOutputLevel来计算UV为了匹配非VT情况可以加入RuntimeVirtualTextureReplace节点进行判断。
# UDIMs Virtual Texture多象限虚拟贴图
https://docs.unrealengine.com/5.0/en-US/streaming-virtual-texturing-in-unreal-engine/
参看UDIM Support章节。大致的方法就是把多个贴图按照`BaseName.####.[Support Image Format]`进行命名,####代表了坐标。将这些贴图放到同一目录之后只需要导入1001坐标的贴图即可自动全部导入。
![image.png](https://cdn.jsdelivr.net/gh/blueroseslol/ImageBag@latest/ImageBag/Images/20230730210018.png)
工作流可以参考:
- https://www.youtube.com/watch?v=SkUW4JSYrEo
- https://www.youtube.com/watch?v=HhT9oEB7xks
# 其他
## 贴图优化
具体参看Managing the Texture Streaming Poolhttps://www.youtube.com/watch?v=uk3W8Zhahdg
大致步骤:
- 使用Tools - Audit - Statistics查看贴图占用显存以及场景中的使用数量。
- 通过ViewMode - OptimizationViewModes - RequiredTextureResolution 查看贴图在场景中所需要的占用比例是否合适。
- 使用批量编辑功能修改Texture资产的MaximumTextureSize到指定Mipmap层级的分辨率即可。
另一个种方式就是使用SVT。