Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (1 posts)

Weird texture glitch in DirectX 12 when using dynamic indexing

Last post 2/10/2017 3:27 PM by Squall Liu. 0 replies.
  • 2/10/2017 3:27 PM

    Weird texture glitch in DirectX 12 when using dynamic indexing

    This question is posted on stackoverflow, too.


    Recently, I implemented the texture loading in my engine. But the textures would have some small glitches sometimes.

    The problem is shown as the following picture: enter image description here

    This is tested with AMD R9 380. I also tried to execute my program on Intel Graphic HD 4600, but it drawn nothing at all. (No geometry is shown.)


    My shader code:

    struct MaterialData
        float4 gDiffuseAlbedo;
        float3 gFresnelR0;
        float  gRoughness;
        float4x4 gMatTransform;
        uint gDiffuseMapIndex;
        uint MaterialPad0;
        uint MaterialPad1;
        uint MaterialPad2;
    StructuredBuffer<MaterialData> gMaterialData : register(t1, space1);
    // texture array for dynamic indexing
    // gMaxNumOfTextures is set to 16 at now
    Texture2D gCommonTexture[gMaxNumOfTextures] : register(t3);
    // in my pixel shader:
    float4 diffuseAlbedoMap = gCommonTexture[matData.gDiffuseMapIndex].Sample(gsamAnisotropicWrap, pin.TexC) * matData.gDiffuseAlbedo;

    I already double-checked the matData.gDiffuseMapIndex, and I'm sure that it is correct.

    I tried everything to fix this but in vain. Until I modified my code to this:

    // in my pixel shader:
    float4 diffuseAlbedoMap = float4(0,0,0,0);
    uint realMatIndex;
    for(realMatIndex = 0;realMatIndex < gMaxNumOfTextures;realMatIndex++)
        if(realMatIndex == matData.gDiffuseMapIndex)
            diffuseAlbedoMap = gCommonTexture[matData.gDiffuseMapIndex].Sample(gsamAnisotropicWrap, pin.TexC) * matData.gDiffuseAlbedo;

    And this works properly!

    No glitches on my R9 380.

    All geometries are shown normally on HD 4600.


    BUT WHY!?

    Why do I need to use a for loop to check the index again for preventing glitches?


    What may cause this problem?

    I thought this problem all the night but I still couldn't find the answer.



    Full shader code: enter link description here

    I found the solution. (In my post on stackoverflow.)
Page 1 of 1 (1 posts) Previous Discussion Next Discussion