Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 24 Mar 2012
Offline Last Active Apr 01 2012 11:36 AM

Topics I've Started

Loading of 3D Textures from a 2D texture

24 March 2012 - 09:54 AM


I'm trying to implement a color gradient post effect that uses the final framebuffer color to index into a 3d texture cube for remapping the color. Currently I'm struggling to load the texture so that I get a 3D texture shader resource view out of it. The source texture is a 1024 x 32 png texture representing a 32x32x32 color cube.

I get the file loaded into memory (from my own file handling system) and then use D3DX11GetImageInfoFromMemory to get the texture resolution (will get saved into a D3DX11_IMAGE_INFO structure, named rImageInfo in the code snippet below).

I then tried to use D3DX11CreateShaderResourceViewFromMemory to create a 3d texture shader resource view.

    D3DX11_IMAGE_LOAD_INFO rImageLoadInfo;
    rImageLoadInfo.Depth = p_iColumns * p_iRows;
    rImageLoadInfo.Width = rImageInfo.Width / p_iColumns;
    rImageLoadInfo.Height = rImageInfo.Height / p_iRows;
    rImageLoadInfo.FirstMipLevel = 0;
    rImageLoadInfo.MipLevels = 1;
    rImageLoadInfo.Usage = D3D11_USAGE_DEFAULT;
    rImageLoadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    rImageLoadInfo.CpuAccessFlags = 0;
    rImageLoadInfo.MiscFlags = 0;
    rImageLoadInfo.Format = rImageInfo.Format;
    rImageLoadInfo.Filter = D3DX11_DEFAULT;
    rImageLoadInfo.MipFilter = D3DX11_DEFAULT;
    rImageLoadInfo.pSrcInfo = &rImageInfo;

    hr = D3DX11CreateShaderResourceViewFromMemory(pD3D11Device, pDataBuffer, (tUInt32)iFileSize, &rImageLoadInfo, NULL, &pShaderResourceView, NULL);

I end up with this D3D error message:

D3DX11: Depth resampling can only be performed on D3D11_RESOURCE_DIMENSION_TEXTURE3D textures. Check LoadInfo.Depth, make sure it's 1 or D3DX11_FROM_FILE.

Does somebody know how to do this correctly? How do you guys load 3d textures?