2D Toolkit Forum

2D Toolkit => Support => Topic started by: m4ko on March 27, 2013, 02:39:16 pm

Title: Compression
Post by: m4ko on March 27, 2013, 02:39:16 pm
Hello,

I have a question regarding atlas compression. Why does compression like DXT5 and PVRTC produce such horrific results?

The number is a textmesh on top of a normal tk2dsprite. The tk2dsprite is shown once compressed and uncompressed. The size is the same.

Compressed. Black dots
(http://s4.postimg.org/nsl183w7d/dxt5.png) (http://postimg.org/image/nsl183w7d/)

Uncompressed
(http://s4.postimg.org/kn0fhwdl5/no_dxt5.png) (http://postimg.org/image/kn0fhwdl5/)

Info about the PNG:
The source looks like the uncompressed image. There is only alpha blending on the outer edge of the yellow ring. The green center and the yellow ring on the inside are solid. In the atlas texture this looks crispy and perfect.

Texture:
filter mode - point
no mip maps
Texture Type Advanced / no power 2
compression DXT5 / PVRTC4 (same results)


Any idea why compression places black/dark grey dots in the image? I don't mind losing detail... but getting artifacts like this is unacceptable. How do I need to handle this to get proper results?
Title: Re: Compression
Post by: MaaS on March 27, 2013, 02:46:18 pm
There is only alpha blending on the outer edge of the yellow ring. The green center and the yellow ring on the inside are solid.

Are you sure there is not alpha blending between the yellow ring and the green center? It seems so... but honestly, PVRTC is the worst looking thing ever :P
Title: Re: Compression
Post by: m4ko on March 27, 2013, 02:52:08 pm
I just double checked with out graphics artist. He showed me the alpha. There is nothing on the inner ring. It's a perfect white circle with blended edges on the outside.
Title: Re: Compression
Post by: unikronsoftware on March 27, 2013, 05:56:10 pm
DXT & PVRTC should produce pretty different results. First thing to do is open up the sprite collection atlas texture in Photoshop and look and make sure there isn't any alpha change / black dot on the inside. Its unlikely but its worth looking at just to make sure.

I take it the sprite in your image is just the green button and doesn't include the background? If so, my prime suspect would be the background outside the white outline. Are you using premultiplied alpha by any chance?

Now, with PVRTC / DXT - Unity doesn't let you choose your compressor, but you can use your own compressed textures if you want. What I'm saying is you could load the png into ATI Compressenator / NVDXT for DXTC and PVRTEXTOOL to save out an appropriate compressed file. With these tools you can fiddle with compression parameters to try and get a bit better quality out of it. Save them out as a .pvr for PVRTC (dds for DXT) into your Unity project and override the material with it.
This is a manual process and you'd have to do it every time the sprite collection changed, but its a viable option nonetheless.

ps - I can explain why DXT looks so horrible sometimes. It works in 4x4 blocks of pixels, evenly divided from the start of your texture. (0, 0 = first block, 0, 4 = second block and so on). Each 4x4 block gets 2 16 bit colors (565) and 2 colors interpolated between these 2 colors. Each pixel in the 4x4 block can be one of these 4 colors. As you can imagine this really limits what kind of colors you can have in a 4x4 block. A sure fire way to break DXT horribly is to have a 4x4 block with different primary colors in there.



Title: Re: Compression
Post by: m4ko on March 28, 2013, 08:07:06 am
Thank you unikron. It's always a pleasure to read your technically profound and detailed posts.

And you are right. We export our sprites from Photoshop CS6 as PNGs with premultiplied alpha. Even though there is no irregularity in the spots where the black dots pop up this somehow causes them. We now export as TIF with seperate alpha channel. The result looks much better. There is still a dark shade in one corner but at normal resolution it's barely visible. I wonder if TIFs are the way to go. If someone has another recommendation on how to export from photoshop post here.

Thanks again.