Thoughts on webp texture format?

Hi

In some of my 3d assets, I noticed instead of PNG they use a JPG texture for diffuse map and one for alpha map due to much less file size. I noticed neither Gltf spec nor JME PBRLighting does not support separate alpha map and upon exporting from blender to Gltf it combines those to PNG which largely increases the file size.

As an example on a texture with res 1024x1024:

With separate diffuse/alpha maps (in JPG) the size is 238 KB
After converted to PNG it becomes 1.2 MB

This can largely affect the size of my assets. I decided to test with a few other formats (TGA, PSD, DDS with dxt1,3,5, WebP) and noticed that WebP gave the best result in my test with a file of size 165 KB and quality loss was negligible and after that, it was the DDS DXT1 with a file size of 524 KB.

The interesting thing is that WebP image quality is looking better than DDS even though its size is much less than DDS!!
I used Gimp for conversion.

As I am going to target Android devices as well, the nice thing I found with WebP is that unlike DDS it is already supported by Android (but one must use JME’s AndroidBufferImageLoader instead of AndroidNativeImageLoader).

I am also interested to hear your ideas about using this format instead of PNG and that how wide it is used in games and if you have any other suggestions.

5 Likes

Hi, @Ali_RS have you tried using webp format on Android? :wink:

Yes, tried it yesterday with Android 7 on a simulator, and it worked. (WebP support is added from android 4.0)

For android, you need to register the AndroidBufferImageLoader into the asset manager to load WebP textures.

assetManager.registerLoader(AndroidBufferImageLoader.class, "webp");

AndroidBufferImageLoader uses android BitmapFactory to load textures but seems it is deprecated in JME, idk why!

By default JME uses AndroidNativeImageLoader that uses the stb_image library with JNI but unfortunately, it does not support WebP.

For desktop, JME uses Java ImageIO to load textures, and ImageIO supports WebP via a plugin. You just need to add pluging to your gradle dependencies and ImageIO will automatically pick that:

Edit:
For desktop you also need to add this as well

assetManager.registerLoader(AWTLoader.class, "webp");

3 Likes

Thank you @Ali_RS , I am looking for a solution for texture compression on android. :grinning:

2 Likes

yeh, i heard a lot of good about webp, so i guess it would be good not just for Android.

2 Likes

Yeah, I have been testing it on more textures and I was able to reduce my asset size by around 600% :slightly_smiling_face:

I went ahead and added WebP conversion into my asset conversion pipeline when converting from Gltf to j3o.

3 Likes