Quantcast
Viewing all 1174 articles
Browse latest View live

Created Unassigned: Invalid result of MakeTypeless for DXGI_FORMAT_A8_UNORM [1330]

For DXGI_FORMAT_A8_UNORM MakeTypeless returns DXGI_FORMAT_R8_TYPELESS, which is invalid (color channel mismatch).
For example, we can't do CopyResource beetween DXGI_FORMAT_A8_UNORM and DXGI_FORMAT_R8_*

Commented Unassigned: Invalid result of MakeTypeless for DXGI_FORMAT_A8_UNORM [1330]

For DXGI_FORMAT_A8_UNORM MakeTypeless returns DXGI_FORMAT_R8_TYPELESS, which is invalid (color channel mismatch).
For example, we can't do CopyResource beetween DXGI_FORMAT_A8_UNORM and DXGI_FORMAT_R8_*
Comments: Ok, so DXGI_FORMAT_A8_UNORM should return DXGI_FORMAT_A8_UNORM with MakeTypeless. Thanks for the report!

Source code checked in, #1167ebb9c7615a1f515903b12e61ab3e98209315

DXGI_FORMAT_A8_UNORM is not compatible with DXGI_FORMAT_R8_TYPELESS

Edited Issue: Invalid result of MakeTypeless for DXGI_FORMAT_A8_UNORM [1330]

For DXGI_FORMAT_A8_UNORM MakeTypeless returns DXGI_FORMAT_R8_TYPELESS, which is invalid (color channel mismatch).
For example, we can't do CopyResource beetween DXGI_FORMAT_A8_UNORM and DXGI_FORMAT_R8_*

Closed Issue: Invalid result of MakeTypeless for DXGI_FORMAT_A8_UNORM [1330]

For DXGI_FORMAT_A8_UNORM MakeTypeless returns DXGI_FORMAT_R8_TYPELESS, which is invalid (color channel mismatch).
For example, we can't do CopyResource beetween DXGI_FORMAT_A8_UNORM and DXGI_FORMAT_R8_*
Comments: Fix submitted as changelist 1167ebb9c761

Updated Wiki: Filter Flags

enum TEX_FILTER_FLAGS
  • TEX_FILTER_DEFAULT Default flags

Algorithm

This selects the filtering mode used for resizing and mipmap generation. In most cases it defaults to using "Fant" (aka "Box").
  • TEX_FILTER_POINT Nearest neighbhor
  • TEX_FILTER_LINEAR Bilinear/Trilinear interpolation
  • TEX_FILTER_CUBIC Bicubic/Tricubic interpoloation
  • TEX_FILTER_FANT Fant which is euivalent to a box filter for down-scaling.
  • TEX_FILTER_BOX Box filter (alias for Fant since they are equivalent for down-scaling).
  • TEX_FILTER_TRIANGLE Finite low-pass triangle filter.

The legacy D3DX library implemented Point, Linear, Box, and Triangle

Dithering

This selects the use of dithering for format conversions. By default it uses no dithering.

Wrap mode

This controls how edge pixels are filtered. It defaults to CLAMP which is the only one supported by the WIC code paths. These have no impact on POINT or BOX filtering methods.
  • TEX_FILTER_WRAP_U
  • TEX_FILTER_WRAP_V
  • TEX_FILTER_WRAP_W
  • TEX_FILTER_WRAP These indicates the texture will be used with wrap texture addressing modes D3D11_TEXTURE_ADDRESS_WRAP in U, V, and/or W. This affects Linear, Cubic, and Triangle filtering.
  • TEX_FILTER_MIRROR_U
  • TEX_FILTER_MIRROR_V
  • TEX_FILTER_MIRROR_W
  • TEX_FILTER_MIRROR These indicates the texture will be used with mirror texture addressing modes D3D11_TEXTURE_ADDRESS_MIRROR in U, V, and/or W. This affects Cubic filtering. For Linear and Triangle filtering, MIRROR and the default of clamp give the same result.

Color space

This controls color space transformation for conversions.
  • TEX_FILTER_SRGB_IN Indicates the input format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_FILTER_SRGB_OUT Indicates the output format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_FILTER_SRGB This is the same as setting both TEX_FILTER_SRGB_IN and TEX_FILTER_SRGB_OUT

The sRGB color space overall is approximately equivalent to gamma 2.2. It's actually linear below a threshold, and gamma 2.4 beyond that.
http://en.wikipedia.org/wiki/SRGB

WIC usage

When both WIC-based and non-WIC based codepaths are in place, these flags can influence the standard logic choice. These are primarily used for testing and debugging purposes.
  • TEX_FILTER_FORCE_NON_WIC
  • TEX_FILTER_FORCE_WIC
  • TEX_FILTER_SEPARATE_ALPHA WIC makes use of pre-multiplied alpha when resizing images, which works fine for standard transparency data. If the alpha channel, however, contains some other kind of value then the resulting image can have 'holes' in it. Use of this flag uses an alternative algorithm which resizes the RGB and alpha channels independantly and then recombines the result. This flag is not used by the non-WIC code paths, but will cause the Convert() function to use non-WIC paths.

Convert channel selection

For Convert operations, these flags control special-case logic in the non-WIC paths. Without these flags, RGB to R conversions default to converting to a luminance value and RGB to RG conversion defaults to copying the RED and GREEN channels. These are implemented in the non-WIC code paths.
  • TEX_FILTER_RGB_COPY_RED When converting from RGB to R formats, this indicates that the RED channel could be copied. For RGB to RG conversions, it can be combined with GREEN or BLUE to control which channels end up in the output.
  • TEX_FILTER_RGB_COPY_GREEN When converting from RGB to R formats, this indicates that the GREEN channel could be copied. For RGB to RG conversions, it can be combined with RED or BLUE to control which channels end up in the output.
  • TEX_FILTER_RGB_COPY_BLUE When converting from RGB to R formats, this indicates that the BLUE channel could be copied. For RGB to RG conversions, it can be combined with RED or GREEN to control which channels end up in the output.

Updated Wiki: Filter Flags

enum TEX_FILTER_FLAGS

TEX_FILTER_DEFAULT Default flags

Algorithm

This selects the filtering mode used for resizing and mipmap generation. In most cases it defaults to using "Fant" (aka "Box").
  • TEX_FILTER_POINT Nearest neighbhor
  • TEX_FILTER_LINEAR Bilinear/Trilinear interpolation
  • TEX_FILTER_CUBIC Bicubic/Tricubic interpoloation
  • TEX_FILTER_FANT Fant which is euivalent to a box filter for down-scaling.
  • TEX_FILTER_BOX Box filter (alias for Fant since they are equivalent for down-scaling).
  • TEX_FILTER_TRIANGLE Finite low-pass triangle filter.

The legacy D3DX library implemented Point, Linear, Box, and Triangle

Dithering

This selects the use of dithering for format conversions. By default it uses no dithering.

Wrap mode

This controls how edge pixels are filtered. It defaults to CLAMP which is the only one supported by the WIC code paths. These have no impact on POINT or BOX filtering methods.
  • TEX_FILTER_WRAP_U
  • TEX_FILTER_WRAP_V
  • TEX_FILTER_WRAP_W
  • TEX_FILTER_WRAP These indicates the texture will be used with wrap texture addressing modes D3D11_TEXTURE_ADDRESS_WRAP in U, V, and/or W. This affects Linear, Cubic, and Triangle filtering.
  • TEX_FILTER_MIRROR_U
  • TEX_FILTER_MIRROR_V
  • TEX_FILTER_MIRROR_W
  • TEX_FILTER_MIRROR These indicates the texture will be used with mirror texture addressing modes D3D11_TEXTURE_ADDRESS_MIRROR in U, V, and/or W. This affects Cubic filtering. For Linear and Triangle filtering, MIRROR and the default of clamp give the same result.

Color space

This controls color space transformation for conversions.
  • TEX_FILTER_SRGB_IN Indicates the input format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_FILTER_SRGB_OUT Indicates the output format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_FILTER_SRGB This is the same as setting both TEX_FILTER_SRGB_IN and TEX_FILTER_SRGB_OUT

The sRGB color space overall is approximately equivalent to gamma 2.2. It's actually linear below a threshold, and gamma 2.4 beyond that.
http://en.wikipedia.org/wiki/SRGB

WIC usage

When both WIC-based and non-WIC based codepaths are in place, these flags can influence the standard logic choice. These are primarily used for testing and debugging purposes.
  • TEX_FILTER_FORCE_NON_WIC
  • TEX_FILTER_FORCE_WIC

TEX_FILTER_SEPARATE_ALPHA WIC makes use of pre-multiplied alpha when resizing images, which works fine for standard transparency data. If the alpha channel, however, contains some other kind of value then the resulting image can have 'holes' in it. Use of this flag uses an alternative algorithm which resizes the RGB and alpha channels independantly and then recombines the result. This flag is not used by the non-WIC code paths, but will cause the Convert() function to use non-WIC paths.

Convert channel selection

For Convert operations, these flags control special-case logic in the non-WIC paths. Without these flags, RGB to R conversions default to converting to a luminance value and RGB to RG conversion defaults to copying the RED and GREEN channels. These are implemented in the non-WIC code paths.
  • TEX_FILTER_RGB_COPY_RED When converting from RGB to R formats, this indicates that the RED channel could be copied. For RGB to RG conversions, it can be combined with GREEN or BLUE to control which channels end up in the output.
  • TEX_FILTER_RGB_COPY_GREEN When converting from RGB to R formats, this indicates that the GREEN channel could be copied. For RGB to RG conversions, it can be combined with RED or BLUE to control which channels end up in the output.
  • TEX_FILTER_RGB_COPY_BLUE When converting from RGB to R formats, this indicates that the BLUE channel could be copied. For RGB to RG conversions, it can be combined with RED or GREEN to control which channels end up in the output.

Updated Wiki: CaptureTexture

Captures a Direct3D 11 render target and returns an image.

This function is intended for use with tools or editor programs. For runtime/engine use, we strongly recommend using ScreenGrab instead of DirectXTex.

HRESULT CaptureTexture( _In_ ID3D11Device* pDevice,
    _In_ ID3D11DeviceContext* pContext,
    _In_ ID3D11Resource* pSource,
    _Out_ ScratchImage& result );

Example

ScratchImage image;
HRESULT hr = CaptureTexture( device, context, pResource, image );
if ( SUCCEEDED(hr) )
{
    hr = SaveToDDSFile( image.GetImages(), image.GetImageCount(), image.GetMetadata(), 
        DDS_FLAGS_NONE, filename );
    if ( FAILED(hr) )
    {
        ...

Remarks

This function can support capturing 1D, 1D array, 2D, 2D array, cubemap, cubemap array, and 3D textures in the full range of DXGI formats.

MSAA textures are resolved before being captured.

Updated Wiki: FlipRotate

Flip and/or rotate an image.

HRESULT FlipRotate( _In_ const Image& srcImage, _In_ DWORD flags,
    _Out_ ScratchImage& image );

HRESULT FlipRotate( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata, _In_ DWORD flags,
    _Out_ ScratchImage& result );

Parameters

flags: Combination of options to apply

Optionally a rotation
  • TEX_FR_ROTATE0 Rotate by 0 degrees (no-op)
  • TEX_FR_ROTATE90 Rotate by 90 degrees
  • TEX_FR_ROTATE180 Rotate by 180 degrees
  • TEX_FR_ROTATE270 Rotate by 270 degrees

Optionally a flip
  • TEX_FR_FLIP_HORIZONTAL Horizonal flip
  • TEX_FR_FLIP_VERTICAL Vertical flip

Example

ScratchImage srcImage;

...

ScratchImage destImage;
hr = FlipRotate( srcImage.GetImages(), srcImage.GetImageCount(), srcImage.GetMetadata(),
        TEX_FR_FLIP_HORIZONTAL, destImage );
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.

Updated Wiki: Resize

Resize an image or set of images.

Note: that if given a set of images, the resulting ScratchImage will always have mipLevels of 1 (i.e. any mipmaps from the original are discarded)

HRESULT Resize( _In_ const Image& srcImage,
    _In_ size_t width, _In_ size_t height, _In_ DWORD filter,
    _Out_ ScratchImage& image );

HRESULT Resize( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ size_t width, _In_ size_t height, _In_ DWORD filter,
    _Out_ ScratchImage& result );

Parameters

filter: See Filter Flags

If using TEX_FILTER_DEFAULT, this routine will default to using FANT if using the WIC code paths. If using the non-WIC codepaths, it defaults to BOX if the destination image is half the size in both dimensions of the source image, otherwise it defaults to LINEAR.

Example

ScratchImage srcImage;

...

ScratchImage destImage;
hr = Resize( srcImage.GetImages(), srcImage.GetImageCount(), srcImage.GetMetadata(),
   100, 50, TEX_FILTER_DEFAULT, destImage );
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.

The second version of Resize is intended for working with 1D arrays, 2D arrays, cubemaps, and cubemap arrays with mipmaps.

This function is implemented with both WIC and non-WIC code paths. The WIC code paths are used for > 8-bit color depth formats, sRGB color formats, or when WRAP/MIRROR semantics are requested.

Release Notes

  • When resizing HDR images, be sure to stick with the default of TEX_FILTER_FANT when using WIC as the WIC bitmap scaler has limited supported for high bit-depth and extended range formats. By default, the DirectXTex library chooses to use non-WIC codepaths when generating mipmaps for > 8 color-depth images with LINEAR or CUBIC filtering.

Updated Wiki: GenerateMipMaps

Generates mipmaps for an image or a set of images.

Note: This generates mipmaps for 1D and 2D dimension textures. For 3D dimension textures, see GenerateMipMaps3D.

HRESULT GenerateMipMaps( _In_ const Image& baseImage, _In_ DWORD filter,
    _In_ size_t levels,
    _Inout_ ScratchImage& mipChain, _In_ bool allow1D = false );

HRESULT GenerateMipMaps( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DWORD filter, _In_ size_t levels,
    _Inout_ ScratchImage& mipChain );

Parameters

baseImage: The mipmap chain is created by repeatedly down-sizing a base image. The first level of the resulting mipChain is set to a copy of the input baseImage.

filter: See Filter Flags

levels: Number of mip map levels including base. A value of 0 indicates creating a full mipmap chain down to 1x1

allow1D: If set to true and given an input baseImage with a height of 1 then the resulting mipChain will be a TEX_DIMENSION_TEXTURE1D. Otherwise the resulting mipChain is a TEX_DIMENSION_TEXTURE2D.

Example

ScratchImage baseImage;

...

ScratchImage mipChain;
hr = GenerateMipMaps( baseImage.GetImages(), baseImage.GetImageCount(), baseImage.GetMetadata(), TEX_FILTER_DEFAULT, 0, mipChain );
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.

The second version of GenerateMipMaps is intended for working with 1D arrays, 2D arrays, cubemaps, and cubemap arrays with mipmaps. For volume maps, see GenerateMipMaps3D

This function is implemented with both WIC and non-WIC code paths. The WIC code paths are used for > 8-bit color depth formats, sRGB color formats, or when WRAP/MIRROR semantics are requested.

Release Notes

  • When resizing HDR images, be sure to stick with the default of TEX_FILTER_FANT when using WIC as the WIC bitmap scaler has limited supported for high bit-depth and extended range formats. By default, the DirectXTex library chooses to use non-WIC codepaths when generating mipmaps for > 8 color-depth images with LINEAR or CUBIC filtering.

Updated Wiki: GenerateMipMaps3D

Generates mipmaps for a 3D volume texture from a set of images representing the slices.

Note: This generates mipmaps for 3D dimension textures. For 1D and 2D dimension textures, see GenerateMipMaps.

HRESULT GenerateMipMaps3D( _In_reads_(depth) const Image* baseImages, _In_ size_t depth,
    _In_ DWORD filter, _In_ size_t levels,
    _Out_ ScratchImage& mipChain );

HRESULT GenerateMipMaps3D( _In_reads_(nimages) const Image* srcImages,
    _In_ size_t nimages, _In_ const TexMetadata& metadata,
    _In_ DWORD filter, _In_ size_t levels, _Out_ ScratchImage& mipChain );

Parameters

baseImages/srcImages: The mipmap chain is created by repeatedly down-sizing the slices of base images. The first level of the resulting mipChain is set to a copy of the input baseImages.

depth: The Z dimension of the volume texture which is also the number of slices in the baseImages array.

filter: See Filter Flags. Note that for non-power-of-2 depth volume maps, only TEX_FILTER_TRIANGLE will give the expected results. It therefore defaults to Triangle for non-pow-of-2 volume maps, otherwise it defaults to Fant/Box.

levels: Number of mip map levels including base. A value of 0 indicates creating a full mipmap chain down to 1x1x1.

Example

ScratchImage baseImages;

...

ScratchImage mipChain;
hr = GenerateMipMaps3D( baseImages.GetImages(), baseImages.GetImageCount(), baseImages.GetMetadata(), TEX_FILTER_DEAFULT, 0, mipChain );
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.

Each miplevel of a 3D volume texture is half the size in width & height and half the number of slices of the one above to a minimum of 1.

This function does not make use of WIC for resizing since volume textures require 3D filtering methods.

Note: All slices in a miplevel must be in contiguous memory for working with Direct3D 11, which is how ScratchImage is implemented.

Updated Wiki: PremultiplyAlpha

This converts an image assuming the original is not using premultiplied alpha into a premultiplied alpha version of the same image. The format and size are not changed.

Breaking Change notice: The 'flags' parameter was not present in the August 2013 and previous versions of DirectXTex.

HRESULT PremultiplyAlpha( _In_ const Image& srcImage, _In_ DWORD flags,
    _Out_ ScratchImage& image );

HRESULT PremultiplyAlpha( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata, _In_ DWORD flags,
    _Out_ ScratchImage& result );

Parameters

flags: Combination of options to apply
  • PMALPHA_IGNORE_SRGB Ignore any sRGB colorspace conversions

This controls color space transformation for conversions.
  • TEX_PMALPHA_SRGB_IN Indicates the input format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_PMALPHA_SRGB_OUT Indicates the output format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_PMALPHA_SRGB This is the same as setting both TEX_PMALPHA_SRGB_IN and TEX_PMALPHA_SRGB_OUT

Example

ScratchImage srcImage;

...

ScratchImage destImage;
hr = PremultiplyAlpha( srcImage.GetImages(), srcImage.GetImageCount(), srcImage.GetMetadata(), TEX_PMALPHA_DEFAULT destImage );
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.

This is most useful for working with rendering that relies on premultiplied alpha blending (see DirectXTK).

Related Links

http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx
http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BPremultiplied%20alpha%5D%5D
http://ssp.impulsetrain.com/2011-08-10_Gamma_Correction_vs__Premultiplied_Pixels.html

Updated Wiki: ComputeNormalMap

Converts a height-map to a normal-map.

HRESULT ComputeNormalMap( _In_ const Image& srcImage, _In_ DWORD flags,
    _In_ float amplitude, _In_ DXGI_FORMAT format,
    _Out_ ScratchImage& normalMap );

HRESULT ComputeNormalMap( _In_reads_(nimages) const Image* srcImages,
    _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format,
    _Out_ ScratchImage& normalMaps );

Parameters

flags: a combination of the following flags
  • CNMAP_DEFAULT Default flags

Selects which channel to use as the height. Luminance is the average of R, G, and B.
  • CNMAP_CHANNEL_RED
  • CNMAP_CHANNEL_GREEN
  • CNMAP_CHANNEL_BLUE
  • CNMAP_CHANNEL_ALPHA
  • CNMAP_CHANNEL_LUMINANCE

Selects mirroring semantics for scanline references. Otherwise defaults to wrap.
  • CNMAP_MIRROR_U
  • CNMAP_MIRROR_V
  • CNMAP_MIRROR Same as both CNMAP_MIRROR_U and CNMAP_MIRROR_V
  • CNMAP_INVERT_SIGN Inverts the sign of the computed normal vector
  • CNMAP_COMPUTE_OCCLUSION Computes a crude occlusion term and stores in the resulting alpha channel

amplitude: Scaling factor for normals

format: Format of the resulting ScratchImage

Example

ScratchImage hmapImage;

...

ScratchImage normalMap;
hr = ComputeNormalMap( hmapImage.GetImage(0,0,0), CNMAP_CHANNEL_LUMINANCE | CNMAP_COMPUTE_OCCLUSION, 2.f, DXGI_FORMAT_R8G8B8A8_UNORM, normalMap );
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.

This method computes the normal by using the central difference with a kernel size of 3x3. The central differencing denominator used is 2.0. RGB channels in the destination contain biased (x,y,z) components of the normal.

Updated Wiki: CopyRectangle

Copies a rectangle of pixels from one image to another.

HRESULT CopyRectangle( _In_ const Image& srcImage, _In_ const Rect& srcRect,
   _In_ const Image& dstImage,
   _In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset );

Parameters

srcRect: A rectangle described with x, y of the upper right corner, and w and h with the width and height, which indicates pixel location from srcImage to copy. The w and h also define the size of the destination rectangle in dstImage. Both rectangles must be valid for the size of the images (i.e. the API does not support clipping).

filter: See Filter Flags. Source and destination images do not need to be the same format, in which case conversions will use these flags.

xOffset, yOffset: Pixel location of destination rectangle in dstImage. The width and height of the destination rectangle is the same as srcRect.w and srcRect.h.

Example

Here's an example that copies a source image to the location (100,50) location in a new, larger image.

ScratchImage srcImage;

...

ScratchImage destImage;
destImage.Iniitalize2D( ... );

auto mdata = srcImage.GetMetadata();
Rect r( 0, 0, mdata.width, mdata.height );
hr = CopyRectangle( *srcImage.GetImage(0,0,0), r, *dstImage.GetImage(0,0,0), 
   TEX_FILTER_DEFAULT, 100, 50 );
if ( FAILED(hr) )
    ...

Remarks

Behavior of this function is not defined if the source and destination image are the same and the source and destination rectangles overlap.

Block compressed images are not supported as either the source or destination. Use Decompress to uncompress BC images before using this function.

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.

Updated Wiki: ComputeMSE

Computes the mean-squared error for each component based on two input images.

HRESULT ComputeMSE( _In_ const Image& image1, _In_ const Image& image2,
    _Out_ float& mse, _Out_writes_opt_(4) float* mseV,
    _In_ DWORD flags = 0 );

Parameters

flags: a combination of the following flags
  • CMSE_DEFAULT Default flags
  • CMSE_IMAGE1_SRGB Indicates image1 should have sRGB -> scRGB conversion applied before comparison.
  • CMSE_IMAGE2_SRGB Indicates image2 should have sRGB -> scRGB conversion applied before comparison.
  • CMSE_IMAGE1_X2_BIAS Indicates image1 should have the UNORM -> SNORM conversion applied before comparison.
  • CMSE_IMAGE2_X2_BIAS Indicates image2 should have the UNORM -> SNORM conversion applied before comparison.
  • CMSE_IGNORE_RED Indicates comparison should ignore differences in the RED (X) channel.
  • CMSE_IGNORE_GREEN Indicates comparison should ignore differences in the GREEN (Y) channel.
  • CMSE_IGNORE_BLUE Indicates comparison should ignore differences in the BLUE (Z) channel.
  • CMSE_IGNORE_ALPHA Indicates comparison should ignore differences in the ALPHA (W) channel.

Remarks

Image data is converted to DXGI_FORMAT_R32G32B32A32_FLOAT for this operation. BC data is automatically decompressed.

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.

Updated Wiki: ComputeMSE

Computes the mean-squared error for each component based on two input images.

HRESULT ComputeMSE( _In_ const Image& image1, _In_ const Image& image2,
    _Out_ float& mse, _Out_writes_opt_(4) float* mseV,
    _In_ DWORD flags = 0 );

Parameters

flags: a combination of the following flags
  • CMSE_DEFAULT Default flags
  • CMSE_IMAGE1_SRGB Indicates image1 should have sRGB -> scRGB conversion applied before comparison.
  • CMSE_IMAGE2_SRGB Indicates image2 should have sRGB -> scRGB conversion applied before comparison.
  • CMSE_IMAGE1_X2_BIAS Indicates image1 should have the UNORM -> SNORM conversion applied before comparison.
  • CMSE_IMAGE2_X2_BIAS Indicates image2 should have the UNORM -> SNORM conversion applied before comparison.
  • CMSE_IGNORE_RED Indicates comparison should ignore differences in the RED (X) channel.
  • CMSE_IGNORE_GREEN Indicates comparison should ignore differences in the GREEN (Y) channel.
  • CMSE_IGNORE_BLUE Indicates comparison should ignore differences in the BLUE (Z) channel.
  • CMSE_IGNORE_ALPHA Indicates comparison should ignore differences in the ALPHA (W) channel.
mse: The sum of the channel mean-squared error.

mseV: Points to an array of 4 floats which holds the individual channel mean-squared error. Can be nullptr.

Remarks

Image data is converted to DXGI_FORMAT_R32G32B32A32_FLOAT for this operation. BC data is automatically decompressed.

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.

Updated Wiki: ComputeNormalMap

Converts a height-map to a normal-map.

HRESULT ComputeNormalMap( _In_ const Image& srcImage, _In_ DWORD flags,
    _In_ float amplitude, _In_ DXGI_FORMAT format,
    _Out_ ScratchImage& normalMap );

HRESULT ComputeNormalMap( _In_reads_(nimages) const Image* srcImages,
    _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format,
    _Out_ ScratchImage& normalMaps );

Parameters

flags: a combination of the following flags
  • CNMAP_DEFAULT Default flags

Selects which channel to use as the height. Luminance is a monochrome value computed from R, G, and B.
  • CNMAP_CHANNEL_RED
  • CNMAP_CHANNEL_GREEN
  • CNMAP_CHANNEL_BLUE
  • CNMAP_CHANNEL_ALPHA
  • CNMAP_CHANNEL_LUMINANCE

Selects mirroring semantics for scanline references. Otherwise defaults to wrap.
  • CNMAP_MIRROR_U
  • CNMAP_MIRROR_V
  • CNMAP_MIRROR Same as both CNMAP_MIRROR_U and CNMAP_MIRROR_V
  • CNMAP_INVERT_SIGN Inverts the sign of the computed normal vector
  • CNMAP_COMPUTE_OCCLUSION Computes a crude occlusion term and stores in the resulting alpha channel

amplitude: Scaling factor for normals

format: Format of the resulting ScratchImage

Example

ScratchImage hmapImage;

...

ScratchImage normalMap;
hr = ComputeNormalMap( hmapImage.GetImage(0,0,0), CNMAP_CHANNEL_LUMINANCE | CNMAP_COMPUTE_OCCLUSION, 2.f, DXGI_FORMAT_R8G8B8A8_UNORM, normalMap );
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.

This method computes the normal by using the central difference with a kernel size of 3x3. The central differencing denominator used is 2.0. RGB channels in the destination contain biased (x,y,z) components of the normal.

Updated Wiki: Compress

Compresses an image or set of images to a block-compressed (BC) format.

HRESULT Compress( _In_ const Image& srcImage, _In_ DXGI_FORMAT format,
    _In_ DWORD compress, _In_ float alphaRef,
    _Out_ ScratchImage& cImage );

HRESULT Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef,
    _Out_ ScratchImage& cImages );

HRESULT Compress( _In_ ID3D11Device* pDevice, _In_ const Image& srcImage,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight,
    _Out_ ScratchImage& image );

HRESULT Compress( _In_ ID3D11Device* pDevice,
    _In_ const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight,
    _Out_ ScratchImage& cImages );

Parameters

device: The DirectCompute based versions of Compress require a Direct3D 11 device with Feature Level 10.0 or greater that supports DirectCompute.

format: Format to compress to. Must be a BC compressed format (i.e. DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB - DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM_SRGB)

Note that the DirectCompute based versions of Compress only support DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_BC7_UNORM, and DXGI_FORMAT_BC7_UNORM_SRGB

compress: Compress control flags
  • TEX_COMPRESS_DEFAULT Default flags.
  • TEX_COMPRESS_RGB_DITHER Enables dithering RGB colors for BC1-3 compression
  • TEX_COMPRESS_A_DITHER Enables dithering alpha channel for BC1-3 compression
  • TEX_COMPRESS_DITHER Same as TEX_COMPRESS_RGB_DITHER and TEX_COMPRESS_A_DITHER
  • TEX_COMPRESS_UNIFORM By default, BC1-3 uses a perceptual weighting. By using this flag, the perceptual weighting is disabled which can be useful when using the RGB channels for other data.
  • TEX_COMPRESS_PARALLEL This opts-in to multi-threaded compression if enabled.
  • TEX_COMPRESS_SRGB_IN Indicates the input format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_COMPRESS_SRGB_OUT Indicates the output format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_COMPRESS_SRGB This is the same as setting both TEX_COMPRESS_SRGB_IN and TEX_COMPRESS_SRGB_OUT

The sRGB color space overall is approximately equivalent to gamma 2.2. It's actually linear below a threshold, and gamma 2.4 beyond that.
http://en.wikipedia.org/wiki/SRGB

alphaRef: Threshold reference value when compressing an alpha channel for BC1 formats which support 1-bit transparency. (0 to 1 range)

alphaWeight: Used to weight the error metric's alpha computation for the BC7 GPU compressor. Use 1.0 for default, or a larger number to improve alpha accuracy potentially at the expense of the color channels.

Example

ScratchImage srcImage;

...

ScratchImage bcImage;
hr = Compress( srcImage.GetImages(), srcImage.GetImageCount(), srcImage.GetMetadata(), DXGI_FORMAT_BC3_UNORM, TEX_COMPRESS_DEFAULT, 0.5f, bcImage );
if ( FAILED(hr) )
    ...

Remarks

By default, the BC1 - BC3 color encoding algorithms will use a perceptual weighting of the Red and Blue channels which usually gives better visual results for standard color textures. For textures that do not contain color data, you will likely want to use TEX_COMPRESS_UNIFORM to disable the perceptual weighting.

When compressing for BC4, only the RED channel in the original image is used. When compressing for BC5, only the RED and GREEN channels are used.

The DirectXTex library functions allow arbitrary sized images to handle non-power-of-2 mipmapped BC textures. Note that Direct3D will not allow a resource to be created using BC format with the top-level size set to something other than a multiple of 4 in width and height, even though it does allow the mipchain below it to not meet that requirement. In other words, the library allows some textures to be compressed that are not actually valid on Direct3D 11.

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.

Release Notes

The software based encoder for BC6H and BC7 is computationally expensive and can be quite slow. The DirectCompute based encoder which is much faster has been integrated into the DirectXTex library, but the standalone version is also available http://code.msdn.microsoft.com/BC6HBC7-DirectCompute-35e8884a

Threading

The CPU-based compressor will use all cores on a system if given TEX_COMPRESS_PARALLEL for the BC6H / BC7 codec.

The DirectCompute GPU-based compressor makes use of the device's immediate context.

Related Links

http://msdn.microsoft.com/en-us/library/bb204843.aspx
http://msdn.microsoft.com/en-us/library/bb694531.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/hh308955.aspx
http://en.wikipedia.org/wiki/S3_Texture_Compression
http://en.wikipedia.org/wiki/3Dc
http://developer.download.nvidia.com/opengl/specs/GL_ARB_texture_compression_bptc.txt

Updated Wiki: Compress

Compresses an image or set of images to a block-compressed (BC) format.

HRESULT Compress( _In_ const Image& srcImage, _In_ DXGI_FORMAT format,
    _In_ DWORD compress, _In_ float alphaRef,
    _Out_ ScratchImage& cImage );

HRESULT Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef,
    _Out_ ScratchImage& cImages );

HRESULT Compress( _In_ ID3D11Device* pDevice, _In_ const Image& srcImage,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight,
    _Out_ ScratchImage& image );

HRESULT Compress( _In_ ID3D11Device* pDevice,
    _In_ const Image* srcImages, _In_ size_t nimages,
    _In_ const TexMetadata& metadata,
    _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight,
    _Out_ ScratchImage& cImages );

Parameters

device: The DirectCompute based versions of Compress require a Direct3D 11 device with Feature Level 10.0 or greater that supports DirectCompute.

format: Format to compress to. Must be a BC compressed format (i.e. DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB - DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM_SRGB)

Note that the DirectCompute based versions of Compress only support DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_BC7_UNORM, and DXGI_FORMAT_BC7_UNORM_SRGB

compress: Compress control flags

alphaRef: Threshold reference value when compressing an alpha channel for BC1 formats which support 1-bit transparency. (0 to 1 range)

alphaWeight: Used to weight the error metric's alpha computation for the BC7 GPU compressor. Use 1.0 for default, or a larger number to improve alpha accuracy potentially at the expense of the color channels.

Related flags

TEX_COMPRESS_DEFAULT Default flags.

Dithering

  • TEX_COMPRESS_RGB_DITHER Enables dithering RGB colors for BC1-3 compression
  • TEX_COMPRESS_A_DITHER Enables dithering alpha channel for BC1-3 compression
  • TEX_COMPRESS_DITHER Same as TEX_COMPRESS_RGB_DITHER and TEX_COMPRESS_A_DITHER
  • TEX_COMPRESS_UNIFORM By default, BC1-3 uses a perceptual weighting. By using this flag, the perceptual weighting is disabled which can be useful when using the RGB channels for other data.

Threading

  • TEX_COMPRESS_PARALLEL This opts-in to multi-threaded compression if enabled.

Color space

  • TEX_COMPRESS_SRGB_IN Indicates the input format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_COMPRESS_SRGB_OUT Indicates the output format is the sRGB format. This is implied if using a DXGI_FORMAT_*_SRGB format
  • TEX_COMPRESS_SRGB This is the same as setting both TEX_COMPRESS_SRGB_IN and TEX_COMPRESS_SRGB_OUT

The sRGB color space overall is approximately equivalent to gamma 2.2. It's actually linear below a threshold, and gamma 2.4 beyond that.
http://en.wikipedia.org/wiki/SRGB

BC7

  • TEX_COMPRESS_BC7_USE_3SUBSETS Indicates that BC7 compression should use the 3 subset modes (mode 0 and 2). Otherwise it skips these to improve compression performance.

Example

ScratchImage srcImage;

...

ScratchImage bcImage;
hr = Compress( srcImage.GetImages(), srcImage.GetImageCount(), srcImage.GetMetadata(), DXGI_FORMAT_BC3_UNORM, TEX_COMPRESS_DEFAULT, 0.5f, bcImage );
if ( FAILED(hr) )
    ...

Remarks

By default, the BC1 - BC3 color encoding algorithms will use a perceptual weighting of the Red and Blue channels which usually gives better visual results for standard color textures. For textures that do not contain color data, you will likely want to use TEX_COMPRESS_UNIFORM to disable the perceptual weighting.

When compressing for BC4, only the RED channel in the original image is used. When compressing for BC5, only the RED and GREEN channels are used.

The DirectXTex library functions allow arbitrary sized images to handle non-power-of-2 mipmapped BC textures. Note that Direct3D will not allow a resource to be created using BC format with the top-level size set to something other than a multiple of 4 in width and height, even though it does allow the mipchain below it to not meet that requirement. In other words, the library allows some textures to be compressed that are not actually valid on Direct3D 11.

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.

Release Notes

The software based encoder for BC6H and BC7 is computationally expensive and can be quite slow. The DirectCompute based encoder which is much faster has been integrated into the DirectXTex library, but the standalone version is also available http://code.msdn.microsoft.com/BC6HBC7-DirectCompute-35e8884a

Threading

The CPU-based compressor will use all cores on a system if given TEX_COMPRESS_PARALLEL for the BC6H / BC7 codec.

The DirectCompute GPU-based compressor makes use of the device's immediate context.

Related Links

http://msdn.microsoft.com/en-us/library/bb204843.aspx
http://msdn.microsoft.com/en-us/library/bb694531.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/hh308955.aspx
http://en.wikipedia.org/wiki/S3_Texture_Compression
http://en.wikipedia.org/wiki/3Dc
http://developer.download.nvidia.com/opengl/specs/GL_ARB_texture_compression_bptc.txt
Viewing all 1174 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>