Open thokra1 opened 3 years ago
Mipmap generation in toktx uses the same code as basisu
. Use --genmipmap
to invoke it. It automatically does -mip_srgb
if the input images are srgb, as determined from the input image. Similarly -mip_linear
is done if the input images are linear. You can override the image metadata with--{assign,convert}_oetf
which will also change the mipmap generation. You can set the filter with --filter
, the scale with --fscale
and the clamp mode with --wmode
. The only things missing are -mip_renormalize
, -mip_fast
and -mip_slow
. I have a TODO for renormalize. toktx currently always does the same as -mip_slow
. The resampling speed has never troubled me so I didn't have a TODO for fast & slow.
Whoops! You want the mipmap generation functionality in libktx. If I add it, I'll make it work for any format not just when using the BasisU encoder. Like with toktx, mip_srgb and mip_linear will be chosen based on the texture format but it will be possible to override.
This would be highly appreciated. Alternatively, I could spare some time and give you a pull request, if you're interested.
A PR would be great. The PR can access the resampler in the BasisU code in a similar way to how toktx does it. The genmipmap function should give KTX_INVALID_OPERATION if the texture is already in a block-compressed format or if it already has mipmaps.
I was caused to re-read this report after which I have a few questions:
ktx create
(except it does not support BMP and TGA inputs). So @thokra1 what exactly are you asking for?ktx create
?The BasisU tool can also unpack .basis files to "one of more .ktx/.png files". You could then read these back into the tool and use the mipmap generation. You can do exactly the same with the ktx tool suite: use ktx extract
to create .png or .exr files then ktx create
with mipmap generation options to create a new .ktx2 file. But I do not recommend doing this from source files that have been subject to lossy compression: .basis files or .ktx2 files with BasisU, BCn, ASTC, ETC, etc. format images because you will introduce further losses. For this reason, if we were to add mipmap generation support to libktx, we would make it a KTX_INVALID_OPERATION
to generate mipmaps if the .ktx2 file has such a format.
The crux of deciding whether there is anything to proceed with here is the answer to question 2.
@MarkCallow one significant use case would be tools like glTF-Compressor. To my understanding it uses libktx via JS/WASM to compress PNG/JPG images in glTF files; ktx create
is not available in a browser environment. As a result, glTF files generated with glTF-Compressor currently lack mipmaps:
Currently, there doesn't seem to be a way to let the BasisU encoder generate mip maps. There is a host of options one can pass to the latest BasisU CLI:
Currently, while using libKTX works well for most other encoding-related tasks, all of the above has to be implemented separately (in our case using STBI resize, which sadly lacks Kaiser window filtering, IIRC).