2 minute read

In this post I show you how to create a compressed ktx2 file from a set of cubemap images.

I used the compression to compress a uncompressed 360MB 4k skybox into a 0.5MB(!) file (using a very sparse space-skybox)

The ktx docs are complex to read and short on examples. I offer my solution here if anyone else needs to convert a cubemap to a basisu compressed ktx2 cubemap.

First install the ktx tools. I use windows and downloaded the installer from the “Releases” page on GitHub: Link (I used v4.3.2)

The below command was all I needed. (You may have to scroll right to see the whole command, or just copy everything.)

# ktx v4.3.2
ktx create --format R8G8B8_SRGB --encode basis-lz --cubemap ./right.png ./left.png ./top.png ./bottom.png ./front.png ./back.png output.ktx2

Breakdown of the command:

  • ktx create: This is the command to create a new KTX file.
  • --format R8G8B8_SRGB: This specifies the format of the images. R8G8B8_SRGB means the images are in 8-bit RGB format with sRGB color space. (This is probably what you want.)
  • --encode basis-lz: This specifies the encoding and compression method to use, in this case, basis-lz for Basis Universal ETC1S compression. (You may also try uastc for higher visual quality if needed)
  • --cubemap: This flag indicates that the images are to be used as a cubemap.
  • ./right.png ./left.png ./top.png ./bottom.png ./front.png ./back.png: These are the input images for the cubemap, representing the six faces of the cube as inputs.
  • output.ktx2: The last parameter is the name of the output KTX2 file.

You may want to decide which encoding you want to use, check the docs for variants.

Thats all for this time.

Note: If you have HDR images this is not yet supported as of writing. But it seems like UASTC HDR support should be coming.

// Nils Henrik

Tags: ,

Categories:

Updated: