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

36 lines
2.4 KiB
Markdown
Raw 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
使用步骤:
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节点进行判断。