microsoft/DirectXTex

Color information is lost on transparent pixels when using GenerateMipMaps

Llerd opened this issue · 3 comments

Llerd commented

When using ::GenerateMipMaps to generate mipmaps on a texture with color-information stored in pixels that has a zero alpha-value, the color-information seems to be cleared. Is this intended behavior? I expected it to retain the color-information.

WIC uses premultiplied-alpha by default, which means 0 alpha will result in 0 R,G,B.

One option is to use TEX_FILTER_SEPARATE_ALPHA which resizes the alpha independently from the color, which is typically used if the alpha channel is not actually alpha data and the pm alpha would destroy it.

Another option is to use TEX_FILTER_FORCE_NON_WIC which avoids using WIC entirely for the filtering even in cases that can in theory work with it. These paths do not force the use of pm alpha.

Llerd commented

Using TEX_FILTER_SEPARATE_ALPHA didn't help, and the color-data was still cleared.
TEX_FILTER_FORCE_NON_WIC worked as long as I didn't use the BOX filter (which did not work for non pow2 textures).

Thanks for the info!

Makes sense. With TEX_FILTER_SEPARATE_ALPHA, it is still using WIC for the color channel blending.

The non-WIC version of TEX_FILTER_BOX requires power of 2. I'll note that on the wiki.