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

KTX2 uncompressed textures support #47

Closed
jsorel opened this issue Dec 16, 2021 · 2 comments
Closed

KTX2 uncompressed textures support #47

jsorel opened this issue Dec 16, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@jsorel
Copy link

jsorel commented Dec 16, 2021

Hello,

Having compression support is nice but all compressions are lossy and sometimes we need the exact values.

I noticed you skip all uncompressed texture.

                if(ktx.ktxClass==KtxClassId.ktxTexture2_c) {
                    if(ktx.needsTranscoding) {
                        texture = await Transcode(ktx,linear);
                    } else {
                        Debug.LogError("Only supercompressed KTX is supported");
                    }
                } else {
                    Debug.LogError("Only KTX 2.0 is supported");
                }

Would it be possible to support a few uncompressed format for stuff not SRGB-like who require no data-loss ?

  • VK_FORMAT_R8_UINT
  • VK_FORMAT_R16_UINT
  • VK_FORMAT_R16_SINT
  • VK_FORMAT_R16_SFLOAT
  • VK_FORMAT_R32_SFLOAT
@atteneder
Copy link
Owner

@jsorel Thanks for bringing it up. You're absolutely right, that would indeed be helpful.

The only reason it's not supported at the moment is that the MVP initially aimed for BasisU decompression support (only).

Truth be told, I'm quite busy on glTF work (where non-compressed KTX files are not a thing yet), so if any volunteer would offer help with support for uncompressed, I'd be very grateful.

@atteneder atteneder added the enhancement New feature or request label Dec 16, 2021
@jsorel
Copy link
Author

jsorel commented Dec 16, 2021

Thanks for the fast answer.

I understand your situation, (I made both a GLTF-1 and GLTF-2/GLB reader/writer plus conversion to a 3d API in Java).

I can't help much because I don't know anything about Unity or C# ...

BUT I've been working with KTX-Software libktx for the last two weeks and figured out how to read/write and convert them to java API so I can give you the steps with libKTX at least and the matching GL format and GL internalformat.

If you could write juste one case then I believe it would be possible for me to write the others and send a merge request.

Here are the steps in pseudo-code :

ktxtexture2 tex = libktx.ktxTexture_CreateFromNamedFile("../r_reference_u.ktx2", KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT);
int level = 0;
int layer = 0;
int faceSlice = 0;
int textureWidth = tex.baseWidth;
int textureHeight = tex.baseHeight;

int offset = libktx.ktxTexture2_GetImageOffset(level, layer, faceSlice);
int nbBytes = libktx.ktxTexture2_GetImageSize(level);
byte[] rawData = new byte[nbBytes];

Pointer dataPointer = libktx.ktxTexture_GetData();
dataPointer.get(offset, rawData, 0, nbBytes);

switch (tex.vkFormat) {
  case VK_FORMAT_R8_UNORM : 
      // I don't know how to create a unity texture, but rawData contains tightly packed UInt8
      // that would be GL format : GL_RED and internalFormat : GL_R8
  . . .
}

r_reference_u.ktx2.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants