KhronosGroup / KTX-Software

KTX (Khronos Texture) Library and Tools
Other
874 stars 229 forks source link

ktx2ktx2 not working with IBL cubemap? #278

Closed YVin3D closed 4 years ago

YVin3D commented 4 years ago

We're trying to integrate KTX2 into Cesium, but while converting one of our sandcastle cubemaps (attached) to KTX2, I run into this error message:

ktx2ktx2 failed to create ktxTexture; File data is inconsistent with KTX spec.

I'm fairly certain that the texture is valid since it was generated by one of our devs using Google Filament a while back. You can see the file in action on this Cesium example page

Running macOS Catalina 10.15.5, libktx-4.0.0 (latest build at the time of posting this)

kiara_6_afternoon_2k_ibl.ktx2.zip

DDoS commented 4 years ago

I'm having the same issue, so I did some debugging. The failure happens in ktxCheckHeader1_ because pHeader->glFormat == pHeader->glInternalformat.

Note the comment:

// glInternalFormat is either unsized (which is no longer and should
// never have been supported by libktx) or glFormat is sized.

Filament implements its own KTX writer and uses KtxBundle::R11F_G11F_B10F for both glFormat and glInternalFormat in iblRoughnessPrefilter and extractCubemapFaces, so the error is expected for IBL and skybox KTX files.

It seems Filament is the one that should be fixed.

MarkCallow commented 4 years ago

Thanks @DDoS. You've saved me some time. Your analysis is correct. Will one of you open an issue for Filament?

DDoS commented 4 years ago

I'm testing a fix for Filament, I'll open a PR if it works, or an issue if I can't find a fix.

DDoS commented 4 years ago

@YoussefV The KTX writing issue was fixed in Filament main: https://github.com/google/filament/pull/2845

YVin3D commented 4 years ago

@DDoS Great! Thanks for the help Aleksi!