Graphics.CopyTexture has wired behaviour when I use it to create a Texture2DArray asset

Texture2DArray texture2DArray = new Texture2DArray(texArray[0].width, texArray[0].height, texArray.Count,
            texArray[0].format, false, isLinear);
        for (int i = 0; i < texArray.Count; i++)
        {
            Graphics.CopyTexture(texArray[i],0,0,texture2DArray, i,0);
        }

I’m using above code to generate a Texture2DArray asset. It’s wired when I use it to generate a normal map Texture2DArray asset.

The asset becomes pink when I preview it.

The reason I found is that all of data in red channel of every normal map go to alpha channel in the Texture2DArray asset. I’ve checked every normal map’s format, it’s BC7. Also I tried to change the format but the issue is still there.

But, if I change to iOS platform and use ASTC6x6 format for every nomal map, the generated Texture2DArray asset is good.

I’m confused what happened?


Every Normal Map


Pink Normal Map Texture2DArray

Not entirely sure but my guess is that it has something to do with normal map encoding. I think, Unity uses DXT5nm on PC by default:

This is how DXT5nm normal maps are decoded (UnityCG.cginc):

// Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
// Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
fixed3 UnpackNormalmapRGorAG(fixed4 packednormal)
{
    // This do the trick
   packednormal.x *= packednormal.w;

    fixed3 normal;
    normal.xy = packednormal.xy * 2 - 1;
    normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
    return normal;
}

When you take a RenderDoc capture, the normal maps appear red as well.

Check if CopyTexture is doing the right thing in RenderDoc. Do not rely on the inspector. The inspector may show the 2D normal maps differently because it knows what they contain (after all you set the type when you import the texture). Also check if both source and destination have the texture format that you expect. Your screenshot says BC3 (=DXT5) but you mention BC7.

The format is good and the difference here is the picture I captured is generated from a BC3 normal map, based on a trial of my attempt. And it seems sampling this Texture2DArray asset is correct. Maybe the inspector is wrong.