- Home /
32 bit color in texture file
I need to store 32-bit color in a texture map. I know Unity can support such textures, but I can't seem to find a Unity-supported file type that can hold 32-bit color with a lossless compression. I've been using TIFF for everything, but if I save a 32-bit TIFF I get a complaint from Unity saying it can't be read. Anyone know a file type that I can use?
EDIT: I should clarify a bit. I'm not using PNG or TGA because I lose data when saving from Blender and loading in Unity. For example, if my image has a very low alpha, the original color value is replaced by pure white for unknown reasons. I have verified that it's not fixed by changing import settings.
Strange, i've seen no data loss when using PNG or TGA with 8 bits per channel = 32bits in total. If you need more precision, I think you can use the EXR file format that supports more bit depth per channel or floating point format (Unity uses this for some lightmaps it computes)
The plain white issue has nothing to do with a limitation of the file format but the behaviour of the exporter. $$anonymous$$ost exporter replace the colors of completely transparent pixels by a solid color (usually white or black) to improve compression quality. From a pure picture point of view it makes sense since those pixels can't be seen at all as they are transparent. However from a general purpose point of view it's an annoying problem. Though changing to a different file format usually won't fix it if the exporter does the same "optimisation". There are only a few programs which actually preserve the color information of transparent pixels. Even Photoshop "suffers" from that "feature".
edit
just to get this straight: By 32bit color you mean "bits per pixel" and not bits per channel, right?
Well, I did mean "bits per pixel", but it would be awesome if I could have more. I'm not trying to use this data for rendering, but for a compute shader, and I could use all the data I can get. If I could somehow manage something closer to 64 bits per pixel (16 bits per channel) that would be ideal.
As things stand, I think I am stuck making my own file format, a custom exporter for Blender, and using some kind of post-build script to use the data at runtime. Image files just don't hold enough.
Edit: If I could hold a full float per pixel, which I believe are 4 full bytes, I could simplify my entire system to the point where I only need one single channel. So a 32-bit single-channel texture would solve it all.
I see that blender can save to EXR with 16 bits per channel half-floats (http://blender-manual-i18n.readthedocs.io/ja/latest/data_system/files/formats/openexr.html) but i'm less sure Unity can read them as 16bit/channel texture (didn't try, just some quick search). So it might be quicker to use your own format if you can export it from Blender. Unity-side, you can read the file and saves it as a Texture2D Asset (Texture2D supports more formats than it can import + save using AssetDatabase). You can even automate this using EditorApplication.projectWindowChanged (did this to generate custom 3D textures assets)
I tried that since posting the question, but it doesn't integrate very well. It ends up having to read the file from a .asset file based on my own file format, but I can't seem to make that .asset hold a two-dimensional float array. That's why I figured I should just have a script run after the build that can copy my custom file into the build directory, read it at runtime, and go from there. That does cause problems with the editor though because I can't just assign this texture to any of the texture fields.
I was really hoping for a clean solution, and without Unity adding support for custom file formats or Blender fixing the export problem, it just isn't going to happen.
Your answer
Follow this Question
Related Questions
WWW.texture provides a :"?" texture... 1 Answer
Blit into Texture2DArray slice not working in WebGL 0 Answers
build file doesn't show image with GUI parts 0 Answers
Find texture by name? Or other types? 2 Answers
How to load image 2 Answers