mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.8k stars 35.31k forks source link

Expand KTX2Loader to support RGB formats #27174

Closed krispya closed 10 months ago

krispya commented 10 months ago

Description

Currently the KTX2Loader supports RGBA, RG and Red formats: https://github.com/mrdoob/three.js/blob/d9817318e7a2cea5ed1fb62416d9f8a3863f2013/examples/jsm/loaders/KTX2Loader.js#L719

I'd like to see RGB formats included as well. The main use case I have is converting HDRI to KTX2. An EXR or HDR file from PolyHaven will be RGB out of the box and require some image processing to add a dummy A channel. ktx create needs channel parity so it wants to create R32G32B32_SFLOAT textures from this input. Ideally, I could do this process and input it directly into Three.

Solution

I'm not sure how the internals with texture formats work. If RGB can be supported out of the box or if an alpha channel needs to be added.

Alternatives

The alternative is add an image processing step and maybe add to docs the supported formats so the information is easier to track down.

Additional context

No response

donmccurdy commented 10 months ago

ktx create needs channel parity so it wants to create R32G32B32_SFLOAT textures from this input. Ideally, I could do this process and input it directly into Three.

This is a limitation in the current alpha release of KTX Software, and has already been fixed on main, but an updated alpha release hasn't been published yet. Prominent APIs (Metal, for example) underneath WebGL and WebGPU do not support RGB8, so I would avoid it if you can. Also see:

There are still workarounds possible in three.js to manually use RGBFormat, but I'm not sure KTX2Loader should apply those automatically.

krispya commented 10 months ago

Ah! I appreciate the information. Texture formats has been a big learning experience. Hopefully this ticket helps someone else who is wondering the same thing.