1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-21 12:00:06 +00:00
8 ScaleMipMapsAlphaForCoverage
Chuck Walbourn edited this page 2022-01-20 17:41:58 -08:00
DirectXTex

Scales mipmap alpha values to preserve alpha coverage based on an alpha test reference value.

This is intended for use after generating mipimaps with GenerateMipMaps. It does not support volume mipmaps.

HRESULT ScaleMipMapsAlphaForCoverage(
    const Image* srcImages, size_t nimages, const TexMetadata& metadata, size_t item,
    float alphaReference, ScratchImage& mipChain);

Parameters

srcImages: The image array of miplevels to use as the image source which has nimages images. The first level of the resulting mipChain is set to a copy of the first image. Each level after that contains the same RGB data as the matching miplevel source image, but the alpha value is scaled.

metadata: Metadata describing the texture. The info.mipLevels value should match the nimages value passed to this function.

item: Is used when processing texture arrays to look up the right entry in mipChain.

alphaReference: Is the alpha test reference value which ranges from 0 to 1.

mipChain: Is where the results are written. Generally it should be created to match the mipChain returned by GenerateMipMaps and then this function is called once for each array item to set all the values.

Example

ScratchImage baseImage;

...

ScratchImage mipChain;
hr = GenerateMipMaps( baseImage.GetImages(), baseImage.GetImageCount(),
    baseImage.GetMetadata(), TEX_FILTER_DEFAULT, 0, mipChain );
if ( FAILED(hr) )
    

auto& info = mipChain.GetMetadata();
ScratchImage coverageMipChain;
hr = coverageMipChain.Initialize(info);
if (FAILED(hr))
   

for (size_t item = 0; item < info.arraySize; ++item)
{
    auto img = mipChain.GetImage(0, item, 0);
    assert(img);

    hr = ScaleMipMapsAlphaForCoverage(img, info.mipLevels, info, item, 0.5f,
        coverageMipChain);
    if (FAILED(hr))
        
}

Remarks

This function does not operate directly on block compressed images. See Decompress and Compress.

This function cannot operate directly on a planar format image. See ConvertToSinglePlane for a method for converting planar data to a format that is supported by this routine.

Further reading

Computing Alpha Mipmaps