Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Graphics Texture2DArray making textures blurrier

Discussion in '5.4 Beta' started by JasonBricco, May 6, 2016.

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    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:

    Code (CSharp):
    1. Shader "Custom/Diffuse"
    2. {
    3.     Properties
    4.     {
    5.         _TexArray ("Array", 2DArray) = "" {}
    6.     }
    7.  
    8.     SubShader
    9.     {
    10.         Pass
    11.         {
    12.             Tags { "RenderType" = "Opaque" }
    13.             LOD 200
    14.            
    15.             CGPROGRAM
    16.               #pragma vertex vert
    17.               #pragma fragment frag
    18.               #pragma target 3.5
    19.  
    20.             UNITY_DECLARE_TEX2DARRAY(_TexArray);
    21.  
    22.             struct VertexIn
    23.             {
    24.                 float4 vertex : POSITION;
    25.                 float4 texcoord : TEXCOORD0;
    26.                 float4 col : COLOR;
    27.             };
    28.  
    29.             struct VertexOut
    30.             {
    31.                 float4 pos : SV_POSITION;
    32.                 float4 uv : TEXCOORD0;
    33.                 float4 col : COLOR;
    34.             };
    35.  
    36.             VertexOut vert(VertexIn v)
    37.             {
    38.                 VertexOut o;
    39.  
    40.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    41.                 o.uv = v.texcoord;
    42.                 o.col = v.col;
    43.  
    44.                 return o;
    45.             }
    46.  
    47.             float4 frag(VertexOut i) : COLOR
    48.             {
    49.                 float3 light = i.col.rgb;
    50.                 float sun = i.col.a;
    51.  
    52.                 float3 amb = UNITY_LIGHTMODEL_AMBIENT * 2 * sun;
    53.                 amb = max(amb, 0.0666);
    54.                   amb = max(amb, light);
    55.  
    56.                   half4 col = UNITY_SAMPLE_TEX2DARRAY(_TexArray, i.uv.xyz);
    57.                   return float4(col.xyz * amb, 1.0);
    58.             }
    59.  
    60.             ENDCG
    61.         }
    62.     }
    63. }
    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:

    Image.png

    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!
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    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?
     
    JasonBricco likes this.
  3. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    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!
     
    Peter77 likes this.