I need to be able to compile an ".hlsl, .fx" shader in my DirectX app. The issue is that, with the code below, I can only specify 6 textures by their default path directory.

I don't want this - I want to be able to set one path to the directory containing all of my textures, then compile my shader and see the shader effect on all those 50 textures.

I am using DirectX June 2010 and using Direct3D11 and Visual Studio 2015.

#define NUM_TEXTURES 7
1] =
//    DiffuseMap              NormalHeightMap                 DisplayName,    
fHeightScale fBaseTextureRepeat fDensityScale fMeaningfulDifference
{ L"Textures\\rocks.jpg",    L"Textures\\rocks_NM_height.dds",  L"Rocks",       
10.0f,       1.0f,              25.0f,        2.0f/255.0f },
{ L"Textures\\stones.bmp",   L"Textures\\stones_NM_height.dds", L"Stones",      
5.0f,        1.0f,              10.0f,        5.0f/255.0f },
{ L"Textures\\wall.jpg",     L"Textures\\wall_NM_height.dds",   L"Wall",        
8.0f,        1.0f,              7.0f,         7.0f/255.0f },
{ L"Textures\\wood.jpg",     L"Textures\\four_NM_height.dds",   L"Four 
shapes", 30.0f,       1.0f,              35.0f,        2.0f/255.0f },
{ L"Textures\\concrete.bmp", L"Textures\\bump_NM_height.dds",   L"Bump",        
10.0f,       4.0f,              50.0f,        2.0f/255.0f },
{ L"Textures\\concrete.bmp", L"Textures\\dent_NM_height.dds",   L"Dent",        
10.0f,       4.0f,              50.0f,        2.0f/255.0f },
{ L"Textures\\wood.jpg",     L"Textures\\saint_NM_height.dds",  L"Saints" ,     
20.0f,       1.0f,              40.0f,        2.0f/255.0f },
{ L"",                       L"",                               L"Custom" ,     
5.0f,        1.0f,              10.0f,        2.0f/255.0f },
DWORD                               g_dwNumTextures = 0;
ID3D11ShaderResourceView*           g_pLightTextureRV = NULL;
g_pszCustomTextureDiffuseFilename[MAX_PATH] = L"";
g_pszCustomTextureNormalHeightFilename[MAX_PATH] = L"";
DWORD                               g_bRecreateCustomTextureDensityMap  = 

Normally your textures are loaded by the program and not by the shader directly. You then set the parameters of the GPU in some fashion such as:

m_texturePtr = m_effect->GetVariableByName("shaderTexture")->AsShaderResource();

which I grabbed from this tutorial as an example: http://rastertek.com/dx10tut48.html

The Graphics Card isn't made to randomly read from an unlimited numbers of textures at a time. Normally you will batch all the objects who require the same textures into the same call to the graphics library so that you don't have to keep swapping textures a lot.

If you have an object or collection of objects that use many different textures but need to be drawn in a single batch, then it's conventional to pre-combine those textures into a texture atlas or array texture. This is a single logical texture as far as the shader is concerned, and texture coordinates are used to pick out the particular texture you wanted from the larger collection.

In your case, simply make it so that before you render a model, you send the necessary texture to the graphics library first. The below is my code (C# monogame; using DX11 shaders)

public static void BatchDraw(Effect effect, bool clear)
            // walk through each texture type
            for (int j=0; j < (int)TextureType.MAX_TEXTURE; j++)
                // derive the batch
                var currBatch = ObjectBatcher[j];
                // create a quad that is used for centering and sizing the texture
                var originalQuad = TextureSizes[j];

                // set the texture of the effect so that when we call draw, the correct type of texture is drawn
                //effect.Texture = TextureArray[j];
                // for each of the "models", place it in 3-space and send the data to the graphics device
                var len = currBatch.PsuedoCount;
                for(int i=0; i<len; i++)
                        // The offset of the texture to adjust the other vertices
                        // The vertices that will be filled and then drawn
                        // The quad will be centered on this obj's position and spun by this obj's rotation
                    foreach (var pass in effect.CurrentTechnique.Passes)
                        // TODO: Look into the offset. Possibly a way to reduce my own computation?
                            // We’ll be rendering two triangles
                            // The array of verts that we want to render
                            // The offset, which is 0 since we want to start 
                            // at the beginning of the floorVerts array
                            // The number of triangles to draw


NOTE: I currently pass in each quad (my "models"), but instead I should pass in an array that describes all of those batched models at a time.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .