KTX - michaliskambi/x3d-tests GitHub Wiki
The point of the proposal is to add KTX (Khronos Texture Format) as a recommended format to be supported by X3D browsers.
- For 2D textures (ImageTexture node), at http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/texturing.html#ImageTexture (currently it recommends JPG, PNG, and (with less emphasis) GIF)
- For cubemap textures (ImageCubeMapTexture node), at http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/env_texture.html#ImageCubeMapTexture (currently it recommends DDS, to which KTX is a great alternative, see discussion below)
- For 3D textures (ImageTexture3D node), at http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/texture3D.html#ImageTexture3D (currently it recommends a number of formats including DDS). These textures are also useful with volume rendering ( http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/volume.html ).
Why
KTX is a Khronos standard, and it's really good for providing textures for modern rendering libraries (OpenGL, Direct3D, Vulkan...).
Features supported by both DDS and KTX:
- Supports GPU texture compression (S3TC, PVRTVC...). Note that there are various GPU compression algorithms (S3TC aka DXT*, PVRTC*, ATITC*, ETC*). Content creators using KTX or DDS with GPU texture compression must be aware that not all compression formats are available on all platforms, so it is wise to always provide an uncompressed texture version as an alternative to the compressed one, to work on all platforms.
- Supports 2D textures, 3D textures, cubemaps (6x 2D texture)
- Supports mipmaps (that is, mipmap information can be stored directly in the texture file; this usually results in better quality mipmaps than when you generate mipmaps at runtime)
- Texture arrays (something more flexible than 3D texture, since the number of slices doesn't have to be power of two)
Features only in KTX:
- 1D textures (useful e.g. to provide precalculated values of some function to shaders; e.g. the results of "sin(x)" could be expressed as a grayscale texture of size 1x256, and thus an approximate "sin(x)" can be implemented by a simple texture lookup (with some trivial mapping applied to adjust the input and output domain))
- KTX may be top-to-bottom or bottom-to-top. Thus, it is friendly to both Direct3D (that expects top-to-bottom data) and OpenGL (that expects bottom-to-top). In contrast, DDS only supports top-to-bottom, which means that you need to do tricks to make it supported in OpenGL (in case of CGE: when reading DDS, we invert on CPU non-compressed textures, and we expect the compressed textures to be already inverted; IOW, in each case, we effectively invert them twice in the pipeline PNG -> DDS -> CGE).
- KTX is a proper standard, with open specification developed by a coordination of various people at Khronos. In contrast, DDS "specification" is "whatever Microsoft is doing" ( https://en.wikipedia.org/wiki/DirectDraw_Surface , X3D bibliography http://www.web3d.org/documents/specifications/19775-1/V3.3/index.html just links to https://docs.microsoft.com/pl-pl/windows/desktop/direct3ddds/dx-graphics-dds-reference ).
KTX information
- https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
- https://www.khronos.org/opengles/sdk/tools/KTX/
Castle Game Engine documentation for DDS and KTX (contains various CGE implementation details, but also general info about KTX):
- https://castle-engine.io/x3d_implementation_texturing.php#section_dds
- https://castle-engine.io/x3d_implementation_texturing.php#section_ktx
Viewers:
- A number of viewers and converters are linked at https://www.khronos.org/opengles/sdk/tools/KTX/ (section "Working with KTX Files")
- I also have glViewImage, https://castle-engine.io/glviewimage.php , a viewer for various image formats (including KTX and DDS) handled by Castle Game Engine
glTF relation
KTX in glTF?
- Currently glTF doesn't mention KTX, only PNG and JPG.
- But they are working on it: https://github.com/KhronosGroup/glTF/issues/835 . The arguments there (cubemap support etc.) are similar to our arguments above for X3D.
License
- For libktx: https://www.khronos.org/opengles/sdk/tools/KTX/doc/libktx/licensing.html . Note: libktx is an open-source library from Khronos (optional, but certainly not required, to read KTX -- it's easy to read KTX without it, CGE does it, Michalis did it in three.js too). This is not a license relating to KTX specification.