【Unity性能优化】ASTC压缩格式(Android)

ASTC中ARM研发的一种贴图压缩格式,相对于PVRTC,ETC2他对贴图尺寸没有要求。

iOS端游戏开发逐渐从PRVTC转到了ASTC。iOS9(A8架构)(iphone6)开始支持ASTC压缩格式。

Android支持 OpenGL ES 3.1 和 Vulkan 设备。目前有约5%的Android尚不支持ASTC

可以通过下面函数判断是否支持ASTC格式

SystemInfo.SupportsTextureFormat(TextureFormat format)

foreach (TextureFormat textureFormat in Enum.GetValues(typeof(TextureFormat)))
{
    try
    {
        _sb.Append($"({textureFormat}):");
        _sb.AppendLine(SystemInfo.SupportsTextureFormat(textureFormat).ToString());
    }
    catch(Exception e)
    {
            _sb.AppendLine(e.ToString());
    }
}

 当某台android设备不支持ASTC面到用到ASTC格式的贴图时,会出现如下解压日志,解压后图片格式为RGBA32

WARNING: RGBA Compressed ASTC4X4 sRGB format is not supported, decompressing texture
WARNING: RGBA Compressed ASTC4X4 UNorm format is not supported, decompressing texture

特殊情况:

三星手机a02s SystemInfo.SupportsTextureFormat 判断结果为支持ASTC_RGB这一批(如:ASTC_RGB_8x8 = 51)而不支持ASTC_RGBA这一批(如ASTC_RGBA_8x8 = 57)。实际测试发现即使是支持带Alpha的ASTC贴图的,因为内存中的贴图大小并没有变大,同时日志中也没有看因不支持ASTC而解压的日志。

实际应用:

Android上当因ETC2达不到美术要求的精度,而又不希望用RGBA时,可以考虑用ETC2和ASTC两套贴图,在那些不支持ASTC的5%android上用ETC2的贴图。当然,如果这些贴图是引用加载的,那么实现起来会很麻烦。

猜你喜欢

转载自blog.csdn.net/PangNanGua/article/details/121421644