microsoft / DirectXTex

DirectXTex texture processing library
https://walbourn.github.io/directxtex/
MIT License
1.74k stars 426 forks source link

UINT and SINT formats in texconv #482

Open Puxtril opened 2 weeks ago

Puxtril commented 2 weeks ago

The help menu for texconv lists many DXGI formats of type UINT and SINT. Whenever I try to convert textures (from png/jpg) to these formats, texconv seems to output incorrect textures. Looking at the output in a hex editor, UINT and SINT only contain bytes of value 0 or 1. Is this intended behavior?

Textures.zip

walbourn commented 2 weeks ago

The values coming out of the PNG are expressed in float-point numbers which will be 0 to 1. When storing them as UINT or SINT, it's going to result in 0 or 1. If you want the values to range for all the supported integers, that is what UNORM and SNORM do.

Puxtril commented 2 weeks ago

So in this case, it sounds like an issue with PNGs storing data as floats. Is there an input format that works better for this conversion?

walbourn commented 2 weeks ago

All image processing in DirectXTex is done with floating-point to take advantage of SIMD operations.

What is it you expect to happen converting a classic 8-bit UNORM image to a 32-bit UINT image?

Puxtril commented 2 weeks ago

I just expected the end result to be similar to UNORM/SNORM conversions, considering the documentation on Microsoft states the underlying storage format for UNORM/UINT are identical (unsigned integer). And since texconv converted without throwing an error, I was confused why end results varied so much. It was a misunderstanding on my part.

I'm using texconv to generate test data for a project I'm working on using a random png I found online. Now I'm just wondering what would be a better source format to use for generating a valid UINT/SINT image.

walbourn commented 2 weeks ago

There are special conversion cases for doing to/from UNORM/SNORM formats which are not applied to UINT/SINT. This in large part because UINT/SINT doesn't have any specific meaning in textures: it's just a raw format used by compute shaders.

I'm open to adding some special conversion here, but it's not clear to me what is the logical behavior.

Puxtril commented 1 week ago

I don't have any ideas for conversions, as I'm not familiar with UINT/SINT in standard use cases. But now I have a better understanding of how texconv sees those formats (doesn't do any conversion).

I'm fine with closing the issue as my questions have been answered.