RaininSaga/UABEAfC

Texture (compression?) problem

Closed this issue · 3 comments

Hi,

I tried to export a Texture2D then reimport it.
It worked but the size of the AssetBundle increased.

Is it a known behavior / bug ?
Should I add some parameter to decompression / compression steps ?
Is it possible that potential 8bit color is replaced by some higher value in the process ?

Exemple

AssetBundle: item_icons (from Outward Game Definitive edition).
Texture2D: tex_men_iconItemLightBombAdvanced_v_icn
Unity Version 2020.3.26f1 (as stated from a parameter in each item_icons asset).
Size of the texture in bundle before re-import: 236 bytes
Size of the texture in bundle after re-import: 5524 bytes

1/ Show (before export/import)
parameter: "D:\Dev\Outward\Assets_Test_3\item_icons"

This is an assetbundle.
[0]   CAB-d95f7bc2c107810157a5d007e28b5c0a
[1]   CAB-d95f7bc2c107810157a5d007e28b5c0a.resS

CAB-d95f7bc2c107810157a5d007e28b5c0a
      ItemName   [Bundle/Name:FileId:PathId]                                       Byte            Type
--------------------------------------------------------------------------------------------------------
CAB-d95f7bc2c107810157a5d007e28b5c0a/tex_men_iconItemLightBombAdvanced_v_icn:0:9221070761432349770   236           Texture2D

2/ Export:
parameter: "D:\Dev\Outward\Assets_Test_3\item_icons" -export CAB-d95f7bc2c107810157a5d007e28b5c0a/tex_men_iconItemLightBombAdvanced_v_icn:0:9221070761432349770

3/ Import:
parameter: "D:\Dev\Outward\Assets_Test_3\item_icons" -import CAB-d95f7bc2c107810157a5d007e28b5c0a/tex_men_iconItemLightBombAdvanced_v_icn:0:9221070761432349770 "D:\Dev\Outward\Assets_Test_3\CAB-d95f7bc2c107810157a5d007e28b5c0a_tex_men_iconItemLightBombAdvanced_v_icn_0_9221070761432349770.png"

4/ Show (after export/import)
parameter: "D:\Dev\Outward\Assets_Test_3\item_icons"

This is an assetbundle.
[0]   CAB-d95f7bc2c107810157a5d007e28b5c0a
[1]   CAB-d95f7bc2c107810157a5d007e28b5c0a.resS

CAB-d95f7bc2c107810157a5d007e28b5c0a
      ItemName   [Bundle/Name:FileId:PathId]                                       Byte            Type
--------------------------------------------------------------------------------------------------------
CAB-d95f7bc2c107810157a5d007e28b5c0a/tex_men_iconItemLightBombAdvanced_v_icn:0:9221070761432349770   5524           Texture2D

Additional information:

When I try to export the texture its format is DXT1 both for vanilla and altered bundle.
I suspect the behavior (problem?) comes from AssetsTools.Net.

As you say, that's the part that's handled by AssetsTools.NET, and as I don't have a good understanding of its internal processing, I think it would be best to ask its creator, nesrak1.

That said, I think that since the .resS file exists in the assetbundle, the texture size of 236 bytes displayed in the first show command is not the size of the texture itself.
This is about the file structure of Unity asset bundles,

[0] CAB-d95f7bc2c107810157a5d007e28b5c0a
[1] CAB-d95f7bc2c107810157a5d007e28b5c0a.resS

The texture data itself is stored in [1].resS, and the texture asset in [0] only contains a reference link and a few parameters. It is about a few hundred bytes.
When you import a texture through AssetsTools.NET, the texture is integrated into the [0] asset (this is not an exact representation), and then when you look at the size in show command, the size of the texture itself is displayed.

By the way, have you ever looked at the exported texture (png) in an image viewer?
If it is really 236 bytes, it will be very small around 10 pixels, or a monochrome image such as black and white.

Thank you.
The exported png size is approx 12 K.
CAB-d95f7bc2c107810157a5d007e28b5c0a size is approx 1 689 K.
CAB-d95f7bc2c107810157a5d007e28b5c0a.resS size is approx 13 667 K.

If you feel like it:
I'm interested in what you mean by "the texture is integrated into the [0] asset (this is not an exact representation)"
I'm interested in understanding why there is texture format conversion in TexturePlugin.TextureEncoderDecoder and in AssetsTools.NET. Afaik, the format is a meta data stored and all format are handled by Unity so from my noob point of view it looks like avoidable complexity. Unity Source.

Meanwhile, I close the thread as you answered.

I'm interested in what you mean by "the texture is integrated into the [0] asset (this is not an exact representation)"

I don't understand it exactly, so I might be wrong.
The textures in CAB-d95f7bc2c107810157a5d007e28b5c0a only have a small amount of metadata, and the actual texture data is stored in CAB-d95f7bc2c107810157a5d007e28b5c0a.resS.
If you import any texture into CAB-d95f7bc2c107810157a5d007e28b5c0a, the data stored in resS will not be changed, instead the actual texture data will be embedded in the metadata section of CAB-d95f7bc2c107810157a5d007e28b5c0a.

I'm interested in understanding why there is texture format conversion in TexturePlugin.TextureEncoderDecoder and in AssetsTools.NET.

Please ask the author, nesrak1, for specifications.
I don't know if the texture format is converted or not, but from quick look at the code for TexturePlugin, it doesn't seem to support all formats, so that might be the cause.