- Home /
Problems With Alpha Channels When Loading DXT5 Texture2D From PNG
I'm having a strange problem when loading pngs from disk as Texture2Ds in Unity. I want to load the images using DXT5 like so:
Texture2D texture = new Texture2D(2,2, TextureFormat.DXT5, false);
...
texture.LoadImage(buffer);
When I do this, some of the images appear as they normally do, meaning, the look like they look when I load them in an image editor. But other images appear red and washed out. It seems like there may be some channel mangling going on with the images but I comparing and image that works next to one that doesn't in any graphics editor yields no clue as to why some of the images are red.
If I load the images as ARGB32 then they all work fine but I see a performance degradation.
What could be causing the images to take on a red hue? Is this a problem that should be solved in my code or is it a problem saving the image files? The image files came from a number of different users who created them using whatever tools they had available but the images look perfectly fine in every editor I've tried. Any clues what's going on and how to fix it in my script?
This may not be the issue, but your "performance degradation" you're talking about could be $$anonymous$$ipmapping... if you want your textures to always be top quality no matter what, consider disabling $$anonymous$$ipmapping.
$$anonymous$$ipmapping was disabled for these images in the construction of the Texture2Ds.
Answer by fherbst · Jun 18, 2010 at 11:31 PM
Maybe use a Photoshop action (or FastStone or whatever) and overwrite all images with resaved ones? That could get rid of possible faults in whatever editors were used. Maybe the alpha is written differently by the external tools, interpreted in the correct way by image viewers, but not by Unity (things like premultiplied/non-premultiplied alphas in compositing).
The red-hued images themselves were lacking alpha channels so as part of our build process I added a script that adds the alpha channel and overwrites the original.
This is to Ben 2: Thank you very much for providing me with the answer. I have been having troubles with this all day, and for some reason I didn't stumble on your solution before now. It works perfectly. Have you ever reported a bug in this regard? I mean, compressing a .png texture should just work, no matter how it's saved... At the very least if it is created using the Texture2D.EncodeToPng function, provided by the API.
Anyways, thanks again!!!!!
I was facing the exact same problem here for three days now! Adding the alpha channel on Photoshop solved the problem, but I need to make sure that the application does this by itself.
Could you tell me how you did it via script?
Your answer
Follow this Question
Related Questions
How to Make a Character Flicker? 1 Answer
Need Help adding Main Color Property to a complicated Shader 1 Answer
unity png color bleeding 1 Answer
Vegetation Texture Error 1 Answer
Texture with alpha upon a color 0 Answers