1
\$\begingroup\$

I need to be able to compile a shader ".hlsl, .fx" in my DirectX app but here is the issue I can only specify 6 textures by there default path directory I don't want this I want to be able to set one path for all textures all 50 of them and then compile them and see the shader effect on all textures all 50 of them that's my issue thanks? I am using DirectX June 2010 and using Direct3D11 and visual studio 2015.

#define NUM_TEXTURES 7
DETAIL_TESSELLATION_TEXTURE_STRUCT DetailTessellationTextures[NUM_TEXTURES + 
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_pDetailTessellationBaseTextureRV[NUM_TEXTURES+1];
ID3D11ShaderResourceView*           
g_pDetailTessellationHeightTextureRV[NUM_TEXTURES+1];
ID3D11ShaderResourceView*           
g_pDetailTessellationDensityTextureRV[NUM_TEXTURES+1];
ID3D11ShaderResourceView*           g_pLightTextureRV = NULL;
WCHAR                               
g_pszCustomTextureDiffuseFilename[MAX_PATH] = L"";
WCHAR                               
g_pszCustomTextureNormalHeightFilename[MAX_PATH] = L"";
DWORD                               g_bRecreateCustomTextureDensityMap  = 
false;
\$\endgroup\$

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0
\$\begingroup\$

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 store dozens of textures at a time (if I understand it right, feel free to correct me.) Instead; it uses its ram for storing the depth info, the massive indexed-buffers it can receive, etc.

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.


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];
                effect.Parameters["colorTexture"].SetValue(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++)
                {
                    AdjustModel(
                        // The offset of the texture to adjust the other vertices
                        originalQuad,
                        // The vertices that will be filled and then drawn
                        quadVertices, 
                        // The quad will be centered on this obj's position and spun by this obj's rotation
                        currBatch[i]);

                    foreach (var pass in effect.CurrentTechnique.Passes)
                    { 
                        pass.Apply();

                        // TODO: Look into the offset. Possibly a way to reduce my own computation?
                        myGD.DrawUserPrimitives(
                            // We’ll be rendering two triangles
                            PrimitiveType.TriangleList,
                            // The array of verts that we want to render
                            quadVertices,
                            // The offset, which is 0 since we want to start 
                            // at the beginning of the floorVerts array
                            0,
                            // The number of triangles to draw
                            2);
                    }

                }


            }
        }

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.

\$\endgroup\$
  • \$\begingroup\$ "The Graphics Card isn't made to store dozens of textures at a time (if I understand it right, feel free to correct me) " modern graphics cards are indeed designed with a large amount of video memory for storing many textures at a time. The problem of swapping between many textures within a collection of materials is often addressed by combining the textures into an atlas or array texture, so it's one logical texture taking up the same video memory as dozens of individual images. \$\endgroup\$ – DMGregory Jul 8 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.