Loading Crunched DXT at runtime

Hello everyone,
i need to load a DXT crunch texture downloaded with WWW (no bundle).
Is there a way to load it?

I tried with LoadRawTextureData but without success.

Texture2D texture = new Texture2D(4096, 2048, TextureFormat.DXT1Crunched, true);
texture.LoadRawTextureData(www.bytes);

Are you getting any errors or is it just not working?

You also need to call texture.Apply(); after you’ve loaded the texture data.

Damn! you’re right, I forgot it. :rage:
thank you @tonemcbride
Is there a way to load it without setting the width height and DXT(DXT1 or DXT5) ?
This information is contained within the file; for DDS (not crunched) i can read the header bytes and get this informations in a fairly simple way but for crn…

I think crunched files just have the raw data without headers but I’m not certain, someone else here might know? You could always add a width/height to the file that you’re downloading and read that in before creating the texture 2d?

Looking inside c++ crunch lib I found I can get width height and format from byte stream.

        ushort width = System.BitConverter.ToUInt16(new byte[2] { www.bytes[13], www.bytes[12] }, 0);
        ushort height = System.BitConverter.ToUInt16(new byte[2] { www.bytes[15], www.bytes[14] }, 0);
        byte format = www.bytes[18];
        TextureFormat textureFormat = TextureFormat.RGB24;
        if(format == 0){
            textureFormat = TextureFormat.DXT1Crunched;
        }
        else if (format == 2) {
            textureFormat = TextureFormat.DXT5Crunched;
        }
        else{
            throw new System.Exception("Not supported format");
        }

Now I have a bigger problem. Load dxt1/5 crunch texture with LoadrawTexturedata works in the editor, in standalone PC version but not in WebGL.
These are the errors in the console:

Has anyone experienced and solved this problem?

OUT_OF_MEMORY, try to increase webgl memory in player settings,
3239051--248901--upload_2017-9-30_17-27-48.png

Hey,

I was able to get the image size and format using @r3dwolf solution.
But the texture appears like this:

I’m compressing the image with the crunch library GitHub - Unity-Technologies/crunch at unity
and using the following to load the texture from a WWW request:

 Texture2D texture = new Texture2D(width, height, textureFormat, false);
texture.LoadRawTextureData(www.bytes);
texture.Apply();

Anyone knows what’s the problem?

I am having a similar problem. When I try to (at runtime) load Crunch textures from Unity’s fork of Crunch, they appear like this. (this is all in version 2017.2 or below, btw. As of 6/6/2018 crunch textures won’t open at all with version 2017.3 or above.)

3523711--282060--upload_2018-6-6_23-22-22.png

However, when I load crunch textures from the “vanilla” version of Crunch by Binomial, they appear just fine.

It’s unfortunate, because Unity creates Crunch textures roughly 5 to 6 times faster than vanilla.

Did you file a bug report?