Is the texture a normal map? #503
-
Is there some way to detect whether a supercompressed texture is meant to be decompressed to a normal map format (BC5 on PCs). This was an issue in Basis and I was hoping KTX would add this data to the file. I notice if I used the --normal_map setting the blue channel is removed, but how to detect this in the file format? |
Beta Was this translation helpful? Give feedback.
Replies: 14 comments
-
That data is available in the KTX file, please see Section 3.10.2. |
Beta Was this translation helpful? Give feedback.
-
This color model provides channel Ids, e.g. KHR_DF_CHANNEL_UASTC_RGB that must be used to indicate the effective number of components in the data. Consumers use this information to help select a transcode target. The following ids are valid and must be used for the type of data indicated. How does the color model provide channel IDs? I'm also looking in the output of toktx and it says all supercompression parameters will be stored in the file metadata: However, the resulting KTX files, when loaded with libktx, report a kvDataLen value of 0, and the kvData pointer is NULL. |
Beta Was this translation helpful? Give feedback.
-
Channel IDs are a part of DFD. The spec has an example of BasisLZ/ETC1S R+G texture. |
Beta Was this translation helpful? Give feedback.
-
Thank you but I don't understand that diagram. |
Beta Was this translation helpful? Give feedback.
-
It looks like ktxTexture2_GetNumComponents() can return this information, but on closer inspection, the two-channel color formats are treated as luminance / alpha: So relying on the number of channels may not be a good idea. |
Beta Was this translation helpful? Give feedback.
-
The number of channels may be the same but the channel IDs would be different for RG and LA, assuming that the KTX file was created with correct options. |
Beta Was this translation helpful? Give feedback.
-
Okay, here is how to detect that the --normal_map setting was used by the generator:
However, I would still like to be able to retrieve the channel IDs and use that as well. This setting only works with the ECTS compression method. |
Beta Was this translation helpful? Give feedback.
-
For anything but transcodable textures, I am thinking about adding a new metadata item @Leadwerks |
Beta Was this translation helpful? Give feedback.
-
@MarkCallow |
Beta Was this translation helpful? Give feedback.
-
This seems more versatile than guessing based on component counts and channel IDs. Some files may store a normal map in an uncompressed format, for example. The application could make more intelligent decisions about how to treat the file. I don't have a very strong preference as long as a method is chosen, but it does seem like something is needed for practical usage, at least when a transcodable format is in use. |
Beta Was this translation helpful? Give feedback.
-
You know, the question might not really be whether it's a normal map, but whether it should be transcoded into an RG format. This is only applicable to supercompressed textures, and those are always going to be transcoded into some memory-compressed format. No one is going to use lossy compression for an image and then decompress it to RGBA. If a supercompressed texture is stored with two channels, and those channels are red and green, I can't think of any reason those would not always be transcoded into BC5 format, at least on PC. |
Beta Was this translation helpful? Give feedback.
-
Exactly. And for this purpose ktxTexture2_GetNumComponents() provides the information you need. |
Beta Was this translation helpful? Give feedback.
-
Well, except for the channel IDs. I'll start with this approach but in the future I think a new command or some example code to detect the channels in use will be needed. |
Beta Was this translation helpful? Give feedback.
-
For transcodable textures |
Beta Was this translation helpful? Give feedback.
For transcodable textures
ktxTexture2_GetNumComponents()
uses the channel ids to determine the value it returns. You don't need any more information to determine an appropriate transcode target.