Texture2DArray making textures blurrier

Hi all,

I’m trying to get the texture arrays working. They do seem to be working, but for some reason they’re making my textures blurrier than they should be. Am I missing something important in my shader? (Up to now, I’ve written all my shaders as surface shaders, but decided to learn how to write vertex/fragment shaders instead. My first attempt is probably not very good).

Shader I’m using is this:

Shader "Custom/Diffuse"
{
    Properties
    {
        _TexArray ("Array", 2DArray) = "" {}
    }

    SubShader
    {
        Pass
        {
            Tags { "RenderType" = "Opaque" }
            LOD 200
           
            CGPROGRAM
              #pragma vertex vert
              #pragma fragment frag
              #pragma target 3.5

            UNITY_DECLARE_TEX2DARRAY(_TexArray);

            struct VertexIn
            {
                float4 vertex : POSITION;
                float4 texcoord : TEXCOORD0;
                float4 col : COLOR;
            };

            struct VertexOut
            {
                float4 pos : SV_POSITION;
                float4 uv : TEXCOORD0;
                float4 col : COLOR;
            };

            VertexOut vert(VertexIn v)
            {
                VertexOut o;

                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                o.uv = v.texcoord;
                o.col = v.col;

                return o;
            }

            float4 frag(VertexOut i) : COLOR
            {
                float3 light = i.col.rgb;
                float sun = i.col.a;

                float3 amb = UNITY_LIGHTMODEL_AMBIENT * 2 * sun;
                amb = max(amb, 0.0666);
                  amb = max(amb, light);

                  half4 col = UNITY_SAMPLE_TEX2DARRAY(_TexArray, i.uv.xyz);
                  return float4(col.xyz * amb, 1.0);
            }

            ENDCG
        }
    }
}

I made the texture array property, declared the variable with the Unity macro, and used the other Unity macro to sample it according to how Aras seemed to have suggested on a post elsewhere.

I had previously made the shader support just a single texture. In the following picture, you can see on the left my shader that supported a single texture (and worked fine), and on the right my shader above using the texture array:

Clearly, the right (texture array) version is blurrier. And I don’t know why that is. It doesn’t seem to be a problem with the Graphics.CopyTexture I used to copy from the source texture (the pixels were equal in both cases). I’m assuming my lack of shader writing knowledge made me forget something important.

Thanks for any help!

I didn’t work with Texture2DArray yet, but according to the documentation it has a filterMode property. I guess you want it to be Point Filtering, did you check that already?

1 Like

Ah, no, I didn’t even think to consider that it would set the texture array to bilinear filtering by default and was thinking way off in the wrong areas. Thanks for that!

1 Like