-
Notifications
You must be signed in to change notification settings - Fork 510
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This is set to "gltfpack".
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.