Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gltfpack: Implement support for KTX2 with supercompression #81

Merged
merged 16 commits into from
Nov 27, 2019

Conversation

zeux
Copy link
Owner

@zeux zeux commented Nov 26, 2019

This change adds -tc command line flag that uses basisu command line tool to compress images using Basis Universal format, and then converts the result to KTX2 container format.

The resulting images are then referenced from the output gltf/glb file using KHR_texture_basisu and KHR_image_ktx2 extensions.

This converter is written by following the KTX2 spec but using a few
data structures from KTX/Basis source to simplify the implementation.

The implementation is incomplete - it doesn't write the correct DFD yet
- and hasn't been tested.
The DFD is currently constructed by following the spec - I'm not sure
this is correct because the validator has a different idea about whether
to include sample information into the DFD and which color model to
specify.
When -tc is specified, we use basisu to compress Basis textures and then
re-encode the result in a KTX container.
This change refactors the flow in writeImage so that error path is
always in the else {} branch.
Instead of two loops to lay out the data and then write it, just use a
single loop that fills a temporary variable.
Our DFD had incorrect size - it was much larger than it should be. This
change fixes this and also removes all sample information from DFD -
while the spec says it must be included, the validator says it must not
be included and we will trust the validator for now.

In a similar vein, use UNSPECIFIED color model because it validates
cleanly even though the spec disagrees.
We now include KHR_image_ktx2 and KHR_texture_basisu into the list of
used and required extensions, and use correct MIME type and JSON
specification to refer to the images used.
According to a recent spec update, Basis DFD in fact must contain
information about color channels so we are going to include it. It's
unclear how we can tell whether an image is two-channel, so for now just
differentiate between 3-channel and 4-channel images.
According to a recent specification update, KTX2 images with Basis
supercompression need to in fact include an RGBSDA DFD that specifies
all channels used.

It's not clear how we can infer that the original image was two-channel
so for now just distinguish between 3- and 4-channel images.
We now use the use of the texture to infer sRGB/linear information; this
is used to change BasisU encoding settings as well as specify the
correct DFD in KTX2 images.
The flag definition is broken - the flags don't correspond to bit masks
and aren't specifying correct bit positions either. Just copy the flags
from Basis file header in the meantime as this is what toktx does...
When -tc is used without -te, we need to produce files with .ktx
extensions.
This change moves logic into analyzeImages, writeTexture, writeArray,
writeExtensions and printSceneStats to make process a bit shorter and
faster to compile. The extension refactor in particular makes it easier
to tell, at a glance, which extensions are going to be used/required.
Also format vertexcodec.cpp - clang-format behavior here is somewhat
weird but so be it.
@zeux zeux merged commit b8e7cd8 into master Nov 27, 2019
@zeux zeux deleted the gltf-ktxbasis branch November 27, 2019 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant