Skip to content

ScaleMipMapsAlphaForCoverage

Chuck Walbourn edited this page Jan 21, 2022 · 8 revisions
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

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Windows 7 Service Pack 1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • GCC 10.5, 11.4, 12.3
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectXTex Rust bindings

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally