This project has moved and is read-only. For the latest updates, please go here.


Support for MIRROR/WRAP vs. CLAMP filtering for mipmap generation


DirectXTex uses WIC's IWICBitmapScaler object to resize images and to generate mipmap chains. WIC only supports "Clamp" filtering modes, so this doesn't always result in a properly tileable texture.
Closed Jun 6, 2013 at 10:02 PM by walbourn


walbourn wrote Dec 20, 2012 at 1:35 AM

One solution is to continue to use WIC to do the filtering, but 'pad' the image before filtering with the appropriately replicated pixels.

The other is to not use WIC for this kind of operation and instead really on _ConvertScanline and implementing the filtering directly supporting all the desired modes.

walbourn wrote Apr 16, 2013 at 6:38 AM

Do the filtering in linear space as well (i.e. convert sRGB on input & output, possibly moving it to Load/StoreScanline)

walbourn wrote Apr 24, 2013 at 6:37 PM

D3DX only provided a MIRROR flag set (MIRROR_U, MIRROR_V, MIRROR_W) and did not have a specific WRAP mode. That's because for tileable textures, the difference should be minimal. This saves a lot of implementation complexity as well. Therefore, I'm going to work on the assumption that just having a MIRROR flag set (with clamp being the default) is sufficient.

walbourn wrote Apr 24, 2013 at 6:38 PM

For the general case of Resize, I plan to stick to using the WIC only implementation and to focus instead on custom filtering for the GenerateMipmaps[3D] scenarios. General image resizing with high-quality is already done pretty well with WIC.

walbourn wrote Apr 25, 2013 at 7:42 PM

D3DX is actually a little sloppy in the Direct3D difference of mirror vs. wrap. The D3DX MIRROR flags actually treat it as Direct3D would 'wrap' in some cases. Generally these flags are just indicating 'tile' vs. 'non-tiled' treatment in the mipmap generation anyhow.

walbourn wrote Apr 25, 2013 at 11:44 PM

After some more digging, I found that the D3DX flags are actually to use a "MIRROR" model instead of a "WRAP" model. It uses a WRAP model by default. The "MIRROR" behavior is actually more like a CLAMP because it only addresses an off-by-1 scenario.

For DirectXTex I think I'll stick with CLAMP by default but add TEX_FILTER_WRAP_U, TEX_FILTER_WRAP_V, TEX_FILTER_WRAP_W.

walbourn wrote May 20, 2013 at 10:16 PM

See related workitem 930

walbourn wrote Jun 3, 2013 at 6:36 PM

For POINT and BOX, LINEAR vs. MIRROR are not relevant.

For LINEAR, MIRROR is the same as clamp.

For CUBIC, WRAP vs MIRROR vs. CLAMP are distinct. That means I should have both after all.

walbourn wrote Jun 3, 2013 at 6:39 PM

D3DX defaulted to "WRAP". WIC uses only CLAMP, so the DirectXTex library defaults to "CLAMP".

walbourn wrote Jun 3, 2013 at 6:47 PM

See realated work item 943.

walbourn wrote Jun 6, 2013 at 10:02 PM

Resolved with changeset 28432: DirectXTex: 2D & 3D linear and cubic filtering with optional mirror/wrap vs. clamp