BinomialLLC / basis_universal

Basis Universal GPU Texture Codec
Apache License 2.0
2.68k stars 261 forks source link

Extract .basis from ktx2. #318

Open fire opened 2 years ago

fire commented 2 years ago

We can compress images into ktx2.

basisu::basis_compressor c;
// ...
const basisu::uint8_vec &buvec = c.get_output_ktx2_file();

How do we take a ktx2 and get a basis file with all the mipmaps, layers, and supporting both etc1s and uastc?

Trying to implement basisu in gltf where I convert a gltf ktx2 basisu to the internal storage of a .basis instead of directly to bptc, astc, or dxt5.

fire commented 2 years ago

Working in the https://github.com/V-Sekai/godot/tree/gltfpack-basisu branch.

// https://github.com/V-Sekai/godot/commit/3adfbf559adddf5d5a991ea7a2c03a97f6cc3e65
// This takes a image and outputs a ktx2. Easy.
Vector<uint8_t> (*Image::basis_universal_ktx2_packer_ptr)(const Ref<Image> &, Image::UsedChannels) = nullptr;
// This takes a image and outputs an image which is internally a .basis. Stuck here.
Ref<Resource> (*Image::basis_universal_ktx2_unpacker_ptr)(const uint8_t *, int) = nullptr;
richgel999 commented 2 years ago

How do we take a ktx2 and get a basis file with all the mipmaps, layers, and supporting both etc1s and uastc?

Is the KTX2 uncompressed? That should be relatively easy, although we would need to write a KTX2 reader. (Which isn't hard, but any parser involves security concerns.)

fire commented 2 years ago

Is a KTX2 reader something that fits this library for purpose of png -> ktx2, and ktx2 -> basis. Not sure where else to fit it. Other devs spent some time converting to basis.

See https://github.com/mosra/magnum-plugins/issues/110

MarkCallow commented 1 year ago

There is already a widely supported KHR_texture_basisu extension for glTF which uses KTX v2 format files. It seems like https://github.com/V-Sekai/godot/tree/gltfpack-basisu is out-of-date or incorrect.

fire commented 1 year ago

Yes, its incorrect, thats the whole point of this bug. I can either implement support or close.

MarkCallow commented 1 year ago

Or you can use a non-broken gltf pack tool.