Converting D3DFMT_DXT5/D3DFMT_A8R8G8B8 to D3DFMT_U8V8 in DirectX11?

Started by
4 comments, last by jonwil 5 years, 7 months ago

We have an engine based on Direct3D11 that uses ID3D11Device::CreateTexture2D to create its textures passing in whatever format we read from the dds file header.

We also have a previous version of our engine that uses the DX9 fixed function bump map feature for bump maps. This feature takes bump map textures in U8V8 format as input but it also takes textures in DXT5 and A8R8G8B8 and converts them into U8V8 using D3DXCreateTextureFromFileInMemoryEx in d3dx9).

Our current D3D11 engine handles the U8V8 textures just fine (I think it feeds it to CreateTexture2D as DXGI_FORMAT_R8G8_TYPELESS) and has some shader code that emulates the fixed function bump map feature without problems. But now we want to add support for the DXT5 and A8R8G8B8 bump maps.

Does anyone know where I can find code for Direct3D11 (or just plain code with no dependence on specific graphics APIs) that can convert the DXT5 or A8R8G8B8 texture data into U8V8 data in the same way as D3DXCreateTextureFromFileInMemoryEx and the other D3DX9 functions would do? (Someone out there must have written some code to convert between different texture formats I am sure, I just can't find it)

Advertisement

In this case all the only "conversion" that you would do would be to chop off the extra 2 channels to create an R8G8_UNORM texture. You can certainly do this yourself before creating the texture resource, but you could also just ignore it. Your shader code will work the same with R8G8_UNORM as it will with R8G8B8A8_UNORM formats if it only uses the first two channels of the texture fetch.

If you really want to do format conversions, DirectXTex can do all of that for you.

 In this case we need whatever magic d3dx9 does when it converts RGBA data to U8V8 data (which is clearly more than just lopping off 2 channels based on some testing I have done). If DirectXTex can do that same magic conversion, that would be good. Otherwise I will keep looking for some code that can do it :)

 

I'm not sure what the old D3DX functions would be doing there. It looks like U8V8 is a signed integer format (DirectXTex seems to treat it as R8G8_SNORM), so perhaps it was something to with unpacking from the [0, 1] range to the [-1, 1] range. You may want to file an issue on the DirectXTex GitHub repo or see if you can contact Chuck Walbourn directly to see if he can help you out. He's open-sourced a lot of the old D3DX stuff, so he's probably the best person to ask.

I filed an issue in the DirectXTex repo asking if DirectXTex can produce data matching the U8V8 format and if so, how. Seems like this might be the way to go (its essentially the "official" replacement for the texture stuff in d3dx9 so one would assume if what I want is possible, DirectXTex would be able to do it)

 

This topic is closed to new replies.

Advertisement