贴图格式设置
Format
a) Automatic使用对应平台推荐贴图格式(比如: Android为ETC)。
b) RGB 24bit, RGBA 32bit, RGB 16bit等都是所有平台通用的贴图格式。
Use Crunch Compression
是否使用2次压缩,这个是有损压缩,只有ETC, ETC2, DXT1, DXT5才能进行2次压缩。勾选的话,还可以设置压缩品质。
Compression
a) None所有平台都是用RGBA 32bit
b) Low Quality
c) Normal Quality: PC为RGBA Compressed DXT5, iOS为RGBA Compressed PVRTC 4bits, Android为RGBA Compressed ETC2 8bits
d) High Quality: PC为RGB(A) Compressed BC7, iOS为RGBA Compressed PVRTC 4bits, Android为RGBA Compressed ETC2 8bits
各个平台特有贴图格式
pc平台的DXT1和DXT2
iOS的PVRTC和ASTC
Android的ETC1和ETC2
勾上Crunch把品质设为90
PC的DXT5和DXT1支持2次压缩
iOS的PVRTC和ASTC都不支持2次压缩
Android的ETC和ETC2支持2次压缩
关于是否要使用Crunch?
a) 二次压缩是有损压缩,有可能让图片变得很糊或者让渐变图片显示异常。
b) 压缩后文件大小变小,文件很多的情况下可以降低游戏包体大小。文件变小了,磁盘io就少了,加载速度就变快了。
c) 运行时内存大小没有影响
所以,如果没有肉眼可见的画面变糊变差等情况,就可以使用。
非Crunch时的压缩品质
1) DXT1和DXT5不支持
2) iOS的PVRTC和ASTC支持,Fast对应compressionQuality为0,Normal对应50,Best对应100
3) Android的ETC和ETC2支持
Android平台的Alpha通道分离
使用一张RGB ETC图片+Alpha8图片来实现透明度,需要配置Unity内置的shader UI/DefaultETC1
打印设置的代码
public static void PrintSettingsInfo(TextureImporterPlatformSettings settings) { Debug.Log($"========== name: {settings.name}"); switch (settings.name) { case "DefaultTexturePlatform": Debug.Log($"maxSize: {settings.maxTextureSize}"); Debug.Log($"resize: {settings.resizeAlgorithm}"); Debug.Log($"format: {settings.format}"); Debug.Log($"compression: {settings.textureCompression}"); Debug.Log($"crunch: {settings.crunchedCompression}"); Debug.Log($"crunchQuality: {settings.compressionQuality}"); break; case "Standalone": Debug.Log($"maxSize: {settings.maxTextureSize}"); Debug.Log($"resize: {settings.resizeAlgorithm}"); Debug.Log($"format: {settings.format}"); Debug.Log($"crunchQuality: {settings.compressionQuality}"); break; case "Android": Debug.Log($"maxSize: {settings.maxTextureSize}"); Debug.Log($"resize: {settings.resizeAlgorithm}"); Debug.Log($"format: {settings.format}"); Debug.Log($"crunchQuality: {settings.compressionQuality}"); Debug.Log($"splitAlpha: {settings.allowsAlphaSplitting}"); Debug.Log($"etc2Fallback: {settings.androidETC2FallbackOverride}"); break; case "iPhone": Debug.Log($"maxSize: {settings.maxTextureSize}"); Debug.Log($"resize: {settings.resizeAlgorithm}"); Debug.Log($"format: {settings.format}"); Debug.Log($"crunchQuality: {settings.compressionQuality}"); break; } Debug.Log($"=========="); } var texImporter = (TextureImporter)AssetImporter.GetAtPath("xxxxx"); PrintSettingsInfo(texImporter.GetDefaultPlatformTextureSettings()); PrintSettingsInfo(texImporter.GetPlatformTextureSettings("Standalone")); PrintSettingsInfo(texImporter.GetPlatformTextureSettings("iPhone")); PrintSettingsInfo(texImporter.GetPlatformTextureSettings("Android"));
常见平台贴图格式设置推荐
PC
不透明图片: RGB Compressed DXT1(3通道共4bits)或RGB Compressed BC7(3通道8bits)
透明图片: RGBA Compressed DXT5(4通道共8bits)或RGBA Compressed BC7(4通道共8bits)
Android - OpenGL ES 2
不透明图片: RGB Compressed ETC 4bits, 3个通道共4bits
透明图片: RGBA 16bits, 每个通道4bits; 或者做alpha分离RGB Compressed ETC 4bits + Alpha8
Android - OpenGL ES 3
不透明图片: RGB Compressed ETC2 4bits, 3个通道共4bits, RGB444则是12bits
透明图片: RGBA Compressed ETC2 8bits, 4个通道共8bits, 多的4bits是用于alpha通道的? RGBA4444则是16bits
iOS - Open GL ES 2
不透明图片: RGB Compressed PVRTC 4bits
透明图片: RGBA Compressed PVRTC 4bits, 4个通道共4bits质量会比较差,
推荐做alpha分离: RGB Compressed PVRTC 4bits+RGB Compressed PVRTC 4bits或Alpha8
iOS - Open GL ES 3
不透明图片: RGB Compressed ASTC xx block, xx可以看作质量, 越大质量越差, 内存占用越小, 4x4为8bits, 8x8为2bits
透明图片: RGBA Compressed ASTC xx block
参考
ios x系列手机图片压缩失真_ASTC纹理压缩格式详解_清枫破的博客-CSDN博客, astc对比以及如何选看这个
Unity iOS 使用 ASTC 格式纹理实践_富贵吧的技术博客_51CTO博客
Unity Android平台中如何取舍ASTC ECT2格式纹理 - 简书 (jianshu.io)
Unity-特定于平台的覆盖的纹理压缩格式 - 哔哩哔哩 (bilibili.com)