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

help! why the ktx2 not displayed? #1933

Closed
Niwei opened this issue Jan 21, 2021 · 14 comments
Closed

help! why the ktx2 not displayed? #1933

Niwei opened this issue Jan 21, 2021 · 14 comments

Comments

@Niwei
Copy link

Niwei commented Jan 21, 2021

I am green hand,use ktx2 not display。Please take a look for me。this model。Thank you
ktx2room

@donmccurdy
Copy link
Contributor

Hi! This is the issue tracker for the glTF file format, and not for any particular piece of software that uses glTF.

That said, the model you shared looks OK to me and displays reasonably in https://gltf-viewer.donmccurdy.com/:

Screen Shot 2021-01-20 at 6 47 45 PM

If you're not able to display the model in some other application, you may need to confirm that the application supports glTF's KHR_texture_basisu extension, and perhaps file a bug on that software.

@Niwei
Copy link
Author

Niwei commented Jan 21, 2021

嗨!这是glTF文件格式的问题跟踪器,而不是使用glTF的任何特定软件的问题跟踪器。

就是说,您共享的模型对我来说看起来不错,并在https://gltf-viewer.donmccurdy.com/中合理显示:

屏幕快照2021-01-20,6 47 45 PM

如果您无法在其他应用程序中显示模型,则可能需要确认该应用程序支持glTF的KHR_texture_basisu扩展,并可能在该软件上提交了错误。

OK,Thank you very much for your answer

@Niwei Niwei closed this as completed Jan 21, 2021
@bghgary
Copy link
Contributor

bghgary commented Jan 21, 2021

It looks like this in Babylon.js Sandbox. Not sure which is right.

image

@donmccurdy
Copy link
Contributor

donmccurdy commented Jan 22, 2021

Hm on closer look, the textures aren't loading in three.js. There's an error showing up in the console repeatedly,

WebGL warning: drawElementsInstanced: TEXTURE_2D at unit 0 is incomplete: Bad mipmap dimension or format.

The textures themselves look fine, so perhaps we have something implemented incorrectly in three.js for the upcoming KHR_texture_basisu extension. I'll look into that more, but it might have been fixed in mrdoob/three.js#20888.

@Niwei
Copy link
Author

Niwei commented Jan 22, 2021

It looks like this in Babylon.js Sandbox. Not sure which is right.

image

Thank you very much.Babylon.js Sandbox display is right. I'll try to use Babylon.js

@donmccurdy
Copy link
Contributor

donmccurdy commented Jan 23, 2021

I've found the cause here — the textures specify sampler minFilter/magFilter values that require mipmaps, but the .ktx2 textures embedded here do not include mipmaps. If you're generating the textures with toktx, there's a --genmipmap option that will fix this.

If this model was created by hand, you could also consider using the glTF-Transform CLI to compress textures in the entire file for you:

gltf-transform etc1s whwd.gltf ktx2room-compressed.glb --verbose

The result will render correctly in both engines:

ktx2room.glb.zip

From the spec,

When a texture refers to a sampler with mipmap minification or when the sampler is undefined, the KTX image SHOULD contain a full mip pyramid.

Implementation Note: Depending on the platform features available, engines may need to decompress the texture and generate missing mipmaps at runtime when a full mip pyramid is not available.

@bghgary do you know what babylon.js is doing here? I thought it wasn't possible to generate mipmaps for compressed textures in WebGL, and I don't think I want to decompress the textures in cases like this. 🤔

@donmccurdy
Copy link
Contributor

I'll also flag that the .ktx2 files have layerCount = 1, and the KTX Specification says...

layerCount specifies the number of array elements. If the texture is not an array texture, layerCount must equal 0.

... is this a bug in exporting software?

ktxinfo
Header

identifier: «KTX 20»\r\n\x1A\n
vkFormat: VK_FORMAT_UNDEFINED
typeSize: 3
pixelWidth: 2048
pixelHeight: 2048
pixelDepth: 0
layerCount: 1
faceCount: 1
levelCount: 1
supercompressionScheme: KTX_SS_BASIS_LZ
dataFormatDescriptor.byteOffset: 0x68
dataFormatDescriptor.byteLength: 44
keyValueData.byteOffset: 0x94
keyValueData.byteLength: 92
supercompressionGlobalData.byteOffset: 0xf0
supercompressionGlobalData.byteLength: 8600

Level Index

Level0.byteOffset: 0x2288
Level0.byteLength: 190462
Level0.uncompressedByteLength: 0

Data Format Descriptor

DFD total bytes: 44
BDB descriptor type 0x0000 vendor id = 0x00000
Descriptor block size 40 (1 samples) versionNumber = 0x0002
Flags 0x00 Xfer 02 Primaries 01 Model 163
Dimensions: 4,4,1,1
Plane bytes: 0,0,0,0,0,0,0,0
    Sample 0
Qualifiers 0 Channel 0x0 (RGB) Length 64 bits Offset 0
Position: 0,0,0,0
Lower 0x00000000
Upper 0xffffffff

KeyValue Data

KTXwriter: ktxsc v4.0.0-beta6~6 / libktx v4.0.0-beta6~2
KTXwriterScParams: --bcmp

Basis Supercompression Global Data

endpointCount: 1486
selectorCount: 2655
endpointsByteLength: 2749
selectorsByteLength: 4248
tablesByteLength: 1563
extendedByteLength: 0

imageFlags: 0
rgbSliceByteLength: 190462
rgbSliceByteOffset: 0
alphaSliceByteLength: 0
alphaSliceByteOffset: 0

@donmccurdy
Copy link
Contributor

@Niwei could you share the steps you are taking to convert your textures to .ktx2? I think there is a bug in a conversion program somewhere here, but I can't reproduce it even with the same version of KTX-Software.

@Niwei
Copy link
Author

Niwei commented Jan 25, 2021

@Niwei could you share the steps you are taking to convert your textures to .ktx2? I think there is a bug in a conversion program somewhere here, but I can't reproduce it even with the same version of KTX-Software.

ok , I use KTX-Software-4.0.0-beta6-win64, and the cli

toktx --t2 --bcmp xxx xxx.jpg

But a few days ago, one of the jpg I used --genmipmap or --automipmap also not right in three.js

@donmccurdy
Copy link
Contributor

Thanks! I wasn't able to reproduce the layerCount = 1 issue seen above, I guess that is a mystery.

But a few days ago, one of the jpg I used --genmipmap or --automipmap also not right in three.js

three.js cannot support --automipmap, or at least I'm not aware of any way to generate mipmaps for compressed textures in WebGL. Using --genmipmap is generally the right choice. But there are other reasons the texture might fail too. It is almost always necessary to use textures with power-of-two dimensions, like 1024x1024. If you have other .ktx2 files that aren't working properly in three.js, feel free to post in the three.js forums as well, and we can help more there: https://discourse.threejs.org/

@Niwei
Copy link
Author

Niwei commented Jan 25, 2021

@dodgyville Thanks! I have learned a lot!

@bghgary
Copy link
Contributor

bghgary commented Jan 26, 2021

@bghgary do you know what babylon.js is doing here? I thought it wasn't possible to generate mipmaps for compressed textures in WebGL, and I don't think I want to decompress the textures in cases like this. 🤔

@Popov72 Can you take a look?

@Popov72
Copy link

Popov72 commented Jan 26, 2021

We don't generate mimaps in Babylon.js, as you said it's not really possible.

What happens is that even if the gltf file is saying to use mipmapping for the min filter, the engine overrides the value and disables mipmapping because the textures don't have mipmaps.

@donmccurdy
Copy link
Contributor

I see — thanks! That does seem like a good fallback then, perhaps with a warning logged.

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

No branches or pull requests

4 participants