Imagination PowerVR SDK Blog

Is there any way to compress `rbga` channel to single channel

pvrtextool

#1

For example,the texture is in rgba mode but what I need just alpha channel.
So I want to remove the data in rbg channels and just store the alpha data.
And then I can save the texture size to 1/3.

Is there any way to achieve this goal?
Thanks!


#2

Hi,

Yes, it is possible. If you are using PVRTexTool just re-compress the texture with an alpha-only format (Name: A 8). Alternatively you can do it programmatically, removing the three channels from the original data (converting from 32bit to 8bit). Load it to OpenGL ES with the GL_ALPHA flag.

Regards.

Carlos.


#3

Am I right?
./PVRTexToolCLI -f a8 -i example.png -o output.pvr


#4

Yes, that is correct.The format a8 will carry only the alpha channel in your png.

Regards.

Carlos.


#5

If you can modify your shaders, you can achieve even higher space savings if you

  1. Create an RGBA texture where each pixel is defined as [RGBA]=[A’, 0, 0, 255], where A’ is the original per-pixel alpha value
  2. Compress the texture as PVRTC with 4bpp (or even 2bpp if the quality ends up being good enough)
  3. Getting the fragment shader to transfer the R channel of the sampled result to the alpha channel.

Notes:

  • Actually, it doesn’t matter if you use [A’, 0, 0, 255], [A’, A’, 0, 255] or [0, A’, 0, 255], as long as it’s consistent . It’s just that the R and G channels in PVRTC have slightly more accuracy than B.
  • It is essential that the A be set to 255 as “opaque” data will compress slightly better (as it gives more precision to the RG&B channels)
  • It is important to keep B constant (and one of a small set of particular constants) - here I’ve chosen 0, but 255 would also do equally well.