Colorkey analogue using DirectXTK

Apr 14, 2014 at 3:41 PM
I have some textures that were used in DirectX 9 application and has colorkey to make their background transparent.
DirectX 11.1 (I have to use it as supported in Windows Store applications) doesn't support colorkeying, so is there a way to use something like colorkey for adding of transparency to the old textures via DirectXTK?
DXGI_FORMAT_R8G8B8A8_UNORM format is used.
Apr 14, 2014 at 6:45 PM
For modern hardware you want the transparency to be in the form of an alpha channel rather than color keying. I recommend editing your textures ahead of time to give them alpha channels, rather than trying to do this conversion on the fly at runtime.

One option is to do this in a paint program, for instance it would be very easy in Photoshop to select a particular color and then clear just that region to transparent. In fact I think you could probably automate that across a set of images using a Photoshop macro.

Another option would be to automate this in code as an offline conversion process. The DirectXTex library would be a good base for this kind of work - I don't think it has color key functionality built in (Chuck will no doubt correct me if I missed that :-) but it should be pretty easy to code that yourself on top of the DirectXTex file load, save, and format conversion functions.
Marked as answer by walbourn on 4/14/2014 at 11:14 AM
Apr 14, 2014 at 7:13 PM
Edited Apr 14, 2014 at 7:16 PM
DirectXTex/texconv doesn't currently have color-keying conversion support, but it would be fairly easy to add. I've added a workitem to add to the core library.

If you could attached some sample images (DDS?) to the work item I can test it out...

BTW, here's an old article on how it was done with legacy D3DX.

I'd rather not add support for color-key substitutions to DDSTextureLoader because this is not an efficient operation to do at runtime. It's best done offline.
Apr 15, 2014 at 2:08 PM
There is sample texture. If you have any access problems, please let me know and I'll try to fix them.
It is png file that contains alpha channel indeed (its black background was set as transparent color yet), but in the application alpha is set to 1.0f (it was acceptable value when color-keying was supported), as a result there is black frame around of the texture.
In case alpha is set to values from 0.0 to 1.0 (excluding 1.0 itself), there is no black backgroung, but all the texture has the transparency set, although arrow itself should be opaque.
One workaround available is to set alpha=0.9999f to make texture look opaque for user and remove black background at the same time, but it seems to be hackish way.