圖片紋理壓縮方案


Unity支持多種圖像格式作為導入紋理的源文件(JPG,PNG,PSD,TGA),Unity會將它們轉換成自己支持的Texture2D格式,在Texture2D的選項設置中,針對不同平台和實際需求,選擇合適的壓縮格式,盡量減少圖片紋理的占用內存。

官方文檔給出了所有支持的紋理壓縮格式:官方文檔鏈接,選擇紋理壓縮格式是圖片內存大小與圖片質量之間的權衡。同時,要選擇平台支持的紋理壓縮格式,當使用目標平台不支持的紋理壓縮格式時,紋理將解壓縮為RGBA 32,並與壓縮的紋理一起存儲在內存中。發生這種情況時,會浪費時間對紋理進行解壓縮,並且浪費內存。此外,不同平台均具有不同的硬件,對特定的壓縮格式進行了優化,選擇不兼容的格式會影響游戲的性能。

Android平台下不帶透明通道優先使用ETC1,帶透明通道的優先使用ETC2,要求更高質量可使用RGBA16,RGBA32。IOS平台下優先使用PVRTC,其次是ASTC。要求更高質量可使用RGBA16,RGBA32。

圖片占用的內存越小,加載速度越快,游戲性能越好。但一些的壓縮格式對圖片的尺寸有一些限制。ETC1,ETC2以及ASTC4x4要求圖片的尺寸的寬和高可以不相等但必須被4整除;IOS的PVRTC壓縮格式要求圖片的寬高必須相等而且是2的整數次冪,否則無法壓縮。另外ETC2和ASTC對硬件也有一些限制,ETC2只支持OpenGL ES 3.0以上的Android手機,ASTC只支持蘋果A8以后的設備。這些都是在選擇壓縮格式要注意的事項。

下面的表格顯示了每種壓縮格式的支持平台。

Texture compression format Description Size
for a 256x256 pixel Texture
Platform Support
RGB Compressed DXT1 壓縮無符號整型整型RGB紋理。 32KB (4 bits per pixel) Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL

Note: With linear rendering on web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32.
RGB Crunched DXT1 類似於RGB壓縮DXT1,但使用壓縮壓縮壓縮。請參閱上面的注釋,了解更多關於壓縮壓縮的內容。 Variable, depending on the complexity of the content in the texture. Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL

Note: With linear rendering on a web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32.
RGBA Compressed DXT5 壓縮無符號整型整型RGBA紋理。每像素8位。 64KB (8 bits per pixel) Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL

Note: With linear rendering on a web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32.
RGBA Crunched DXT5 與RGBA壓縮DXT5相似,但使用壓縮壓縮壓縮。請參閱上面的注釋,了解更多關於壓縮壓縮的內容。 Variable, depending on the complexity of the content in the texture. Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL

Note: With linear rendering on a web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32.
RGB Compressed BC6H 壓縮無符號浮動/高動態范圍(HDR)RGB紋理。 64KB (8 bits per pixel) Windows Direct3D 11: OpenGL 4, Linux.

Note: BC6H Textures are uncompressed at run time to RGBA half on the following platform configurations:
- macOS with OpenGL
- Platforms with Direct3D 10 Shader Model 4 or OpenGL 3 GPUs.
RGB(A) Compressed BC7 高質量的壓縮無符號整型整型RGB或RGBA紋理。 64KB (8 bits per pixel) Windows Direct3D 11: OpenGL 4, Linux

Note: BC7 Textures are uncompressed at run time to RGBA 32bits on the following platform configurations:
- macOS with OpenGL
- Platforms with Direct3D 10 Shader Model 4
Platforms with OpenGL 3 GPUs.
RGB Compressed ETC 壓縮RGB紋理。這是一種默認的紋理壓縮格式,沒有Android項目的alpha通道。 32KB (4 bits per pixel) Android, iOS, tvOS.
Note: ETC1 is supported by all OpenGL ES 2.0 GPUs. It does not support alpha.
RGB Crunched ETC 類似於RGB壓縮等,但使用壓縮壓縮壓縮。請參閱上面的注釋,了解更多關於壓縮壓縮的內容。 Variable, depending on the complexity of the content in the texture. Android, iOS, tvOS.
RGB Compressed ETC2

壓縮RGB紋理。

32KB (4 bits per pixel) Android (OpenGL ES 3.0)
Note: On Android platforms that don’t support ETC2, the texture is uncompressed at run time to the format specified by ETC2 fallback in the Build Settings.
RGBA Compressed ETC2 壓縮RGBA紋理。這是用於Android項目的alpha通道紋理的默認紋理壓縮格式。 64KB (8 bits per pixel) Android (OpenGL ES 3.0), iOS (OpenGL ES 3.0), tvOS (OpenGL ES 3.0)

Note: On iOS and tvOS devices that don’t support ETC2, the texture is uncompressed at run time to RGBA32. On Android platforms that don’t support ETC2, the texture is uncompressed at run time to the format specified by ETC2 fallback in the Build Settings.
RGBA Crunched ETC2 類似於RGBA壓縮ETC2,但是使用壓縮壓縮壓縮。請參閱上面的注釋,了解更多關於壓縮壓縮的內容。 Variable, depending on the complexity of the content in the texture. Android (OpenGL ES 3.0), iOS (OpenGL ES 3.0), tvOS (OpenGL ES 3.0)

Note: On iOS and tvOS devices that don’t support ETC2, the texture is uncompressed at run time to RGBA32. On Android platforms that don’t support ETC2, the texture is uncompressed at run time to the format specified by ETC2 fallback in the Build Settings.
RGB Compressed ASTC 可變塊大小壓縮RGB紋理。 12x12: 0.89 bits per pixel (7.56KB for a 256x256 Texture)
10x10: 1.28 bits per pixel (10.56KB for a 256x256 Textures)
8x8: 2 bits per pixel (16KB for a 256x256 Texture);
6x6: 3.56 bits per pixel (28.89KB for a 256x256 Texture)
5x5: 5.12 bits per pixel (42.25KB for a 256x256 Texture)
4x4: 8 bits per pixel (64KB for a 256x256 Texture)
tvOS (all), iOS (A8), Android (PowerVR 6XT, Mali T600 series, Adreno 400 series, Tegra K1).
RGBA Compressed ASTC 可變塊大小壓縮RGBA紋理。 12x12: 0.89 bits per pixel (7744 bytes for a 256x256 Texture)
10x10: 1.28 bits per pixel (10816 bytes for a 256x256 Textures)
8x8: 2 bits per pixel (16KB for a 256x256 Texture);
6x6: 3.56 bits per pixel (29584 bytes for a 256x256 Texture)
5x5: 5.12 bits per pixel (43264 bytes for a 256x256 Texture)
4x4: 8 bits per pixel (64KB for a 256x256 Texture)
tvOS (all), iOS (A8), Android (PowerVR 6XT, Mali T600 series, Adreno 400 series, Tegra K1).
RGB Compressed PVRTC 2 bits 高壓縮RGB紋理。質量低,但尺寸小,性能更佳。 16KB (2 bits per pixel) Android (PowerVR), iOS, tvOS.
RGBA Compressed PVRTC 2 bits 高壓縮RGBA紋理。質量低,但尺寸小,性能更佳。 16KB (2 bits per pixel) Android (PowerVR), iOS, tvOS.
RGB Compressed PVRTC 4 bits 壓縮RGB紋理。高質量的紋理,特別是在顏色數據上,但是需要很長時間來壓縮。 32KB (4 bits per pixel) Android (PowerVR), iOS, tvOS.
RGBA Compressed PVRTC 4 bits 壓縮RGB紋理。高質量的紋理,特別是在顏色數據上,但是需要很長時間來壓縮。 32KB (4 bits per pixel) Android (PowerVR), iOS, tvOS.
RGB Compressed ATC

壓縮RGB紋理。

32KB (4 bits per pixel) Android (Qualcomm - Adreno), iOS, tvOS.
RGBA Compressed ATC

壓縮RGBA紋理。

64KB (8 bits per pixel) Android (Qualcomm - Adreno), iOS, tvOS.
RGB 16 bit

65萬種沒有阿爾法的顏色。使用比壓縮格式更多的內存,但是更適合於UI

或者沒有漸變的脆紋理。

128KB (16 bits per pixel) All platforms.
RGB 24 bit 真正的顏色,但沒有alpha。 192KB (24 bits per pixel) All platforms
Alpha 8 高質量的alpha通道,但沒有任何顏色。 64KB (8 bits per pixel) All platforms.
RGBA 16 bit 低質量的真實顏色。這是具有alpha通道的紋理的默認壓縮。 128KB (16 bits per pixel) All platforms.
RGBA 32 bit 真正的顏色和alpha。這是具有alpha通道的紋理的最高質量壓縮。 256KB (32 bits per pixel) All platforms.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM