Jump to content
  • Advertisement
mister345

DX11 Multitexturing in DirectX11 - 3 textures work fine, but 4th turns black!

This topic is 370 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

Trying to write a multitexturing shader in DirectX11 - 3 textures work fine, but adding 4th gets sampled as black!
Could you please look at the textureClass.cpp line 79? - I'm guess its D3D11_TEXTURE2D_DESC settings are wrong, 
but no idea how to set it up right. I tried changing ArraySize from 1 to 4, but does nothing. If thats not the issue, please look
at the LightShader_ps - maybe doing something wrong there? Otherwise, no idea.

    // Setup the description of the texture.
    textureDesc.Height = height;
    textureDesc.Width = width;
    textureDesc.MipLevels = 0;
    textureDesc.ArraySize = 1;
    textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    textureDesc.SampleDesc.Count = 1;
    textureDesc.SampleDesc.Quality = 0;
    textureDesc.Usage = D3D11_USAGE_DEFAULT;
    textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
    textureDesc.CPUAccessFlags = 0;
    textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;

Please help, thanks.

https://github.com/mister51213/DirectX11Engine/blob/master/DirectX11Engine/Texture.cpp

 

Share this post


Link to post
Share on other sites
Advertisement

Yes, it did, thanks for following up! Out of curiosity, is there a "right way" to do this? Because it looks like D3D11_TEXTURE2D_DESC  has a few different versions corresponding to different dimensions of arrays - so in my case, if I'm multitexturing with 4 or 5 textures, couldnt I just be using a 1 dimensional array or am I misunderstanding it?

Share this post


Link to post
Share on other sites

I dont think there is a "right" way to do it, just do what is most convenient for you.

If you have a large number of textures, a texture array (which is different from an array of textures) is good as it means your hlsl code can easily access whichever texture it wants by using a texture number. But thats really only useful if you have lots of textures, far more than 4.

Texturearrays also have the restriction that each texture in that array must have the same x and y dimensions. (you would have to have a different texture array object for each different texture size, but you can obviously have an array of them to do this)

To make a texturearray - in your D3D11_TEXTURE2D_DESC object, set textureDesc.ArraySize to be the number of textures.

To make your srv you use D3D11_SRV_DIMENSION_TEXTURE2DARRAY instead of D3D11_SRV_DIMENSION_TEXTURE2D ie

            srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
            srvDesc.Texture2DArray.MostDetailedMip = 0;
            srvDesc.Texture2DArray.MipLevels = desc.MipLevels;
            srvDesc.Texture2DArray.FirstArraySlice = 0;
            srvDesc.Texture2DArray.ArraySize = texturearrayelements; // number of texture array elements

 

In the hlsl you would use Texture2DArray instead of Texture2D. Also remember its a single object not an array of objects when you define its slot in hlsl.

When copying into a texture array you do it by the subresources. So the texture array is layed out by having a subresource for each mip of the 1st texture, then a subresource for each mip of the second texture etc.

 

 

Edited by CortexDragon

Share this post


Link to post
Share on other sites

  • 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!