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

DDS BC5 / ATI2 (3Dc) support #5919

Closed
expenses opened this issue Jan 2, 2023 · 8 comments
Closed

DDS BC5 / ATI2 (3Dc) support #5919

expenses opened this issue Jan 2, 2023 · 8 comments

Comments

@expenses
Copy link

expenses commented Jan 2, 2023

Is your feature request related to a problem? Please describe.

I'd like to be able to convert BC5 .DDS normal maps with imagemagick. Here's a sample:

Wood_Normal.dds.zip

Describe the solution you'd like

Support :D

Describe alternatives you've considered

Gimp supports loading these files, but it's annoying to script. Renderdoc loads these files as well.

Additional context

See https://en.wikipedia.org/wiki/3Dc

Maister has written about compressed GPU textures: https://themaister.net/blog/2020/08/12/compressed-gpu-texture-formats-a-review-and-compute-shader-decoders-part-1/ and has implemented a BC5 decoder at: https://github.com/Themaister/Granite/blob/master/assets/shaders/decode/rgtc.comp

@mmomtchev
Copy link
Contributor

@expenses can you please test my PR, I have a limited number of test files that are all from the same source

@dlemstra
Copy link
Member

dlemstra commented Feb 7, 2023

What should be the output of your image @expenses? When I use the code from @mmomtchev their PR I get the following output image:

z

@expenses
Copy link
Author

expenses commented Feb 8, 2023

Looks like it's decoding correctly, but the blue channel isn't being derived. This is how it looks in gimp:

20230208_10h50m14s_grim

So I don't know too much about this format, except that it's presumably intended for normal maps. Normals are vectors with a length of 1, but because non-HDR images can't handle negative numbers, they're encoded by mapping the values from -1 to +1 to 0 to +1. Afaik, the blue channel can be derived with B = sqrt(1.0 - R^2 - G^2). I haven't had time to check how gimp does this.

@expenses
Copy link
Author

expenses commented Feb 8, 2023

https://developer.nvidia.com/orca/amazon-lumberyard-bistro contains a scene with a large number of DDS textures if you want something to test this on.

@mmomtchev
Copy link
Contributor

@expenses, this is a compression scheme that can encode only 2 colors. It's advantage is that these are encoded at almost full precision with only 4 bits per pixel. It is frequently used to encode floating point data such as splatmaps - instead of actual image data. The real question is how are the colors selected if the image is rendered as an image, because I simply take them to be Red and Green - as defined by Microsoft. Could it be that GIMP does something else?

@mmomtchev
Copy link
Contributor

There are two encoding schemes, BC5_UNORM and BC5_SNORM - which are essentially the same - except for the fact that SNORM is to be interpreted as -1.0f to 1.0f, while UNORM is 0.0f to 1.0f. I didn't implement SNORM because it didn't make any sense in this context. Maybe I should just treat it as UNORM - the other DDS encoders do this.

@mmomtchev
Copy link
Contributor

No, in fact this is not true, no DDS codec in ImageMagick supports any _SNORM encoding, so this is staying like this.

@express texture opened with Microsoft tools (Visual Studio with DirectX development) is also red/green - AFAIK - there is no color selection information - there are simply two channels and Microsoft refers them as Red and Green.

@fmw42
Copy link

fmw42 commented Feb 8, 2023

If you have only two channels of data, then typically the third channel is just set to zero (black).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants