# Texture Compression Update (Alpha testing)

**URL:** <https://forum.defold.com/t/texture-compression-update-alpha-testing/67470>\
**Category:** Announcements\
**Created:** [February 5, 2021, 4:09pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470 "2021-02-05T16:09:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 5, 2021, 4:09pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/1 "2021-02-05T16:09:59Z")

</div>

# Texture Compression Update

We’ve previously had quite limited options for texture compression for our platforms.  
The ones we’ve had have been mostly focused on mobile platforms (ETC1 and Pvrtc1).

Now we’ve updated our pipeline to support ASTC, ETC2, BCx and RGTC formats.  
To do this, we use a library called [Basis Universal](https://github.com/BinomialLLC/basis_universal) from [Binomial](http://www.binomial.info/).

## What does it do?

Traditionally, textures are compressed on the development machine, into a format that (hopefully) is supported on the target user machine. However, if the target machine doesn’t support that format, you have to mitigate that somehow (e.g. separate bundles).

Basis Universal instead compresses into a generic format that gets shipped with the game.  
When the game runs, we check what hardware compression formats are supported, and then ask the basis library to _transcode_ the compressed basis texture into the hardware format we want.

That way you can use the same bundle for multiple versions (e.g. old and new android devices)

# Texture Profiles

The way it works is that you choose a texture format (say `TEXTURE_FORMAT_RGBA`) for a set of textures.  
Then you choose the compression type.

If you chose `DEFAULT`, which means no compression, you’ll get the format you asked for at runtime and the data will be uploaded to the GPU uncompressed. This might be good if you wish to upload a new version of the texture at runtime.

If you chose `BASIS_UASTC`, the texture will be compressed into a `.basis` file (internally), with possible mipmaps.

> **[Texture profiles in Defold](https://defold.com/manuals/texture-profiles/)**
>
> Defold supports automatic texture processing and compression of image data. This manual describes the available functionality.

# Fallback strategy

Note that the texture format you specified, will now act as the fallback format, in case the graphics card didn’t support any suitable compressed formats.

You can see the actual [code here](https://github.com/defold/defold/blob/dev/engine/graphics/src/graphics.cpp#L246-L290)  
The current fallback strategy is fixed, and it favors quality over size (e.g. ASTC over Pvrtc1).

# Performance

The size of the compressed texture stored on disc will be 1 byte per pixel. Also note that we have LZ4 compression on the entire game archive, so the actual size is a little bit smaller still.

To compress faster, the texture compiler itself uses up to 8 threads to compile the texture.  
A big (commercial) project with ~1.5gb of textures takes ~15 minutes on my machine.  
I also happen to know that the authors of Basis Universal are working on improving both the size of the compressed textures, and also the compression speed with ~2-3 times in the next few months.

At runtime, the texture will transcode into the final format before uploading to the GPU. This step takes ~5-15ms per texture. It is currently done on the loader thread, but one of the next tasks is to move the transcoding work to the texture upload thread.

Also, don’t forget to check the texture sizes at runtime using our [Web Profiler](https://defold.com/manuals/profiling/#resource-profiler)!  
It’s an easy way to see if the textures were uploaded to a hardware supported compression format on your device.

# WebP

For engine size (and performance) reasons, the previous compression format WebP has been removed.  
For backwards compatibility, we convert the compression type like so

```
* WEBP -> DEFAULT
* WEBP LOSSY -> BASIS_UASTC

```

# Notes

Note that I’m also working on upgrading our OpenGL backend to support OpenGLES 3 and WebGL 2.  
This is needed in order to support ETC2 on Android, and ASTC on iOS. I expect this work to be done in a few days.

Interestingly enough, the Android devices I have tested on, already support ASTC, so that’s something you can test right now.

# Feedback

We’d love to hear your experience with this feature, and to see if there are any issues that pop up.

You can get the build from the [Alpha Download Page](http://d.defold.com/alpha).

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 5, 2021, 4:10pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/2 "2021-02-05T16:10:17Z")

</div>



---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [February 5, 2021, 5:04pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/3 "2021-02-05T17:04:50Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> You can get the build from the Alpha Download Page.

Fix the link, please! It doesn’t work.

> [@Mathias\_Westerdahl](#):
>
> Now we’ve updated our pipeline to support ASTC, ETC2, BCx and RGTC formats.  
> To do this, we use a library called [Basis Universal](https://github.com/BinomialLLC/basis_universal) from [Binomial](http://www.binomial.info/).

That’s fantastic news! We’re going to use Basis for the upcoming 3d web game [mentioned here](https://twitter.com/Notbadgun/status/1355603061088145414?s=20).

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 5, 2021, 5:30pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/4 "2021-02-05T17:30:04Z")

</div>

> [@aglitchman](#):
>
> Fix the link, please! It doesn’t work.

Fixed!

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [February 5, 2021, 8:19pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/5 "2021-02-05T20:19:49Z")

</div>

I got [my old test project](https://forum.defold.com/t/texture-management-in-defold/8921/10) and made a comparison.

**HTML5**

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/9/1/916e12015769e833b31344792505e9d95c7e6f91.jpeg)  
WebP Safari:  
 ![webp-web-safari](https://forum-defold-uploads.b-cdn.net/original/3X/f/3/f34a53499091457592395fe7a8aec7d482660e44.png)  
Basis Safari:  
 ![basisu-web-safari](https://forum-defold-uploads.b-cdn.net/original/3X/5/f/5feaf2ec2bb24fee9cb03b318dd9dc914d9837ce.jpeg)

WebP Chrome:

 ![webp-web-chrome](https://forum-defold-uploads.b-cdn.net/original/3X/1/f/1f75653badc19e8b6fbed11f4fc96f514409dd3c.png)  
Basis Chrome:  
 ![basisu-web-chrome](https://forum-defold-uploads.b-cdn.net/original/3X/d/6/d6883ce708c63f2b8b2b36910de1187af3d63fca.png)

Build size:

Basis 58.6Mb  
WebP 23.5Mb

Basis zip 18.9Mb  
WebP zip 16.9Mb

**Android**

Device: Xiaomi Redmi Note 4

WebP:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/a/6/a62ad6ec359d2a8a4fffb48ea76418149339a79f.png) cid:17773c779246d5e471a1

Basis:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/8/b/8b39d20e7af7e774f851411f0394ee220e5767af.png) cid:17773c390052330d6d71

Build size:

Basis 20Mb  
WebP 18Mb

**iOS**

Build size:

Basis 19.3Mb  
WebP 17.3Mb

\*Similar to webp, the first time is always much slower. But I didn’t make screenshots it this time.

\*\*I’m going to improve the old test project and repeat all the measurements

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [February 5, 2021, 8:40pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/6 "2021-02-05T20:40:41Z")

</div>

Are these fonts? We have duplicate fonts with different materials set probably a better way to deal with that?

```lua
/_generated_f6cce506.texturec 

```

 ![2021-02-05%2012_31_27-Window](https://forum-defold-uploads.b-cdn.net/original/3X/9/6/969636113a12c2f34019d05a434e1de614e66627.png)

Doing testing with BASIS\_UASTC now.

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [February 5, 2021, 8:42pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/7 "2021-02-05T20:42:15Z")

</div>

> [@AGulev](#):
>
> Basis 58.6Mb  
> WebP 23.5Mb
> 
> Basis zip 18.9Mb  
> WebP zip 16.9Mb

Is LZ4 compression not efficient for Basis textures? Looks like the game archives are not compressed at all.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [February 5, 2021, 11:23pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/8 "2021-02-05T23:23:06Z")

</div>

Compression must be enabled in the editor when building from the editor and testing a texture profile with BASIS\_UASTC enabled otherwise you get errors.

```lua
ERROR:GRAPHICS: Failed to validate header (Basis) for file '/_generated_6a8c4c5.texturec'
ERROR:GAMESYS: Failed to transcode /_generated_6a8c4c5.texturec
ERROR:GAMESYS: No matching texture format found for /_generated_6a8c4c5.texturec. Using blank texture.

```

Loading seems to be faster with BASIS\_UASTC enabled but need to do more testing. Final file size seems larger but need to test that more too.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 6, 2021, 8:26am UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/9 "2021-02-06T08:26:43Z")

</div>

@agulev What are the “zip” files? Are they the game bundle? Or just the build folder zipped up?

@aglitchman There is currently work being done for the uastc compression to make it being more “compressible” by LZ4 (or any other), with minimal quality loss. You can follow the developer [Rich Geldrich](https://twitter.com/GeldreichRich) on Twitter for a lot of updates and details regarding this.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [February 6, 2021, 8:31am UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/10 "2021-02-06T08:31:26Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> What are the “zip” files? Are they the game bundle? Or just the build folder zipped up?

Just a zipped bundle folder.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 6, 2021, 8:33am UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/11 "2021-02-06T08:33:57Z")

</div>

@pkeod No, fonts have the suffix “.fontc”.

We disassemble each font into separate glyphs (raw data), which we then compress individually. We do this since we use a texture atlas which we populate with the small glyphs as they are used, and evict older glyphs as needed.

Since we removed WebP, we now use Deflate for compression, so the sizes grew a little bit. (from 55% to 66%)  
[https://twitter.com/mwesterdahl76/status/1355077773610639360](https://twitter.com/mwesterdahl76/status/1355077773610639360)

I have a PR coming up that will bring the compression of the glyphs back to 62% (On 26 MB fonts, it previously compressed to 17.6mb with deflate, now it compresses to 16.6 mb)

The next big thing for fonts is to add an api to dmSDK that lets extensions provide the actual glyphs themselves to the engine. That, I think will be a huge space saver.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [February 6, 2021, 8:42am UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/12 "2021-02-06T08:42:39Z")

</div>

What’s an easy way to figure out what the /\_generated\_f6cce506.texturec files are? There are apparent duplicates in size which concern me.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 6, 2021, 8:46am UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/13 "2021-02-06T08:46:23Z")

</div>

Agreed, the naming is an issue. You could try to add “-v” to bob (if you’re using it that is), to perhaps see which atlas becomes which texture.  
If it doesn’t, I should add it 😕

Unfortunately, the editor is more “clever” and merges all output that has the same checksum (not sure how often that happens though), so the same .texturec could potentially have multiple source files.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 8, 2021, 1:52pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/14 "2021-02-08T13:52:37Z")

</div>

Since @Jerakin asked for some numbers from my testing.  
Thanks to this I found a thing I had forgot to change, add the LZ4 compression on the textures(!). It was previously turned off since minimal impact on the WebP compressed textures.

- 5 textures (256x256) 2xRGB, 2xRGBA, 1xR
- With mipmaps
- macOS

Build times

```
WebP (lossy) 14.808s
WebP (non lossy) 14.816s
Basis 7.035s

```

Size on disc: (game.arcd) (LZ4 compressed):

```
WebP (lossy) 313930
WebP (non lossy) 315906
Basis 395526

```

_the uncompressed basis textures were 645846 bytes_

Runtime decompress/transcode

```
WebP (lossy) 5 textures / 327680 texels in 7.487000 ms
WebP (non lossy) 5 textures / 327680 texels in 7.310000 ms
Basis 5 textures / 436905 texels in 4.886000 ms

```

_I calculated the texel count is more accurate on basis. They should be the same_

_Update_ The average LZ4 compression of the basis textures are ~42% of the original size.  
Also note that we anticipate even more compression ratio improvements from Basis Universal, as they continue to develop it as we speak.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 8, 2021, 3:30pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/15 "2021-02-08T15:30:44Z")

</div>

Some engine size numbers (since I know @AGulev wants to know 😉 )

_Release builds, stripped_

### arm64-darwin

```
1.2.179 2635564
1.2.180 2553284

-80kb (~3%)

```

### arm64-android (dmengine.apk)

```
1.2.179 2024820
1.2.180 2092295

+64kb (~3%)

```

### wasm-web

```
1.2.179 2160378
1.2.180 2187290

+~26 kb (~1%)

```

_32 kb was added for the WebGL 1 fallback_

In all honesty, I would have thought that the engine would have decreased even more since WebP was quite big. But I guess they were more or less the same size then. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 8, 2021, 3:52pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/16 "2021-02-08T15:52:10Z")

</div>

There is a new [alpha build](https://d.defold.com/alpha/) available, with LZ4 compression enabled for the textures.

---

<div class="post-metadata">

**Author:** ![Lex](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/lex/32/23856_2.png) [@Lex](https://forum.defold.com/u/Lex)\
**Post date:** [February 8, 2021, 4:30pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/17 "2021-02-08T16:30:38Z")

</div>

Piggybacking on this topic, but as I’m trying to compress my resources for iOS and Android. How do you know which FORMAT to chose?

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/3/5/3510b2f6afc00bbef525ed4b2a86bf28e8f1c376.png)  
Luminance, Luminance alpha etc don’t sound familiar, I don’t know which one to chose from. I use regular pngs and spines, which one would you pick and why? Thanks

(If this is off topic I will delete my post)

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [February 8, 2021, 4:35pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/18 "2021-02-08T16:35:28Z")

</div>

Check out this thread

> [@Texture Management in Defold](https://forum.defold.com/t/texture-management-in-defold/8921):
>
> This post is for beginners of mobile game dev and aim to inform about the different areas of how to work with textures in defold. A lot of the number presented in this post are ballpark numbers and should only be seen as a recommendations, not law or fact. Makeshift Table of Content [This post](https://forum.defold.com/t/texture-management-in-defold/8921) Texture profiles Atlases Hardware compression Texture size [Common problems](https://forum.defold.com/t/texture-management-in-defold/8921/2)[Atlas properties](https://forum.defold.com/t/texture-management-in-defold/8921/16)[Resizing Images](https://forum.defold.com/t/texture-management-in-defold/8921/17)[Optimizing](https://forum.defold.com/t/texture-management-in-defold/8921/18) Texture Profiles The texture profile is only used when you bundle your package,…

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [February 8, 2021, 5:21pm UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/19 "2021-02-08T17:21:23Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> Some engine size numbers (since I know @AGulev wants to know 😉 )

awww, thx!

> [@Mathias\_Westerdahl](#):
>
> In all honesty, I would have thought that the engine would have decreased even more since WebP was quite big. But I guess they were more or less the same size then. 🤷‍♂️

Then it’s time to exclude the video recorder by default! =) For me it was a surprise that webp and the recorder uses separate codecs lib. I was sure the recorder use the format it uses just to avoid using separate vpx lib.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [February 9, 2021, 7:02am UTC](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470/20 "2021-02-09T07:02:00Z")

</div>

Yes. But also note that the video recorder is excluded by default on release builds, so you won’t save anything there

[Next page](https://forum.defold.com/t/texture-compression-update-alpha-testing/67470.md?page=2)
