alpha should not be multiplied

This poses a huge problem for game textures where RGB and A are often used for seperate functions,and the alpha channel is usually used for transparency, specular, glossiness…

With the current situation, the 4 channel are mixed together making it impossible to preserve the color or RGBchannels ( often referred as “color” or “diffuse”) and transparency Alpha channel which can represent glosiness,specularity or whatever the shader is utilizing the alpha channel for. These are 2 separate elements, how can I avoid the mixing thing, Unity does it properly with no hassle.



Plus, the only format that can contain transparency and the tool can read is PNG, and that doesn’t allow game developers to use the alpha channel for transparency, specular, glossiness at all. PNG has no alpha only transparency so it’s impossible to put information in the alpha channel (again, Alpha channel can be used for many things depending on the shader)

This why the tool should read TARGA format (not to mention EXR which is another topic for lightmaps and next gen hdr textures).



So how can I avoid the channel mixing issue and bypass the PNG transparency issue with your latest tool?

Err… What exactly is your problem? Who is multiplying your alpha and when? Are you getting greyscale images based on alpha channel?



What do you mean “4 channel are mixed together”? Do you want to create 2 textures out of a single image, i.e. one GL_RGB texture and one GL_ALPHA/GL_LUMINANCE/GL_INTESITY?



What kind of “tool can read … PNG” are you talking about, and what’s wrong with it? How are you using it?



"PNG has no alpha only transparency"

WHAT? What in your opinion is the difference between alpha and transparency? T = 1 - A?



Why PNG “doesn’t allow game developers to use the alpha channel for transparency, specular, glossiness at all”?



I’m totally lost.



I’ve been using PNG for years, and I don’t see anything wrong with it. If some function returns RGB premultiplied by A instead of returning RGBA - that’s most likely a bug in the function you are using. Also make sure you create RGBA textures, not RGB. In your shaders you should be able to access your texture colors without a problem:



vec4 color = texture2D(texture, texCoord);

float alpha = color.a;



Please clarify you question so that we can help you!



P.S. reading .TGA is like 10 lines of code - you only need to pay attention to possible RGB vs BGR layout problems.



Best regards,

Denis

Err... What exactly is your problem?

I can't use RGBA .pvr textures properly in Unity when outputting them from PVRTexTool.
Who is multiplying your alpha and when? Are you getting greyscale images based on alpha channel?



When importing the .pvr RGBA textures in Unity, every part of the texture where the Alpha value is not pure white (1) so black and grays, the color gets changed, as if the Alpha channel is affecting the RGB channels ,I don't know why this is actually happening and this what I mean by multiplying or channel mixing.



Do you want to create 2 textures out of a single image, i.e. one GL_RGB texture and one GL_ALPHA/GL_LUMINANCE/GL_INTESITY?



no, just a normal RGBA texture where the RGB color retain their values regardless of whats in the alpha channel.



What kind of "tool can read ... PNG" are you talking about, and what's wrong with it? How are you using it?




Your tool, the PVRTexTool can only read textures with alpha channel if they are PNG tetxures, doesn't read targa, PSD, and PNG is not a good format if you want visualize your alpha channel and know what what's happening there, as a grayscale canvas just like targa and psd, how can you paint and visualize a grayscale value in PNG for your reflective,glossy or specular map? you can't alpha is only used in PNG for transparency




"PNG has no alpha only transparency"
WHAT? What in your opinion is the difference between alpha and transparency? T = 1 - A?

Why PNG "doesn't allow game developers to use the alpha channel for transparency, specular, glossiness at all"?



PNG has transparency, disregard this point.

The Grayscale Alpha channel is not used only for transparency in Game engines and in 3D softwares, it can be used for a reflection map or a glosiness or a self illumination map....Take a reflective wood material for example with a RGBA pvr texture, the color is taken from the RGB and the reflectivity factor is taken from the A channel. With the current PNG format, you can only use alpha for transparency and not reflectiveness, because what if you had a part of the wood texture where it's totaly black in the alpha channel ( 0 reflectivity), the color well get affected automatically:


Here is the first part of the problem, working with PNG doesn't let you paint properly a grayscale alpha and when saved the color information are affected by PNG's alpha:
http://i.imgur.com/N7MG5H3.jpg


Second part of the problem, in Unity, the alpha gets mixed the color information, notice how the gray bench color is affected thus making work with .pvr texture inpossible:
http://i.imgur.com/TgnL3Gv.jpg







Royter I totally understand your problem and I have the same question.

We are not using Unity but an own framework and engine and it’s a shame that PVRTexTool can’t read TGA’s with an explicit Alpha Channel. We would need that for example to mask something in the alpha channel for a team color shader, where the RGB Channels get multiplied by the alpha with a different color.



Generall question: Does PVRTexTool will support TGA Files in the near future or is there any way to create a RGBA PVRTC 4bpp Texture out of PVRTexTool with explicit Alpha?

Hi,



TGA and EXR support are planned for PVRTexTool in a future release, but it’s not been added yet. In the meantime to do this, it is possible to use channel mixing to use a separate alpha and RGB texture, so if you export your other data as a seperate greyscale image, then mix it with PVRTexTool (rather than in your image editor) you’ll be able to have the alpha explicitly set as a normal channel.



As for the premultiplication in Unity… I’m afraid I have no idea on that one. Is this just a previewing issue, or is it actually affecting the render? Is this a texture with something other than transparency in the alpha channel? If so, maybe Unity is flagging it as “not transparency” for it’s own functions, but there’s no such info in the PVR file. Either way it’s probably worth asking on the Unity forums about this, because there’s nothing that a PVR file could be doing which would cause this.



Thanks,

Tobias

I’m going to pipe on on this because I understand the OPs problem here completely and some other useful points can be made here.



Currently, PVRTexTool has been thought out very one dimensionally, so you have the old “alpha is transparency” mindset ruling it’s design. This has forced me to create my own tool that takes the same command line parameters (at least the ones we use commonly) that takes Targa and PSD and some more options for channel selection/mixing etc. and our compile script passes these off to our command line tool, and the supported file formats to PVRTexToolCL. Our tool enables us to have any combination of layers (using PSD) in textures such as RGB, specular, gloss, glow etc which can be pulled from the source image and then massaged with the PVRTex library to power of two, premultiply and the desired format etc. into textures with RGBA channels representing whatever we want. This enables artists to make their layers in one image and the coders to multiplex desired layers into textures.



In the very least Targa would be a welcome supported format by many, so good to hear that’s on the cards.



PSD is obviously a format used by everyone - and with a little bit of work you can create textures based on their layers instead of the flattened image. This is insanely useful. Perhaps this could be added to the PVR TODO list? It sure is a time saver. If nothing else - something for tool coders to ruminate on.

Hi Mysticcoder,



Thanks for your input - yep I totally get that. Obviously there is the workaround of loading the alpha separately, but it is just that - a workaround. Targa support should be pretty straightforward, and I should be adding it as soon as I get a spare moment to add it.



PSD support is something that I’d love to add, it’s just a case of finding the time to write the file importing code, particularly as layers will complicate it somewhat :)… At the very least I could probably enable the GUI to load PSD files in the next release, as I believe that Qt supports PSD loading - however I’m not sure how/if it handles layers.



Anyway you’ve raised an interesting point about the layers, so I’ll certainly add that to my TODO list :slight_smile:



Thanks,

Tobias

Hello Tobias



About the psd bit,

i am using https://code.google.com/p/java-psd-library/ for parsing the psd and getting the png from it, it s really easy l:) should be not a big deal to have it in c++ but my side it s only use to generate 2d ui ( following the good advise of building UI (UI Example.Whitepaper.pdf )



regards

david guimard