Hello there,
I have a texture that I generate in the editor and then I save it to disk for it to be used during runtime. However, I really want to reduce the quality of the texture by applying Crunch compression as one thing.
However, I want the file that is written to disk to be a compressed version of the original texture, which is by itself not compressed. I hope that makes sense.
I can’t seem to find a way to access Unity’s Crunch compression API and not sure what is a good way in handling this problem. Would really appreciate any help on this
So, if I understand what you want, you want to compress an image using Crunch, and then save a TGA of that compressed image to disk?
The only way to use Crunch is to save an image to disk and import it with Crunch turned on. There’s no support for running Crunch directly, even from within the editor. So you’ll have to generate the image, save it as a TGA in the asset folder, and then modify the subsequently asset’s Texture Importer settings to enable Crunch at the quality level you want. You’ll then need to blit the texture to a RenderTexture and read those pixels back to another texture that you save to disk as another TGA.
Yeah, you can’t compress textures with Crunch compression at runtime but if I understood you correctly, UserNobody, you want to do this in the editor?
I think, in an editor script you should be able to save the generated uncompressed texture as a png into the Assets folder and then force a reimport of the asset. In the AssetPreprocessor, you can enable crunch compression for the texture.
(disclaimer: haven’t tried it)
PS: Theoretically, you could also write a plugin to integrate the crunch library manually, but that would be a very unusual use case. The crunch library gives you either CRN or clustered DDS files. Unity can’t load CRN files and its DDS support is also very limited. So you’d have to upload the compressed data manually to a texture. It should be doable but I can’t think of a good use case.
PPS: Also keep in mind that Crunch compression works on top of regular texture compression (DXT, ETC). So you can’t have a PNG or JPEG with crunch compression because they don’t support texture compression. Only DDS does. Also, if you use the clustered DDS file format, you have to put it into a LZMA compressed archive as well, like Unity’s bundle files.