I've generated a Texture2DArray from array of Texture2Ds and for some reason, when my shader is using Texture Array the output colors are noisy, almost as if noise filter was applied on them. Compare,

Just Texture2D: enter image description here

And when using Texture2DArray: enter image description here

I generate array using this code:

        Texture2D sample = materials[0].albedo;
        materialArray = new Texture2DArray(sample.width, sample.height, 
        materials.Count * 4, TextureFormat.RGBA32, false);

        for (int i = 0; i < materials.Count; i += 4)
            T_Material material = materials[i];

            materialArray.SetPixels(material.albedo.GetPixels(), i);
            materialArray.SetPixels(material.normal.GetPixels(), i + 1);
            materialArray.SetPixels(material.occulusion.GetPixels(), i + 2);
            materialArray.SetPixels(material.rougness.GetPixels(), i + 3);

        AssetDatabase.CreateAsset(materialArray, "Assets/_Generated/" + "terrainTextures.asset");

Initial Texture2Ds are in RGBA 32bit format:

enter image description here

Generated Texture2DArray (4 Textures, albedo, normal, AO, roughness, But I am only using albedo in shader for now):

enter image description here

My shader is simple, it extracts color data from Texture2DArray using index and applies it to PBR's albedo input.

enter image description here

And yes, I tried without my special blending effects, just inserting RGBA4 output to Albedo input of PBR both from Texture2DArray sampler and directly from Texture2D sampler.

Results were the same, Texture2DArray is noisy!

Thanks for any help!


1 Answer 1

materialArray = new Texture2DArray(sample.width, sample.height, 
    materials.Count * 4, TextureFormat.RGBA32, false);

That false says "Do not generate mipmaps for this texture array".

Without mipmaps, you get spatial aliasing - the noise you're observing.

Pass true to generate mipmaps. Then when sampling that texture for a distant surface, the GPU will automatically select a smaller mipmap, which is pre-filtered to smooth out that noise.

  • \$\begingroup\$ Aghh! When I mouseovered this parameter, it was called "mipchain", I got confused and thought better not touch it. Thank you so much! That solved the problem. BTW, if I set textures to be 4k, are they all loaded into GPU VRAM directly? \$\endgroup\$
    – Nick
    Commented Jun 1, 2021 at 15:12
  • 1
    \$\begingroup\$ A "mip chain" means a chain of mipmaps. One half the size, the next a quarter, then an eighth, etc. When in doubt, it helps to check the docs/look up the term or ask a question here to clarify the term. 🙂 \$\endgroup\$
    – DMGregory
    Commented Jun 1, 2021 at 15:16

You must log in to answer this question.

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