# 纹理图集

纹理图集将大量较小的图像打包进一张大图，其中每张小图通过纹理坐标单独寻址。在实时图形中，图集的存在主要是为了减少渲染器发出的纹理绑定和绘制调用次数：引擎无需为每个对象绑定单独的纹理，而是绑定一张图集纹理，并对其中相应的子区域进行采样。<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 一张包含许多较小子图像的大图，每个子图像通过坐标重映射表独立引用<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup><sup> • </sup><sup>[2](https://www.gamedeveloper.com/programming/practical-texture-atlases)</sup> |
| 主要优势 | 减少纹理绑定和绘制调用，降低光栅化过程中因切换纹理而产生的管线开销<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup> |
| 运行时开销 | 顶点着色器中每组纹理坐标一次二维乘加运算，外加一个float4常量寄存器，在大多数场景中可忽略不计<sup>[2](https://www.gamedeveloper.com/programming/practical-texture-atlases)</sup> |
| 打包难度 | 纹理打包是装箱问题的一种形式，已被证明为NP难问题<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup> |
| 下载节省 | 一个DDS文件携带约128字节的文件头；2000个散装纹理文件会额外增加约250KB的纯文件头开销，打包进图集即可消除<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup> |
| 已知局限 | 图集与多级渐远纹理结合使用时，除非对图块进行填充或限制过滤方式，否则会导致子图像之间的纹理渗色<sup>[3](https://gamedev.stackexchange.com/questions/46963/how-to-avoid-texture-bleeding-in-a-texture-atlas)</sup> |
| 现代替代方案 | 数组纹理将多个同尺寸层存储在一张纹理中，避免了一些图集问题，但需要着色器来访问它们<sup>[4](https://wikis.khronos.org/opengl/Array_Texture)</sup> |

## 目的与历史

图集随3D游戏而兴起，在光栅化过程中切换或引用新纹理会带来显著开销。将较小纹理合并为一张较大的纹理，意味着图形管线只需绑定一张纹理，或较少数量的纹理，从而消除切换带来的额外成本。《雷神之锤2》中使用的原始光照图之一便是该技术的早期实例。<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup>

这一优势同样适用于2D和网页游戏。在由许多独立图像元素构建的HTML5游戏中，游戏开发中使用的每种文件格式都携带随文件传输的文件头数据，无论其内容如何。DDS文件通常用于DirectX压缩纹理，其文件头约为128字节；2000个散装纹理文件——对于大型游戏来说并不罕见——每个用户需多传输约250KB。将纹理打包进单张图集即可消除这一冗余开销。<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup>

**运行时如何使用图集。** 引擎构建一张坐标重映射表，将每个原始纹理文件名绑定到图集文件名加重映射坐标，并与图集纹理一同加载。当逻辑纹理被分配给采样器时，纹理管理器改为加载物理图集，并将缩放和偏移对传入一个预留的顶点着色器常量寄存器；顶点着色器对每组纹理坐标应用简单的重映射。实测运行时开销为每组纹理坐标一次二维乘加运算外加一个float4寄存器，这很少成为瓶颈，此外当纹理未完全填满最后一张图集时，还会有一小部分图集空间被浪费。<sup>[2](https://www.gamedeveloper.com/programming/practical-texture-atlases)</sup>

第三个集成点是渲染队列，它按每个逻辑纹理的物理图集ID对绘制调用进行排序。在典型的排序顺序中，图集ID比较排在材质之后，因为着色器切换比纹理切换开销更大；排在距相机距离之前，以便共享着色器和图集的对象从前到后绘制。<sup>[2](https://www.gamedeveloper.com/programming/practical-texture-atlases)</sup>

## 打包算法与工具

决定如何在图集内排列子图像是一个装箱问题，已被证明为NP难问题；其难度之大，以至于一位谷歌开发者布道师曾将该算法的一个变体用作面试题。TexturePacker等现成打包工具可生成图集图像以及一份将每张源图像映射到其最终位置的数据文件。<sup>[1](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)</sup>

生产管线将整个过程自动化。Haemimont Games的伊万-阿森·伊万诺夫（Ivan-Assen Ivanov）所描述的美术管线使用NVIDIA的图集创建工具和NVDXT压缩工具，以美术资源的目录树和配置文件为输入，输出压缩的DDS纹理以及一张重映射表。该工具以不同配置对同一批资源运行三次，为三个纹理质量级别生成图集组：低细节面向64MB显卡，中细节面向128MB，高细节面向256MB。以文件内容和设置的MD5哈希为键的压缩缓存使构建中典型的图集创建部分耗时约2到3分钟，而使用相同设置压缩的相同纹理会以别名形式写入重映射表，以节省纹理内存。<sup>[2](https://www.gamedeveloper.com/programming/practical-texture-atlases)</sup>

## 引擎支持

**Unity。** Unity的Sprite Atlas资源会打包被分配到其“打包对象”列表中的精灵、纹理或文件夹；当前格式使用`.spriteatlasv2`文件扩展名，Unity默认不再使用V1格式。打包选项包括：紧密打包（Tight Packing），使用精灵的网格轮廓而非整张纹理矩形来减少每个精灵周围的透明像素；允许旋转（Allow Rotation），尝试旋转精灵以获得更好的排布；填充（Padding），打包精灵之间的空白像素数；以及Alpha膨胀（Alpha Dilation），将填充像素的alpha设为0。主图集（Master）持有被分配的对象，而变体（Variant）是主图集的缩小版本，用于面向不同尺寸的目标平台。如果某个精灵被添加到多个图集中，Unity在运行时会随机选择使用哪张图集纹理，因此建议手动加载以避免这种情况。<sup>[5](https://docs.unity.com/en-us/engine/6000.0/manual/unity2d/sprite/atlas/create-sprite-atlas)</sup><sup> • </sup><sup>[6](https://learn.unity.com/tutorial/introduction-to-the-sprite-atlas-2019-3?version=2019.4)</sup><sup> • </sup><sup>[7](https://docs.unity.com/en-us/engine/6000.5/script-reference/unityeditor/u2d/spriteatlaspackingsettings)</sup>

Unity的打包器不保证最优结果。按设计，SpriteAtlas使用最佳适配与随机适配的组合来平衡最优性与打包速度，因此并非所有情况下都能实现完美打包；Unity针对一份次优打包缺陷报告的解释说明指引开发者使用ScriptablePacker API进行自定义打包。<sup>[8](https://issuetracker.unity.com/issues/17638/sprite-atlas-results-in-suboptimal-packing-even-when-allow-rotation-is-enabled)</sup>

**Apple SpriteKit。** 在SpriteKit中，SKTextureAtlas类通过减少绘制调用来改善内存使用和渲染性能。创建图集的首选位置是资源目录内，不过源纹理也可以放在应用包中的`.atlas`文件夹内。<sup>[9](https://developer.apple.com/documentation/spritekit/sktextureatlas?changes=_1&language=objc)</sup>

## 局限：渗色与多级渐远纹理

图集最著名的技术问题是纹理渗色，即采样时从相邻子图像中拾取颜色。简单地将图集与多级渐远纹理混用会导致渗色，除非所有子纹理都恰好为1×1像素，因为低级别的多级渐远纹理会将相邻图块混合在一起；一条常见的经验法则是：2D图集内容应避免使用多级渐远纹理，而多级渐远3D内容应避免使用图集。<sup>[3](https://gamedev.stackexchange.com/questions/46963/how-to-avoid-texture-bleeding-in-a-texture-atlas)</sup>

**数组纹理作为替代方案。** 纹理切换的高昂成本使图集广受青睐，但数组纹理——自3.0版本起成为OpenGL的核心功能——将多个同尺寸纹理数据层存储在一张纹理中，避免了图集的一些问题，例如渗色以及每个图块的多级渐远纹理和环绕行为被破坏。

## 图集在当今的定位

如Unity和SpriteKit的支持所示，图集仍然是2D引擎和精灵工作流中减少绘制调用的标准工具。在3D内容创作中，同样的思路以材质图集的形式出现，即将多张纹理合并，使多材质对象能够以统一的材质设置和更少的绘制调用进行绘制。<sup>[5](https://docs.unity.com/en-us/engine/6000.0/manual/unity2d/sprite/atlas/create-sprite-atlas)</sup><sup> • </sup><sup>[9](https://developer.apple.com/documentation/spritekit/sktextureatlas?changes=_1&language=objc)</sup><sup> • </sup><sup>[11](https://www.youtube.com/watch?v=ncwW5KNQ1Eg)</sup> NVIDIA于2004年发布的关于通过纹理图集进行批处理的白皮书将该技术定位为减少批次数的一种工具，并回应了图集降低图像质量的看法，通过Atlas Comparison Viewer演示了在避免常见陷阱的情况下这实为一种误解。<sup>[12](https://download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf)</sup>

## References

1. [Building an HTML5 game? Don't shrug off atlases (Colt McAnlis, Game Developer, 2012)](https://www.gamedeveloper.com/programming/building-an-html5-game-don-t-shrug-off-atlases)
2. [Practical Texture Atlases (Ivan-Assen Ivanov, Haemimont Games, Game Developer, 2006)](https://www.gamedeveloper.com/programming/practical-texture-atlases)
3. [How to avoid texture bleeding in a texture atlas? Game Development Stack Exchange](https://gamedev.stackexchange.com/questions/46963/how-to-avoid-texture-bleeding-in-a-texture-atlas)
4. [Array Texture, OpenGL Wiki, Khronos Group](https://wikis.khronos.org/opengl/Array_Texture)
5. [Create a sprite atlas, Unity Editor documentation](https://docs.unity.com/en-us/engine/6000.0/manual/unity2d/sprite/atlas/create-sprite-atlas)
6. [Introduction to the Sprite Atlas, Unity Learn](https://learn.unity.com/tutorial/introduction-to-the-sprite-atlas-2019-3?version=2019.4)
7. [SpriteAtlasPackingSettings, Unity Script Reference](https://docs.unity.com/en-us/engine/6000.5/script-reference/unityeditor/u2d/spriteatlaspackingsettings)
8. [Unity Issue Tracker: Sprite Atlas results in suboptimal packing even when "Allow Rotation" is enabled](https://issuetracker.unity.com/issues/17638/sprite-atlas-results-in-suboptimal-packing-even-when-allow-rotation-is-enabled)
9. [SKTextureAtlas, Apple Developer Documentation](https://developer.apple.com/documentation/spritekit/sktextureatlas?changes=_1&language=objc)
10. [Bleeding edges when artificially zooming in on texture atlas in the shaders, Khronos Forums](https://community.khronos.org/t/bleeding-edges-when-artifically-zooming-in-on-texture-atlas-in-the-shaders/77241)
11. [Reducing Draw Calls in Unreal (PrismaticaDev, 2022)](https://www.youtube.com/watch?v=ncwW5KNQ1Eg)
12. [Improved Batching via Texture Atlases, NVIDIA whitepaper (2004)](https://download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf)

---
*Initially written Oct 15, 2026*

Topic: 体育、游戏与休闲 › 电子游戏与数字游戏 › 游戏产业 › 开发与技术 › 图形与渲染技术

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/texture-atlas

English original: https://www.edgepedia.org/texture-atlas
