DXT5 Texture SetPixels/GetPixels

how would you edit a dxt5 compressed texture?
are there any public static functions that allow you to decompress the data to rgba32, edit it then compress it back to dxt5, then texture.apply(); ?

just doing getpixels32, setpixels32 and treating it like rgba32 yields incorrect results

Quote: “This function works only on RGBA32, ARGB32, RGB24 and Alpha8 texture formats. For other formats SetPixels is ignored.”

To further explain, you don’t edit compressed textures.

You copy the color values from a compressed texture into an uncompressed texture, modify that uncompressed texture, and then compress the results. You can copy the compressed results back if you want. However if you plan on making multiple modifications you probably want keep the uncompressed version around and make modifications to that every time. Otherwise recompressing a texture using DXT5 over and over will significantly affect the quality, just like recompressing a jpeg over and over.

with GetPixelData, making edits to the NativeArray<> and doing texture.Apply(), does affect the texture.
but when you do that and treat it like rgba, it becomes corrupted.

would be great if unity exposed their compression functions through a static class

A DXT5 texture isn’t in a Color32 format. GetPixelData is getting the raw byte data. Using <Color32> means it’s treating each set of 4 bytes as if they’re a Color32 struct, which will give you junk since that’s not what format the data is.

There are several projects on GitHub that can encode or decode DXT/BC formats if you want to know what the data is, or see examples of how to apply the compression.

Using GetColors32 is decoding the values from the compressed format into Color32. If you want to convert that back to DXT5, you should use one of the compression functions.

One question though, what exactly are you wanting to do? Obviously you’re looking to edit a texture that’s compressed, but for what end result? If you’re looking to modify a DXT texture on the CPU, there’s a good chance you probably should be solving your problem in another way.