Jump to content
  • Advertisement
Sign in to follow this  
Grx

DX11 Loading of 3D Textures from a 2D texture

This topic is 2311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!