Jump to content

  • Log In with Google      Sign In   
  • Create Account


Loading of 3D Textures from a 2D texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Grx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 24 March 2012 - 09:54 AM

Hi,

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?

Sponsor:

#2 MJP   Moderators   -  Reputation: 10547

Like
1Likes
Like

Posted 24 March 2012 - 12:57 PM

You're not going to be able to do it that way...the D3DX texture loader is going to know how to reinterpret your 2D texture as a 3D texture. You'll need to load it as 2D texture first (with D3D11_USAGE_STAGING and D3D11_CPU_ACCESS_READ so that you can read it on the CPU), and then pass the data to CreateTexture3D through the pInitData parameter. As long as your data is in x->y->z byte order, it should work fine as long as you set SysMemPitch and SysMemSlicePitch correctly. So your SysMemPitch should be 32 * formatBytesPerPixel, and the SysMemSlicePitch should be the pitch value that you get when you call Map on your 2D staging texture.

#3 Grx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 24 March 2012 - 05:39 PM

Thanks a lot.

Got it to work with your tips. Actually had to write some code that reorders the texel data as the slices were next to each other in x-direction (1024 x 32).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS