GPU Gems 2 · Chapter 12. Tile-Based Texture Mapping

用 Wang tiles、packed tile texture 和 index texture 在 fragment shader 中合成大虚拟纹理,保持原始 geometry/UV 不变并处理边缘过滤与 mipmap。

学习目标

  • 能解释大纹理的尺寸、存储和带宽限制,以及 tile-based mapping 的虚拟纹理思路
  • 能用 Wang tile 的 edge color 约束构建无缝、低重复的 tile set
  • 能实现 UV → index texture → packed tile texture 的两次 fragment lookup,并保留正确 derivatives
  • 能说明 lower-resolution mipmap 为什么会跨错 tile,以及 edge sanitization 如何缓解 seam 和 popping

大型墙面、地面和地形纹理同时受显存、加载带宽和单纹理尺寸上限约束。把输出规模与存储规模解耦:应用仍使用原始 geometry 和 UV,fragment shader 负责回答 texture request。

Small tile set → large virtual texturetile set少量输入纹理virtual texture大输出,重复少、可扩展
tile-based mapping 把大纹理的存储问题转成 shader 的两次查样:先查 tile 位置,再查 tile 内 texel。

1. Wang tiles 与 edge color

通过边界约束避免任意重复。两个 tile 共享边时,南北或东西 edge color 必须相同;只要匹配边上图案连续,硬件双线性过滤跨边采样也不会产生明显断裂。

是组合规则。tile set 可以手工绘制,也可以从自然纹理算法生成;关键是边缘连续和组合后具有足够的变化。

Wang tiles:边缘编码让拼接连续N / S / W / E edge IDs共享边颜色相同 → 连续 pattern
边缘颜色是约束而不是像素颜色;匹配的边经过连续图案设计后,硬件双线性过滤也能跨 tile。

2. Tile packing 与两次查样

将 tile 集合装入单张输入纹理,避免每块 tile 都绑定独立资源。对输出 UV 先缩放得到 virtual tile 坐标,再读取

Fragment lookup:index first, texel secondUV (s,t)scale by output tilestile coord + fracindex texturewhich tile?row / columnpacked tilefrac UVddx / ddy LOD一次 virtual sample 需要两次纹理查样,但节省大纹理存储
index texture 不需要 mipmap,因为它存的是离散 tile 行列;最终 tile 样本需要显式 derivatives 保持正确 LOD。

取出 tile 坐标后,用缩放 UV 的 fractional part 采样 packed tile 的局部 texel。最终查样要把 ddxddy 传给纹理函数,保证 LOD 依据 virtual texture 的尺度而不是 packed layout 的偶然邻接。

3. Mipmap 与过滤边界

是 tile-based mapping 的质量关键。直接自动生成 mipmap 会把物理相邻但虚拟不相邻的 tile 混起来;低层过滤 footprint 越大,错误越明显。

Mipmap:tile 的边界问题会在低分辨率放大naive mip错误跨 tile 过滤sanitized mip同色 edge 平均校正
高分辨率拼接连续不代表低 mip 合法;要让同色边在每层仍然匹配,可对边缘做统一平均。

实际可以只 sanitise edges,因为低分辨率自然纹理通常已经趋于均匀;若需要更严格连续性,也可以校正 corners,但会增加模糊。另一条边界是最高可用 mip level 受 packed tile 总尺寸限制,输出虚拟纹理再大也不能凭空获得未存储的超粗层。

4. 动手实验:组合、LOD 与连续性

增大 tile 网格,观察 virtual texture 变化;提高 mip level 并关闭 sanitization,观察 seam/popping 风险;切换 line-art 和 organic,思考为什么 tile construction 与 filtering 不能完全分开。

Tile-based texture 实验

观察小 tile set 如何合成大纹理,以及 mipmap sanitation 对边缘连续性的影响。

virtual texture · organic · mip 1edge colors sanitized · filter continuoustiles 4×4 · effective regions 4×4

共享 edge color 的 tile 在低 mip 仍保持合法连接。

小结

  • tile-based texture mapping 用少量 tile 合成大 virtual texture,避免单纹理尺寸和存储瓶颈。
  • Wang tiles 通过 matching edge color 获得非周期、连续的组合。
  • fragment shader 先查 index texture,再查 packed tile,并显式传 derivatives。
  • index 是离散 mapping,不应 mipmap 插值;颜色采样需要正确的 virtual LOD。
  • mipmap sanitization 让低层 edge 仍合法,但会在连续性、模糊和成本之间折中。

练习

问题 1|两次查样 为什么 tile-based mapping 需要 index texture 和 packed tile texture 两次 lookup?

问题 2|边缘匹配 Wang tile 的 edge color 为什么能帮助硬件双线性过滤跨 tile?

问题 3|mipmap 为什么 packed texture 的自动 mipmap 会在 virtual texture 中产生错误 seam?

名词解释

本章出现的专业名词,用大白话再讲一遍。

virtual texture
由少量 tile 在运行时合成、对应用呈现为大纹理的输出。
Wang tiles
通过共享边编码约束组合连续性的方形 tile 集合。
edge color
描述相邻 Wang tile 边界兼容关系的离散标识。
tile packing
把多个输入 tile 放进单张 packed texture 的布局。
index texture
记录每个输出区域对应 packed tile 坐标的离散纹理。
mipmap sanitization
按 edge color 校正低分辨率 tile 边缘的过程。

资料与写作方式声明

本章以GPU Gems 2 · Chapter 12. Tile-Based Texture Mapping权威目录界定学习范围,并结合正文列出的技术资料独立重写;不宣称复现原书正文,也不沿用原作表述。

原作版权归作者与出版社所有;本站原创教学结构与表述仅供学习交流。

讨论

评论区加载中…