handcircus / Unity-Resource-Checker

Editor utility for unity to help check resources in the current scene (including active textures, their sizes, materials, meshes and which objects are using them)
1.02k stars 290 forks source link

Doesn't show texture size in Unity 2022. Не показывает размер текстур в Unity 2022 #35

Open AndreyAs44 opened 2 years ago

AndreyAs44 commented 2 years ago

Give feedback if you saw my message! Most likely, it's in the format that unity chooses by default. That is, if you change it to RGB32, then everything is displayed as it should, and this format does not seem to be supported.

Дайте обратную связь если увидели моё сообщение! Скорее всего дело в формате, который юнити выбирает по умолчанию. То есть если поменять на RGB32 то всё отображается как надо, а данный формат похоже не поддерживается.

image

AndreyAs44 commented 2 years ago

case TextureFormat.R8: return 8; case TextureFormat.R16: return 16; case TextureFormat.BC4: return 16; case TextureFormat.BC5: return 8; case TextureFormat.BC7: return 8; case TextureFormat.RFloat: return 32; case TextureFormat.RG16: return 16; case TextureFormat.RG32: return 32; case TextureFormat.RHalf: return 16; case TextureFormat.BC6H: return 8; case TextureFormat.RGB48: return 16; case TextureFormat.RGFloat: return 32; case TextureFormat.RGHalf: return 16; case TextureFormat.EAC_R: return 4; case TextureFormat.RGBA64: return 16; case TextureFormat.EAC_RG: return 4; case TextureFormat.RGBAFloat: return 32; case TextureFormat.RGBAHalf: return 16; case TextureFormat.ETC2_RGB: return 4; case TextureFormat.ETC2_RGBA1: return 4; case TextureFormat.ETC2_RGBA8: return 8; case TextureFormat.EAC_R_SIGNED: return 4; case TextureFormat.EAC_RG_SIGNED: return 8;

AndreyAs44 commented 2 years ago

int CheckIsBlock(TextureFormat format) { switch (format) { case TextureFormat.ASTC_HDR_4x4: return 16; case TextureFormat.ASTC_HDR_5x5: return 25; case TextureFormat.ASTC_HDR_6x6: return 36; case TextureFormat.ASTC_HDR_8x8: return 64; case TextureFormat.ASTC_HDR_10x10: return 100; case TextureFormat.ASTC_HDR_12x12: return 144; case TextureFormat.ASTC_4x4: return 16; case TextureFormat.ASTC_5x5: return 25; case TextureFormat.ASTC_6x6: return 36; case TextureFormat.ASTC_8x8: return 64; case TextureFormat.ASTC_10x10: return 100; case TextureFormat.ASTC_12x12: return 144; }

    return 0;
}
AndreyAs44 commented 2 years ago

int tWidth = tTexture.width; int tHeight = tTexture.height; if (tTexture is Texture2D) { Texture2D tTex2D = tTexture as Texture2D;

        if (CheckIsBlock(tTex2D.format) == 0)
        {
            int bitsPerPixel = GetBitsPerPixel(tTex2D.format);
            int mipMapCount = tTex2D.mipmapCount;
            int mipLevel = 1;
            int tSize = 0;
            while (mipLevel <= mipMapCount)
            {
                tSize += tWidth * tHeight * bitsPerPixel / 8;
                tWidth = tWidth / 2;
                tHeight = tHeight / 2;
                mipLevel++;
            }

            return tSize;
        }
        else
        {
            int bitsPerBlock = CheckIsBlock(tTex2D.format);
            int tSize = tWidth * tHeight / bitsPerBlock * 128 / 8;
            return tSize;
        }
    }
    if (tTexture is Texture2DArray)
    {
        Texture2DArray tTex2D = tTexture as Texture2DArray;

        if (CheckIsBlock(tTex2D.format) == 0)
        {
            int bitsPerPixel = GetBitsPerPixel(tTex2D.format);
            int mipMapCount = 10;
            int mipLevel = 1;
            int tSize = 0;
            while (mipLevel <= mipMapCount)
            {
                tSize += tWidth * tHeight * bitsPerPixel / 8;
                tWidth = tWidth / 2;
                tHeight = tHeight / 2;
                mipLevel++;
            }
            return tSize * ((Texture2DArray)tTex2D).depth;
        }
    }
    else
    {
        Texture2DArray tTex2D = tTexture as Texture2DArray;
        int bitsPerBlock = CheckIsBlock(tTex2D.format);
        int tSize = tWidth * tHeight / bitsPerBlock * 128 / 8;
        return tSize * ((Texture2DArray)tTex2D).depth;
    }
builder-main commented 9 months ago

Hi, this seems interesting, however could you try to clarify/synthesize your different posts ?

AndreyAs44 commented 9 months ago

Hi, I don't remember very well anymore, the problem was calculating the size of textures. In this case, the build was for android, ASTC texture formats (automatic most optimal choice of unity). For them, I manually added the counting function (in the existing code) based on my observations and approximate understanding of the documentation. The weight of the sprites practically reflected reality, although there were small discrepancies.