The Unity Editor can import texture source files with a number of common formats, such as JPEG or PNG. However, GPUs do not use these formats at runtime; instead, they use different, specialized formats that are optimized for memory usage and speed of sampling operations.
您可以在纹理资源导入设置中为其配置纹理压缩格式。当您向项目添加纹理资源时,Unity 编辑器会自动为每个构建目标选择合适的压缩格式;但是,大多数平台都支持多种纹理压缩格式。
纹理压缩格式会影响加载时间、GPU 帧时间、内存使用、视觉质量、构建大小和压缩时间;因此,在更改此设置之前了解本主题非常重要。
本页包含以下信息:
有关纹理资源导入设置的一般信息,请参见纹理导入设置 。有关每个平台的推荐、默认和支持的纹理压缩格式的信息,请参阅各平台的推荐、默认和支持的纹理压缩格式。
每像素位数 (bpp) 表示单个纹理像素所需的存储量。Bpp 值越低的纹理在磁盘和内存中也越小。较低的 bpp 值也意味着 GPU 使用较少的内存带宽来读取纹理像素。GPU 内存带宽通常是帧率的瓶颈,因此纹理压缩有助于避免这一问题。
纹理资源的视觉质量越高,每像素的位数就越高;因此,这会增大构建大小、加载时间和运行时内存使用。在某种程度上,所有纹理压缩格式都是有损的。未压缩的纹理提供最高的质量,但它们的每像素位数也最高。不同的纹理压缩格式提供不同的折衷。
通常,为了获得最佳运行时性能和磁盘占用空间,对于大多数纹理资源,您应该选择目标设备支持的纹理压缩格式,并且实现所需的视觉质量的最小每像素位数。
当您将纹理用于特定目的时,您可以更改其个别设置。例如,如果您使用只有一个通道的纹理作为遮罩,您可以选择 BC4 格式,在减少文件大小的同时仍能保证质量。如果您将某些纹理用于实现像素精准的 UI,可以选择不压缩它们。
选择您的目标平台和设备支持的格式。当 Unity 加载的纹理具有设备不支持的压缩格式时,它会将纹理解压缩为该平台的默认未压缩格式,并将未压缩副本与原始压缩纹理一起存储在内存中。这会增加纹理加载时间并使用额外的内存。当 Unity 加载的纹理具有设备支持的压缩格式时,GPU 可以使用该数据而无需任何转换。
Crunch 是一种压缩格式,基于 DXT 或 ETC 压缩,通过提供额外的可变比特率压缩。当 Unity 加载一个经过 Crunch 压缩的纹理时,它会在 CPU 上将该纹理解压缩为 DXT 或 ETC,然后将 DXT 或 ETC 压缩纹理数据上传至 GPU。
Crunch 压缩有助于纹理在磁盘上使用尽可能少的空间,但对于运行时内存使用量没有影响。Crunch 纹理可能需要很长时间进行压缩,但在运行时的解压缩速度非常快。您可以调整 Crunch 压缩的有损程度,以在文件大小和质量之间取得平衡。
如果您特别关心构建的大小并且目标平台支持 Crunch,请考虑添加 Crunch 压缩。
有关纹理导入设置以及如何设置特定于平台的覆盖的一般信息,请参阅纹理导入设置。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.