ARM-software / astc-encoder

The Arm ASTC Encoder, a compressor for the Adaptive Scalable Texture Compression data format.
https://developer.arm.com/graphics
Apache License 2.0
1.07k stars 239 forks source link

The alpha channel is painted black during compression #464

Closed matsuzaki215 closed 6 months ago

matsuzaki215 commented 6 months ago

The transparent areas are blacked out, when an image with transparent areas (sample.png) is compressed with the following command. How can I solve this problem?

# add -yflip option because the image was inverted in my environment.
$ astcenc -cs sample.png sample.astc 6x6 -medium -yflip

The following images are comparing images before and after conversion on Unity. ※ Sry, If this is a problem with the Unity settings.

original image (png)

original image (png)

encoded image (astc)

encoded image

solidpixel commented 6 months ago

I don't think this is a compressor problem (or at least, if it was, it no longer reproduces with the latest release). What version of the compressor are you using? Can you share the input texture and the generated output astc file?

Decompressing with the command line seems to give the right result on a transparent PNG I have locally:

./astcenc-avx2 -cs repro.png out.astc 6x6 -medium -yflip
./astcenc-avx2 -ds out.astc out.png
solidpixel commented 6 months ago

In Unity when you import the texture what is the "Alpha Source" option set to in the import settings? I think that needs to be set to "Input Texture Alpha", with the "Alpha Is Transparency" option ticked.

matsuzaki215 commented 6 months ago

@solidpixel Thank you for your reply.

What version of the compressor are you using?

I built astcenc from source code at main branch so its maybe latest version.

Can you share the input texture and the generated output astc file?

Sorry I can't attach astc file to github comment here.

In Unity when you import the texture what is the "Alpha Source" option set to in the import settings? I think that needs to be set to "Input Texture Alpha", with the "Alpha Is Transparency" option ticked.

When I import astc file to Unity, that setting "Alpha Is Transparency" is not available. sc

When I import original png, "Alpha Is Transparency" is available. sc2

matsuzaki215 commented 6 months ago

@solidpixel

As you pointed out, the "Alpha Is Transparency" setting seems to toggle between transparent and black in Unity. However, it appears that the setting is not available when the astc image is loaded.

Please wait a little while before trying to check via the application in production, and if it is transparent I will close this issue.

solidpixel commented 6 months ago

A local check would be to decompress the .astc image back to a .png with the command line tool (i.e. astcenc -ds ...). If that's transparent then this is definitely a Unity integration issue.

matsuzaki215 commented 6 months ago

@solidpixel

Solved!

I import the astc image into my application and confirmed that it is transparent without any problems. In other words, the Unity environment (the way it is shown) was the cause. Thank you for your supports!!

solidpixel commented 6 months ago

Great, thanks for confirming. Closing.