# How to use KTX2 / BASIS compressed normals

**URL:** <https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021>\
**Category:** Questions\
**Created:** [November 25, 2020, 4:37pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021 "2020-11-25T16:37:49Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![blitt6](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@blitt6](https://forum.babylonjs.com/u/blitt6)\
**Post date:** [November 25, 2020, 4:37pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/1 "2020-11-25T16:37:50Z")

</div>

If I use KTX2 normal maps compressed with the `separate_rg_to_color_alpha` option, is there an additional step necessary to load them correctly?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [November 25, 2020, 4:49pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/2 "2020-11-25T16:49:04Z")

</div>

Ping @bghgary and @Evgeni_Popov 🙂

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [November 25, 2020, 6:34pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/3 "2020-11-25T18:34:36Z")

</div>

Nope. It will just work. If you are compressing non-color maps, it’s probably best to use UASTC for the compression. It’s bigger, but it will have much less artifacts.

---

<div class="post-metadata">

**Author:** ![blitt6](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@blitt6](https://forum.babylonjs.com/u/blitt6)\
**Post date:** [November 25, 2020, 11:54pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/4 "2020-11-25T23:54:20Z")

</div>

Thanks @bghgary! Unfortunately, UASTC isn’t really an option for what we’re trying to do. It looks great, but the output files are too big.

---

<div class="post-metadata">

**Author:** ![Alex\_B](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alex\_B](https://forum.babylonjs.com/u/Alex_B)\
**Post date:** [December 1, 2020, 4:21pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/5 "2020-12-01T16:21:11Z")

</div>

Just a quick follow-up on this. I took a look at the Khronos examples page and they are using KTX2 files for their demo. I notice they are not compressing their normal maps but instead are using `JPG` for those files, but `KTX2` for everything else. Have you guys been able to get one of the usual GLTF models like the damaged helmet to work with just `KTX2`, and if so, can you share how that was done?

> **[glTF Sample Viewer](https://github.khronos.org/glTF-Sample-Viewer/)**

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 1, 2020, 4:24pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/6 "2020-12-01T16:24:43Z")

</div>

Pinging @bghgary

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [December 2, 2020, 11:00pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/7 "2020-12-02T23:00:49Z")

</div>

_Sorry for the slow response. It’s been a busy couple of days._

> [@Alex\_B](#):
>
> I took a look at the Khronos examples page and they are using KTX2 files for their demo. I notice they are not compressing their normal maps but instead are using `JPG` for those files, but `KTX2` for everything else.

I would not use the Khronos Sample Viewer as a reference for how to do things right now. It is currently being reworked including the KTX part, so stay tuned.

> [@Alex\_B](#):
>
> Have you guys been able to get one of the usual GLTF models like the damaged helmet to work with just `KTX2` , and if so, can you share how that was done?

If you look at the [medium post for the 4.2 release](https://babylonjs.medium.com/babylon-js-4-2-simplicity-reimagined-965f88d0fad), there is a [PG](https://aka.ms/4_2_BasisUPlayground) with the FlightHelmet using KTX.

Right now, the easiest way to get a glTF asset to be compressed with KTX for its textures is to use [glTF-Transform](https://gltf-transform.donmccurdy.com/) which is what I did for the aforementioned playground.

I did this to get the FlightHelmet glTF compressed:

```plaintext
> gltf-transform etc1s FlightHelmet.gltf output1\FlightHelmet.gltf --slots "baseColorTexture" -v
> gltf-transform uastc output1\FlightHelmet.gltf output2\FlightHelmet.gltf --zstd 22 --slots "!baseColorTexture" -v

```

The Khronos 3D formats working group (of which I’m a member) is working on better documentation and tooling for KTX.

---

<div class="post-metadata">

**Author:** ![Alex\_B](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alex\_B](https://forum.babylonjs.com/u/Alex_B)\
**Post date:** [December 2, 2020, 11:55pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/8 "2020-12-02T23:55:48Z")

</div>

> If you look at the [medium post for the 4.2 release](https://babylonjs.medium.com/babylon-js-4-2-simplicity-reimagined-965f88d0fad), there is a [PG](https://aka.ms/4_2_BasisUPlayground) with the FlightHelmet using KTX.

For some reason that PG is throwing an error. We have gotten the normal maps working using `toktx`, so now we just need to try some different settings to optimize our output. We’ll update this post when we’ve got it dialed in. 🙂

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [December 2, 2020, 11:57pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/9 "2020-12-02T23:57:35Z")

</div>

> [@Alex\_B](#):
>
> For some reason that PG is throwing an error.

What kind of error? It would be good to know if there is an issue here.

---

<div class="post-metadata">

**Author:** ![Alex\_B](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alex\_B](https://forum.babylonjs.com/u/Alex_B)\
**Post date:** [December 3, 2020, 12:36am UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/10 "2020-12-03T00:36:12Z")

</div>

![Screen Shot 2020-12-02 at 4.35.47 PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/36e757e6d14c2a64c83c6138098f21faa293ce7b.png)

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [December 3, 2020, 1:13am UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/11 "2020-12-03T01:13:47Z")

</div>

Hmm, that’s odd. Can you open an incognito/in-private browser window to make sure it’s not a caching issue? Also, make sure you have the playground set to the 4.2 or the latest version.

---

<div class="post-metadata">

**Author:** ![Alex\_B](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alex\_B](https://forum.babylonjs.com/u/Alex_B)\
**Post date:** [December 3, 2020, 1:28am UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/12 "2020-12-03T01:28:42Z")

</div>

Yep, that fixed it. Thanks!

---

<div class="post-metadata">

**Author:** ![Dshah\_H](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dshah_h/32/3607_2.png) [@Dshah\_H](https://forum.babylonjs.com/u/Dshah_H)\
**Post date:** [February 16, 2021, 7:28am UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/13 "2021-02-16T07:28:43Z")

</div>

> [@bghgary](#):
>
> ```auto
> > gltf-transform etc1s FlightHelmet.gltf output1\FlightHelmet.gltf --slots "baseColorTexture" -v
> > gltf-transform uastc output1\FlightHelmet.gltf output2\FlightHelmet.gltf --zstd 22 --slots "!baseColorTexture" -v
> 
> ```

hey @bghgary , the above commands were super helpful, my model went from 25 mb to 7mb by using it. I wanted to ask couple of things if you could enlighten me:

1. I encountered few warnings for POT like: “warn: Texture dimensions 512x367 are NPOT, and may fail in older APIs (including WebGL 1.0) on certain devices.” , I presume it is necessary to correct those for better performance , right?

2. I have created some standard /custom material texture in babylonjs, which are not embedded in GLB model , how would I go about to compress them? (I couldn’t find a command for this on glTF-Trsnform)

3. in above commands you are only using `baseColorTexture`, should I also process on other texture types? here is a small pic from inspect after running above command: 

4. what are these parameters for? `--zstd 22 --slots` and which other parameters are available? couldn’t find in docs.

5. are there some other helpful commands to process my model from glTF-Transform? I [see](https://gltf-transform.donmccurdy.com/cli.html) that draco and weld would be helpful. here are what I am using now

Thanks

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 17, 2021, 1:49am UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/14 "2021-02-17T01:49:06Z")

</div>

> [@Dshah\_H](#):
>
> I encountered few warnings for POT like: “warn: Texture dimensions 512x367 are NPOT, and may fail in older APIs (including WebGL 1.0) on certain devices.” , I presume it is necessary to correct those for better performance , right?

Yes.

> [@Dshah\_H](#):
>
> I have created some standard /custom material texture in babylonjs, which are not embedded in GLB model , how would I go about to compress them? (I couldn’t find a command for this on glTF-Trsnform)

I’m not sure. Maybe ask on the GitHub? [Issues · donmccurdy/glTF-Transform (github.com)](https://github.com/donmccurdy/glTF-Transform/issues)

> [@Dshah\_H](#):
>
> in above commands you are only using `baseColorTexture` , should I also process on other texture types?

The commands I sent will compress all the textures. Only the color texture uses ETC1S where as everything else uses UASTC.

> [@Dshah\_H](#):
>
> what are these parameters for? `--zstd 22 --slots` and which other parameters are available? couldn’t find in docs.

`--zstd` specifies the zstd compression level. `--slots` indicate which texture slots to apply the command to. I’m not sure. I got this information from Don 🙂

> [@Dshah\_H](#):
>
> are there some other helpful commands to process my model from glTF-Transform?

Seems like you got all of them.

---

<div class="post-metadata">

**Author:** ![Dshah\_H](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dshah_h/32/3607_2.png) [@Dshah\_H](https://forum.babylonjs.com/u/Dshah_H)\
**Post date:** [February 17, 2021, 8:30am UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/15 "2021-02-17T08:30:08Z")

</div>

Thanks @bghgary , I figured that we could use toktx for external images compression, with `toktx --t2 --bcmp image_out.ktx2 image_in.png`, I found one of your answer where you mentioned to [use `.ktx2` instead of `.basis`](https://forum.babylonjs.com/t/how-to-generate-a-basis-file/12373/2) , any particular reason for that? I guess it contains more then 1 textures type inside?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 17, 2021, 8:35pm UTC](https://forum.babylonjs.com/t/how-to-use-ktx2-basis-compressed-normals/16021/16 "2021-02-17T20:35:54Z")

</div>

> [@Dshah\_H](#):
>
> use `.ktx2` instead of `.basis`, any particular reason for that?

`.ktx2` is backed by the Khronos Group. `.basis` is not backed by any standards committee.
