2

Closed

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

description

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.
 
This would add TEX_FILTER_FLAGS for TEX_FILTER_MIRROR_U, TEX_FILTER_MIRROR_V, TEX_FILTER_MIRROR_W, TEX_FILTER_MIRROR, TEX_FILTER_WRAP_U, TEX_FILTER_WRAP_V, TEX_FILTER_WRAP_W, TEX_WRAP_MIRROR to be supported by GenerateMipmaps3D.
Closed Jun 6, 2013 at 9:02 PM by walbourn

comments

walbourn wrote Dec 20, 2012 at 12: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 5: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 5: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 5: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 6: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 10: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 9:16 PM

See related workitem 930

walbourn wrote Jun 3, 2013 at 5: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 5:39 PM

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

walbourn wrote Jun 3, 2013 at 5:47 PM

See realated work item 943.

wrote Jun 6, 2013 at 9:02 PM

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